Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
A
avatar-handler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
avatar-handler
Commits
79a4e4fa
Commit
79a4e4fa
authored
Sep 17, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish
parent
5aeea726
Pipeline
#745
canceled with stages
in 2 minutes and 28 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
17 deletions
+28
-17
package-lock.json
package-lock.json
+13
-3
package.json
package.json
+4
-2
src/avatar.ts
src/avatar.ts
+6
-6
src/utility.ts
src/utility.ts
+1
-1
src/worker.ts
src/worker.ts
+4
-5
No files found.
package-lock.json
View file @
79a4e4fa
...
@@ -1402,9 +1402,9 @@
...
@@ -1402,9 +1402,9 @@
}
}
},
},
"@types/node"
:
{
"@types/node"
:
{
"version"
:
"14.
0.9
"
,
"version"
:
"14.
10.3
"
,
"resolved"
:
"https://registry.npmjs.org/@types/node/-/node-14.
0.9
.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@types/node/-/node-14.
10.3
.tgz"
,
"integrity"
:
"sha512-
0sCTiXKXELOBxvZLN4krQ0FPOAA7ij+6WwvD0k/PHd9/KAkr4dXel5J9fh6F4x1FwAQILqAWkmpeuS6mjf1iKA
=="
"integrity"
:
"sha512-
zdN0hor7TLkjAdKTnYW+Y22oIhUUpil5ZD1V1OFq0CR0CLKw+NdR6dkziTfkWRLo6sKzisayoj/GNpNbe4LY9Q
=="
},
},
"@types/normalize-package-data"
:
{
"@types/normalize-package-data"
:
{
"version"
:
"2.4.0"
,
"version"
:
"2.4.0"
,
...
@@ -1465,6 +1465,11 @@
...
@@ -1465,6 +1465,11 @@
"@types/superagent"
:
"*"
"@types/superagent"
:
"*"
}
}
},
},
"@types/underscore"
:
{
"version"
:
"1.10.23"
,
"resolved"
:
"https://registry.npmjs.org/@types/underscore/-/underscore-1.10.23.tgz"
,
"integrity"
:
"sha512-vX1NPekXhrLquFWskH2thcvFAha187F/lM6xYOoEMZWwJ/6alSk0/ttmGP/YRqcqtCv0TMbZjYAdZyHAEcuU4g=="
},
"@types/yargs"
:
{
"@types/yargs"
:
{
"version"
:
"15.0.5"
,
"version"
:
"15.0.5"
,
"resolved"
:
"https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz"
,
"resolved"
:
"https://registry.npmjs.org/@types/yargs/-/yargs-15.0.5.tgz"
,
...
@@ -8539,6 +8544,11 @@
...
@@ -8539,6 +8544,11 @@
}
}
}
}
},
},
"underscore"
:
{
"version"
:
"1.11.0"
,
"resolved"
:
"https://registry.npmjs.org/underscore/-/underscore-1.11.0.tgz"
,
"integrity"
:
"sha512-xY96SsN3NA461qIRKZ/+qox37YXPtSBswMGfiNptr+wrt6ds4HaMw23TP612fEyGekRE6LNRiLYr/aqbHXNedw=="
},
"union-value"
:
{
"union-value"
:
{
"version"
:
"1.0.1"
,
"version"
:
"1.0.1"
,
"resolved"
:
"https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz"
,
"resolved"
:
"https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz"
,
...
...
package.json
View file @
79a4e4fa
...
@@ -21,20 +21,22 @@
...
@@ -21,20 +21,22 @@
},
},
"dependencies"
:
{
"dependencies"
:
{
"
@types/gm
"
:
"
^1.18.9
"
,
"
@types/gm
"
:
"
^1.18.9
"
,
"
@types/underscore
"
:
"
^1.10.23
"
,
"
axios
"
:
"
^0.20.0
"
,
"
axios
"
:
"
^0.20.0
"
,
"
cookie-parser
"
:
"
~1.4.4
"
,
"
cookie-parser
"
:
"
~1.4.4
"
,
"
debug
"
:
"
~2.6.9
"
,
"
debug
"
:
"
~2.6.9
"
,
"
express
"
:
"
~4.16.1
"
,
"
express
"
:
"
~4.16.1
"
,
"
imagemagick-native-12
"
:
"
^1.9.3
"
,
"
imagemagick-native-12
"
:
"
^1.9.3
"
,
"
morgan
"
:
"
^1.9.1
"
,
"
morgan
"
:
"
^1.9.1
"
,
"
promise-mysql
"
:
"
^4.1.3
"
"
promise-mysql
"
:
"
^4.1.3
"
,
"
underscore
"
:
"
^1.11.0
"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"
@types/cookie-parser
"
:
"
^1.4.2
"
,
"
@types/cookie-parser
"
:
"
^1.4.2
"
,
"
@types/express
"
:
"
^4.17.6
"
,
"
@types/express
"
:
"
^4.17.6
"
,
"
@types/jest
"
:
"
^25.2.3
"
,
"
@types/jest
"
:
"
^25.2.3
"
,
"
@types/morgan
"
:
"
^1.9.0
"
,
"
@types/morgan
"
:
"
^1.9.0
"
,
"
@types/node
"
:
"
^14.
0.9
"
,
"
@types/node
"
:
"
^14.
10.3
"
,
"
@types/supertest
"
:
"
^2.0.9
"
,
"
@types/supertest
"
:
"
^2.0.9
"
,
"
concurrently
"
:
"
^5.2.0
"
,
"
concurrently
"
:
"
^5.2.0
"
,
"
jest
"
:
"
^26.0.1
"
,
"
jest
"
:
"
^26.0.1
"
,
...
...
src/avatar.ts
View file @
79a4e4fa
...
@@ -83,7 +83,6 @@ export class Avatar {
...
@@ -83,7 +83,6 @@ export class Avatar {
let
content
:
string
;
let
content
:
string
;
let
queryResult
:
QueryResult
[]
let
queryResult
:
QueryResult
[]
queryResult
=
await
this
.
db
.
query
(
"
select content from `avatar_cache` where url = ? and size = ? limit 1
"
,
[
url
,
size
]);
queryResult
=
await
this
.
db
.
query
(
"
select content from `avatar_cache` where url = ? and size = ? limit 1
"
,
[
url
,
size
]);
console
.
log
(
queryResult
);
if
(
queryResult
.
length
)
{
if
(
queryResult
.
length
)
{
content
=
queryResult
[
0
].
content
;
content
=
queryResult
[
0
].
content
;
buffer
=
Buffer
.
from
(
content
,
"
base64
"
);
buffer
=
Buffer
.
from
(
content
,
"
base64
"
);
...
@@ -110,20 +109,21 @@ export class Avatar {
...
@@ -110,20 +109,21 @@ export class Avatar {
content
content
});
});
}
}
const
resizedContent
:
string
=
await
this
.
processor
.
addTask
(
"
cut
"
,
{
const
resizedContent
Array
:
number
[]
=
await
this
.
processor
.
addTask
(
"
cut
"
,
{
image
:
content
,
image
:
buffer
.
toJSON
().
data
,
filename
,
filename
,
size
size
}
as
CutData
);
}
as
CutData
);
if
(
!
resizedContent
)
{
if
(
!
resizedContent
Array
)
{
console
.
error
(
`Error resizing image of
${
username
}
${
url
}
with size
${
size
}
.`
);
console
.
error
(
`Error resizing image of
${
username
}
${
url
}
with size
${
size
}
.`
);
return
null
;
return
null
;
}
}
const
resizedBuffer
=
Buffer
.
from
(
resizedContentArray
);
await
this
.
db
.
query
(
"
insert into `avatar_cache` set ?
"
,
{
await
this
.
db
.
query
(
"
insert into `avatar_cache` set ?
"
,
{
url
,
url
,
size
,
size
,
content
:
resized
Content
content
:
resized
Buffer
.
toString
(
"
base64
"
)
});
});
return
Buffer
.
from
(
resizedContent
,
"
base64
"
)
;
return
resizedBuffer
;
}
}
}
}
src/utility.ts
View file @
79a4e4fa
export
interface
CutData
{
export
interface
CutData
{
image
:
string
,
// base64
image
:
number
[],
filename
:
string
,
filename
:
string
,
size
:
number
size
:
number
}
}
src/worker.ts
View file @
79a4e4fa
...
@@ -8,16 +8,15 @@ export default async function worker() {
...
@@ -8,16 +8,15 @@ export default async function worker() {
const
processor
=
new
Processor
();
const
processor
=
new
Processor
();
processor
.
addHandler
(
"
cut
"
,
async
(
cutData
:
CutData
)
=>
{
processor
.
addHandler
(
"
cut
"
,
async
(
cutData
:
CutData
)
=>
{
try
{
try
{
console
.
log
(
cutData
.
image
);
const
sourceBuffer
=
Buffer
.
from
(
cutData
.
image
);
const
buf
=
Buffer
.
from
(
cutData
.
image
);
const
targetBuffer
:
Buffer
=
await
magick
.
promises
.
convert
({
const
targetBuffer
:
Buffer
=
await
util
.
promisify
(
magick
.
convert
)({
srcFormat
:
"
PNG
"
,
srcFormat
:
"
PNG
"
,
format
:
"
PNG
"
,
format
:
"
PNG
"
,
srcData
:
buf
,
srcData
:
sourceBuffer
,
width
:
cutData
.
size
,
width
:
cutData
.
size
,
height
:
cutData
.
size
height
:
cutData
.
size
});
});
return
targetBuffer
.
to
String
(
"
base64
"
)
;
return
targetBuffer
.
to
JSON
().
data
;
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
`Worker
${
cluster
.
worker
.
id
}
: Error resizing image to
${
cutData
.
size
}
:
${
e
.
toString
()}
`
);
console
.
error
(
`Worker
${
cluster
.
worker
.
id
}
: Error resizing image to
${
cutData
.
size
}
:
${
e
.
toString
()}
`
);
return
null
;
return
null
;
...
...
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