Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
A
Avatar Handler Re
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
MyCard
Avatar Handler Re
Commits
ccc94c73
Commit
ccc94c73
authored
Jan 07, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tune
parent
867eae47
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
src/app.service.ts
src/app.service.ts
+11
-10
src/dto/ReturnMessage.dto.ts
src/dto/ReturnMessage.dto.ts
+0
-1
src/image/image.service.ts
src/image/image.service.ts
+1
-1
No files found.
src/app.service.ts
View file @
ccc94c73
...
...
@@ -16,6 +16,14 @@ export class AppService extends ConsoleLogger {
super
(
'
app
'
);
}
private
async
saveAvatar
(
url
:
string
,
size
:
number
,
buffer
:
Buffer
)
{
const
avatar
=
new
Avatar
();
avatar
.
url
=
url
;
avatar
.
size
=
size
;
avatar
.
fromBuffer
(
buffer
);
return
this
.
db
.
getRepository
(
Avatar
).
save
(
avatar
);
}
async
getImage
(
username
:
string
,
size
:
number
)
{
const
url
=
await
this
.
avatarApi
.
getURLFromUsername
(
username
);
const
existingAvatar
=
await
this
.
db
.
getRepository
(
Avatar
).
findOne
({
...
...
@@ -27,6 +35,7 @@ export class AppService extends ConsoleLogger {
if
(
existingAvatar
)
{
return
existingAvatar
.
toBuffer
();
}
this
.
log
(
`Resizing
${
url
}
to
${
size
}
`
);
let
originalAvatarBuffer
:
Buffer
;
const
originalAvatar
=
await
this
.
db
.
getRepository
(
Avatar
).
findOne
({
where
:
{
...
...
@@ -39,22 +48,14 @@ export class AppService extends ConsoleLogger {
}
else
{
originalAvatarBuffer
=
await
this
.
avatarApi
.
downloadAvatar
(
url
);
try
{
await
this
.
db
.
getRepository
(
Avatar
).
save
({
url
,
size
:
0
,
buffer
:
originalAvatarBuffer
,
});
await
this
.
saveAvatar
(
url
,
0
,
originalAvatarBuffer
);
}
catch
(
e
)
{
this
.
error
(
`Fail to save original avatar:
${
e
.
message
}
`
);
}
}
const
avatarBuffer
=
await
this
.
image
.
resize
(
originalAvatarBuffer
,
size
);
try
{
const
avatar
=
new
Avatar
();
avatar
.
url
=
url
;
avatar
.
size
=
size
;
avatar
.
fromBuffer
(
avatarBuffer
);
await
this
.
db
.
getRepository
(
Avatar
).
save
(
avatar
);
await
this
.
saveAvatar
(
url
,
size
,
avatarBuffer
);
}
catch
(
e
)
{
this
.
error
(
`Fail to save avatar:
${
e
.
message
}
`
);
}
...
...
src/dto/ReturnMessage.dto.ts
View file @
ccc94c73
import
{
ApiProperty
}
from
'
@nestjs/swagger
'
;
import
{
HttpException
}
from
'
@nestjs/common
'
;
import
{
User
}
from
'
../entities/User.entity
'
;
import
{
PageSettingsWise
}
from
'
./PageSettings.dto
'
;
export
interface
BlankReturnMessage
{
...
...
src/image/image.service.ts
View file @
ccc94c73
...
...
@@ -16,7 +16,7 @@ export class ImageService extends ConsoleLogger {
height
:
size
,
});
}
catch
(
e
)
{
console
.
error
(
`Error resizing image to
${
size
}
:
${
e
.
toString
()}
`
);
this
.
error
(
`Error resizing image to
${
size
}
:
${
e
.
toString
()}
`
);
throw
new
BlankReturnMessageDto
(
500
,
'
Error resizing image
'
);
}
}
...
...
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