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
7231a554
Commit
7231a554
authored
Feb 18, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cache only succeeded things
parent
49f17d59
Pipeline
#20243
passed with stages
in 6 minutes
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
6 deletions
+7
-6
src/app.controller.ts
src/app.controller.ts
+6
-1
src/app.service.ts
src/app.service.ts
+1
-5
No files found.
src/app.controller.ts
View file @
7231a554
...
@@ -4,12 +4,14 @@ import {
...
@@ -4,12 +4,14 @@ import {
Header
,
Header
,
Param
,
Param
,
ParseIntPipe
,
ParseIntPipe
,
Res
,
StreamableFile
,
StreamableFile
,
}
from
'
@nestjs/common
'
;
}
from
'
@nestjs/common
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
AppService
}
from
'
./app.service
'
;
import
{
ApiOperation
,
ApiParam
,
ApiProduces
}
from
'
@nestjs/swagger
'
;
import
{
ApiOperation
,
ApiParam
,
ApiProduces
}
from
'
@nestjs/swagger
'
;
import
{
BlankReturnMessageDto
}
from
'
./dto/ReturnMessage.dto
'
;
import
{
BlankReturnMessageDto
}
from
'
./dto/ReturnMessage.dto
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
Response
}
from
'
express
'
;
@
Controller
()
@
Controller
()
export
class
AppController
{
export
class
AppController
{
...
@@ -21,7 +23,6 @@ export class AppController {
...
@@ -21,7 +23,6 @@ export class AppController {
)
{}
)
{}
@
Get
(
'
avatar/:username/:size/:filename.png
'
)
@
Get
(
'
avatar/:username/:size/:filename.png
'
)
@
Header
(
'
Cache-Control
'
,
'
public, max-age=600
'
)
@
ApiOperation
({
summary
:
'
获取裁剪后的用户头像
'
})
@
ApiOperation
({
summary
:
'
获取裁剪后的用户头像
'
})
@
ApiParam
({
name
:
'
username
'
,
description
:
'
用户名
'
})
@
ApiParam
({
name
:
'
username
'
,
description
:
'
用户名
'
})
@
ApiParam
({
name
:
'
size
'
,
description
:
'
头像尺寸
'
,
type
:
'
number
'
})
@
ApiParam
({
name
:
'
size
'
,
description
:
'
头像尺寸
'
,
type
:
'
number
'
})
...
@@ -30,11 +31,13 @@ export class AppController {
...
@@ -30,11 +31,13 @@ export class AppController {
async
getImage
(
async
getImage
(
@
Param
(
'
username
'
)
username
:
string
,
@
Param
(
'
username
'
)
username
:
string
,
@
Param
(
'
size
'
,
ParseIntPipe
)
size
:
number
,
@
Param
(
'
size
'
,
ParseIntPipe
)
size
:
number
,
@
Res
({
passthrough
:
true
})
res
:
Response
,
)
{
)
{
if
(
size
<
8
||
size
>
1000
)
{
if
(
size
<
8
||
size
>
1000
)
{
throw
new
BlankReturnMessageDto
(
400
,
'
Invalid size
'
).
toException
();
throw
new
BlankReturnMessageDto
(
400
,
'
Invalid size
'
).
toException
();
}
}
const
buffer
=
await
this
.
appService
.
getImage
(
username
,
size
);
const
buffer
=
await
this
.
appService
.
getImage
(
username
,
size
);
res
.
header
(
'
Cache-Control
'
,
'
public, max-age=600
'
);
return
new
StreamableFile
(
buffer
,
{
return
new
StreamableFile
(
buffer
,
{
type
:
'
image/png
'
,
type
:
'
image/png
'
,
disposition
:
'
inline
'
,
disposition
:
'
inline
'
,
...
@@ -51,6 +54,7 @@ export class AppController {
...
@@ -51,6 +54,7 @@ export class AppController {
async
getAnyImage
(
async
getAnyImage
(
@
Param
(
'
url
'
)
url
:
string
,
@
Param
(
'
url
'
)
url
:
string
,
@
Param
(
'
size
'
,
ParseIntPipe
)
size
:
number
,
@
Param
(
'
size
'
,
ParseIntPipe
)
size
:
number
,
@
Res
({
passthrough
:
true
})
res
:
Response
,
)
{
)
{
if
(
size
<
8
||
size
>
1000
)
{
if
(
size
<
8
||
size
>
1000
)
{
throw
new
BlankReturnMessageDto
(
400
,
'
Invalid size
'
).
toException
();
throw
new
BlankReturnMessageDto
(
400
,
'
Invalid size
'
).
toException
();
...
@@ -62,6 +66,7 @@ export class AppController {
...
@@ -62,6 +66,7 @@ export class AppController {
`
${
this
.
urlGetPrefix
}${
url
}
`
,
`
${
this
.
urlGetPrefix
}${
url
}
`
,
size
,
size
,
);
);
res
.
header
(
'
Cache-Control
'
,
'
public, max-age=31536000
'
);
return
new
StreamableFile
(
buffer
,
{
return
new
StreamableFile
(
buffer
,
{
type
:
'
image/png
'
,
type
:
'
image/png
'
,
disposition
:
'
inline
'
,
disposition
:
'
inline
'
,
...
...
src/app.service.ts
View file @
7231a554
...
@@ -18,11 +18,7 @@ export class AppService extends ConsoleLogger {
...
@@ -18,11 +18,7 @@ export class AppService extends ConsoleLogger {
super
(
'
app
'
);
super
(
'
app
'
);
}
}
private
async
saveAvatar
(
private
async
saveAvatar
(
url
:
string
,
size
:
number
,
buffer
:
Buffer
)
{
url
:
string
,
size
:
number
,
buffer
:
Buffer
,
)
{
const
avatar
=
new
Avatar
();
const
avatar
=
new
Avatar
();
avatar
.
url
=
url
;
avatar
.
url
=
url
;
avatar
.
size
=
size
;
avatar
.
size
=
size
;
...
...
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