Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
duiba-tiny-image-node
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
劳工
duiba-tiny-image-node
Commits
9e090357
Commit
9e090357
authored
Nov 10, 2021
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init3
parent
3b54b988
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
14 deletions
+32
-14
api.js
dist/api.js
+6
-5
api.js.map
dist/api.js.map
+1
-1
compress.js
dist/compress.js
+10
-2
compress.js.map
dist/compress.js.map
+1
-1
api.ts
src/api.ts
+3
-2
compress.ts
src/compress.ts
+11
-3
No files found.
dist/api.js
View file @
9e090357
...
...
@@ -146,14 +146,14 @@ async function prepareInputs(req) {
};
inputs
.
push
(
input
);
}
const
hashs
=
inputs
.
map
(
input
=>
input
.
hash
);
const
urls
=
await
(
0
,
redis_1
.
getUrlFromCache
)(
hashs
);
/*const hashs = inputs.map(input => input.hash)
const urls = await
getUrlFromCache(hashs)
for (let i = 0; i < inputs.length; i++) {
const
input
=
inputs
[
i
]
;
const input = inputs[i]
if (urls[i]) {
input
.
url
=
urls
[
i
];
}
input.url = urls[i]
}
}*/
return
inputs
;
}
async
function
tinifyOnce
(
input
,
type
,
cdnRoot
)
{
...
...
@@ -162,6 +162,7 @@ async function tinifyOnce(input, type, cdnRoot) {
return
;
}
const
buffer
=
await
(
0
,
compress_1
.
compressImage
)(
input
.
buffer
,
type
);
console
.
log
(
'compressImage size:'
,
buffer
.
length
);
if
(
cdnRoot
)
{
const
cdnPath
=
path
.
join
(
cdnRoot
,
objectHash
(
buffer
)
+
input
.
extname
);
return
(
0
,
ali_oss_duiba_1
.
uploadFile
)(
buffer
,
cdnPath
);
...
...
dist/api.js.map
View file @
9e090357
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,qCAA6B;AAC7B,yCAAwC;AACxC,iDAAwC;AACxC,0CAAyC;AACzC,6BAA4B;AAC5B,+BAA8B;AAC9B,mCAAuD;AAEvD,MAAM,aAAa,GAAG,cAAc,CAAA;AACpC,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,aAAa,CAAC,CAAA;AAE9D,SAAwB,QAAQ,CAAC,MAAM;IACtC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI;QAC3C,GAAG,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAA;QAC3C,OAAO,IAAI,EAAE,CAAA;IACd,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI;QACpD,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACjB,OAAO,IAAI,EAAE,CAAA;IACd,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AAC/B,CAAC;AAZD,2BAYC;AAED,6BAA6B;AAC7B,KAAK,UAAU,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI;IACnC,MAAM,EAAC,IAAI,GAAG,SAAS,EAAE,OAAO,EAAC,GAAG,GAAG,CAAC,KAAK,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAA;IAC/B,IAAI,SAAS,KAAK,CAAC,EAAE;QACpB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AAK,CAAC,OAAO,CAAC,CAAA;YACtE,OAAO,IAAA,0BAAU,EAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAClC;aAAM;YACN,OAAO,MAAM,CAAA;SACb;KACD;IAAC,OAAO,CAAC,EAAE;QACX,gBAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAA;QACpC,OAAO,CAAC,CAAA;KACR;AACF,CAAC"}
\ No newline at end of file
dist/compress.js
View file @
9e090357
...
...
@@ -8,9 +8,17 @@ const { buffer: imagemin } = require("imagemin");
const
imageminJpegtran
=
require
(
"imagemin-jpegtran-cn"
);
const
imageminPngquant
=
require
(
"imagemin-pngquant-cn"
);
const
node_tinify_1
=
require
(
"node-tinify"
);
var
COMPRESS_TYPE
;
(
function
(
COMPRESS_TYPE
)
{
COMPRESS_TYPE
[
"builtin"
]
=
"builtin"
;
COMPRESS_TYPE
[
"tinypng"
]
=
"tinypng"
;
})(
COMPRESS_TYPE
||
(
COMPRESS_TYPE
=
{}));
function
compressImage
(
buffer
,
type
)
{
if
(
!
COMPRESS_TYPE
[
type
])
{
type
=
COMPRESS_TYPE
.
builtin
;
}
switch
(
type
)
{
case
'builtin'
:
case
COMPRESS_TYPE
.
builtin
:
return
imagemin
(
buffer
,
{
plugins
:
[
imageminJpegtran
(),
...
...
@@ -19,7 +27,7 @@ function compressImage(buffer, type) {
})
]
});
case
'tinypng'
:
case
COMPRESS_TYPE
.
tinypng
:
return
(
0
,
node_tinify_1
.
compress
)(
buffer
,
{
returnType
:
'buffer'
});
}
}
...
...
dist/compress.js.map
View file @
9e090357
{"version":3,"file":"compress.js","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AAC9C,MAAM,gBAAgB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAA;AACxD,MAAM,gBAAgB,GAAG,OAA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aACD,CAAC,CAAA;QACH,KAAK,aAAa,CAAC,OAAO;YACzB,OAAO,IAAA,sBAAQ,EAAC,MAAM,EAAE,EAAC,UAAU,EAAE,QAAQ,EAAC,CAAC,CAAA;KAChD;AACF,CAAC;AAjBD,sCAiBC"}
\ No newline at end of file
src/api.ts
View file @
9e090357
...
...
@@ -146,14 +146,14 @@ async function prepareInputs(req) {
inputs
.
push
(
input
)
}
const
hashs
=
inputs
.
map
(
input
=>
input
.
hash
)
/*
const hashs = inputs.map(input => input.hash)
const urls = await getUrlFromCache(hashs)
for (let i = 0; i < inputs.length; i++) {
const input = inputs[i]
if (urls[i]) {
input.url = urls[i]
}
}
}
*/
return
inputs
}
...
...
@@ -164,6 +164,7 @@ async function tinifyOnce(input, type, cdnRoot) {
return
}
const
buffer
=
await
compressImage
(
input
.
buffer
,
type
)
console
.
log
(
'compressImage size:'
,
buffer
.
length
)
if
(
cdnRoot
)
{
const
cdnPath
=
path
.
join
(
cdnRoot
,
objectHash
(
buffer
)
+
input
.
extname
)
return
uploadFile
(
buffer
,
cdnPath
)
...
...
src/compress.ts
View file @
9e090357
...
...
@@ -8,9 +8,17 @@ const imageminPngquant = require("imagemin-pngquant-cn")
import
{
compress
}
from
'node-tinify'
export
function
compressImage
(
buffer
:
Buffer
,
type
)
{
enum
COMPRESS_TYPE
{
builtin
=
'builtin'
,
tinypng
=
'tinypng'
,
}
export
function
compressImage
(
buffer
:
Buffer
,
type
:
COMPRESS_TYPE
)
{
if
(
!
COMPRESS_TYPE
[
type
])
{
type
=
COMPRESS_TYPE
.
builtin
}
switch
(
type
)
{
case
'builtin'
:
case
COMPRESS_TYPE
.
builtin
:
return
imagemin
(
buffer
,
{
plugins
:
[
imageminJpegtran
(),
...
...
@@ -19,7 +27,7 @@ export function compressImage(buffer: Buffer, type) {
})
]
})
case
'tinypng'
:
case
COMPRESS_TYPE
.
tinypng
:
return
compress
(
buffer
,
{
returnType
:
'buffer'
})
}
}
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