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
092a96e0
Commit
092a96e0
authored
May 12, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
ee0cc0ae
Pipeline
#3244
failed with stages
in 2 minutes and 39 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
14 deletions
+30
-14
src/avatar.ts
src/avatar.ts
+30
-14
No files found.
src/avatar.ts
View file @
092a96e0
...
...
@@ -82,15 +82,23 @@ export class Avatar {
let
buffer
:
Buffer
;
let
content
:
string
;
let
queryResult
:
QueryResult
[]
try
{
queryResult
=
await
this
.
db
.
query
(
"
select content from `avatar_cache` where url = ? and size = ? limit 1
"
,
[
url
,
size
]);
if
(
queryResult
.
length
)
{
}
catch
(
e
)
{
console
.
error
(
`Failed to fetch avatar cache
${
url
}
${
size
}
:
${
e
.
toString
()}
`
);
}
if
(
queryResult
&&
queryResult
.
length
)
{
content
=
queryResult
[
0
].
content
;
buffer
=
Buffer
.
from
(
content
,
"
base64
"
);
return
buffer
;
}
console
.
error
(
`Resizing image of
${
username
}
${
url
}
with size
${
size
}
.`
);
try
{
queryResult
=
await
this
.
db
.
query
(
"
select content from `avatar_cache` where url = ? and size = 0 limit 1
"
,
[
url
,
size
]);
if
(
queryResult
.
length
)
{
}
catch
(
e
)
{
console
.
error
(
`Failed to fetch original avatar cache
${
url
}
${
size
}
:
${
e
.
toString
()}
`
);
}
if
(
queryResult
&&
queryResult
.
length
)
{
content
=
queryResult
[
0
].
content
;
buffer
=
Buffer
.
from
(
content
,
"
base64
"
);
}
else
{
...
...
@@ -103,11 +111,15 @@ export class Avatar {
return
null
;
}
content
=
buffer
.
toString
(
"
base64
"
);
try
{
await
this
.
db
.
query
(
"
insert into `avatar_cache` set ?
"
,
{
url
,
size
:
0
,
content
});
}
catch
(
e
)
{
console
.
error
(
`Failed to save original avatar cache
${
url
}
${
size
}
:
${
e
.
toString
()}
`
);
}
}
const
resizedContentArray
:
number
[]
=
await
this
.
processor
.
addTask
(
"
cut
"
,
{
image
:
buffer
.
toJSON
().
data
,
...
...
@@ -119,11 +131,15 @@ export class Avatar {
return
null
;
}
const
resizedBuffer
=
Buffer
.
from
(
resizedContentArray
);
try
{
await
this
.
db
.
query
(
"
insert into `avatar_cache` set ?
"
,
{
url
,
size
,
content
:
resizedBuffer
.
toString
(
"
base64
"
)
});
}
catch
(
e
)
{
console
.
error
(
`Failed to save avatar cache
${
url
}
${
size
}
:
${
e
.
toString
()}
`
);
}
return
resizedBuffer
;
}
}
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