Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tiny-image
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
tiny-image
Commits
050f5ae3
Commit
050f5ae3
authored
Feb 18, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改错误返回判断阈值为512
parent
6ff61a5f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
3 deletions
+3
-3
index.js
dist/index.js
+1
-1
index.js.map
dist/index.js.map
+1
-1
index.js
src/index.js
+1
-1
No files found.
dist/index.js
View file @
050f5ae3
...
...
@@ -32,7 +32,7 @@ async function compressBuffer(buffer) {
resBuffer
=
Buffer
.
concat
([
resBuffer
,
d
],
resBuffer
.
length
+
d
.
length
);
});
res
.
on
(
'end'
,
()
=>
{
if
(
resBuffer
.
length
>
5
0
)
{
if
(
resBuffer
.
length
>
5
12
)
{
resolve
(
resBuffer
);
}
else
{
let
str
=
resBuffer
.
toString
();
...
...
dist/index.js.map
View file @
050f5ae3
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/index.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2020-02-13.
\n
*/
\n\n
import FormData from 'form-data';
\n
import fs from 'fs-extra';
\n\n
const tinifyUrl = 'http://tinify.duiba.com.cn/tinify';
\n\n
export async function compressBuffer(buffer) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
if (buffer && buffer.length > 0) {\n
\t\t\t
let form = new FormData();
\n\t\t\t
form.append('file', buffer, {\n
\t\t\t\t
filename: 'image.png',
\n\t\t\t\t
contentType: 'image/png',
\n\t\t\t
});
\n\n\t\t\t
form.submit(tinifyUrl, function (err, res) {\n
\t\t\t\t
if (err)
{
\n\t\t\t\t\treject(err);\n\t\t\t\t
}
else {\n
\t\t\t\t\t
res.resume();
\n\t\t\t\t\t
let resBuffer = Buffer.alloc(0);
\n\t\t\t\t\t
res.on('data', (d) => {\n
\t\t\t\t\t\t
resBuffer = Buffer.concat([resBuffer, d], resBuffer.length + d.length);
\n\t\t\t\t\t
});
\n\t\t\t\t\t
res.on('end', () => {\n
\t\t\t\t\t\t
if (resBuffer.length > 50)
{
\n\t\t\t\t\t\t\tresolve(resBuffer);\n\t\t\t\t\t\t
}
else {\n
\t\t\t\t\t\t\t
let str = resBuffer.toString();
\n\t\t\t\t\t\t\t
let json = JSON.parse(str);
\n\t\t\t\t\t\t\t
reject(json.msg);
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
});
\n\t\t\t\t\t
res.on('abort', () =>
{
\n\t\t\t\t\t\treject('abort')\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t
}
else {\n
\t\t\t
reject('empty buffer')
\n\t\t
}
\n\t
})
\n
}
\n\n
export async function compressFile(file) {\n
\t
let buffer = await fs.readFile(file);
\n\t
return compressBuffer(buffer);
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;;;;;;;;AAAA;;;AAGA,AAGA;AACA,MAAM,SAAS,GAAG,mCAAmC,CAAC;;AAEtD,AAAO,eAAe,cAAc,CAAC,MAAM,EAAE;CAC5C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EACvC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;GAChC,IAAI,IAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;GAC1B,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE;IAC3B,QAAQ,EAAE,WAAW;IACrB,WAAW,EAA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.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2020-02-13.
\n
*/
\n\n
import FormData from 'form-data';
\n
import fs from 'fs-extra';
\n\n
const tinifyUrl = 'http://tinify.duiba.com.cn/tinify';
\n\n
export async function compressBuffer(buffer) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
if (buffer && buffer.length > 0) {\n
\t\t\t
let form = new FormData();
\n\t\t\t
form.append('file', buffer, {\n
\t\t\t\t
filename: 'image.png',
\n\t\t\t\t
contentType: 'image/png',
\n\t\t\t
});
\n\n\t\t\t
form.submit(tinifyUrl, function (err, res) {\n
\t\t\t\t
if (err)
{
\n\t\t\t\t\treject(err);\n\t\t\t\t
}
else {\n
\t\t\t\t\t
res.resume();
\n\t\t\t\t\t
let resBuffer = Buffer.alloc(0);
\n\t\t\t\t\t
res.on('data', (d) => {\n
\t\t\t\t\t\t
resBuffer = Buffer.concat([resBuffer, d], resBuffer.length + d.length);
\n\t\t\t\t\t
});
\n\t\t\t\t\t
res.on('end', () => {\n
\t\t\t\t\t\t
if (resBuffer.length > 512)
{
\n\t\t\t\t\t\t\tresolve(resBuffer);\n\t\t\t\t\t\t
}
else {\n
\t\t\t\t\t\t\t
let str = resBuffer.toString();
\n\t\t\t\t\t\t\t
let json = JSON.parse(str);
\n\t\t\t\t\t\t\t
reject(json.msg);
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
});
\n\t\t\t\t\t
res.on('abort', () =>
{
\n\t\t\t\t\t\treject('abort')\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t
}
else {\n
\t\t\t
reject('empty buffer')
\n\t\t
}
\n\t
})
\n
}
\n\n
export async function compressFile(file) {\n
\t
let buffer = await fs.readFile(file);
\n\t
return compressBuffer(buffer);
\n
}
\n
"
],
"names"
:
[],
"mappings"
:
";;;;;;;;;AAAA;;;AAGA,AAGA;AACA,MAAM,SAAS,GAAG,mCAAmC,CAAC;;AAEtD,AAAO,eAAe,cAAc,CAAC,MAAM,E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AAC,cAAc,EAAC;GACtB;EACD,CAAC;CACF;;AAED,AAAO,eAAe,YAAY,CAAC,IAAI,EAAE;CACxC,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;CACrC,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;CAC9B;;;;;"
}
\ No newline at end of file
src/index.js
View file @
050f5ae3
...
...
@@ -26,7 +26,7 @@ export async function compressBuffer(buffer) {
resBuffer
=
Buffer
.
concat
([
resBuffer
,
d
],
resBuffer
.
length
+
d
.
length
);
});
res
.
on
(
'end'
,
()
=>
{
if
(
resBuffer
.
length
>
5
0
)
{
if
(
resBuffer
.
length
>
5
12
)
{
resolve
(
resBuffer
);
}
else
{
let
str
=
resBuffer
.
toString
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment