Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
console
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
console
Commits
a9631fe6
Commit
a9631fe6
authored
Oct 10, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix error thing
parent
fc9c3eaf
Pipeline
#40987
passed with stages
in 1 minute and 9 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
14 deletions
+11
-14
console-api/src/update/update.controller.ts
console-api/src/update/update.controller.ts
+11
-14
No files found.
console-api/src/update/update.controller.ts
View file @
a9631fe6
...
@@ -4,6 +4,7 @@ import { ApiBody, ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiParam, Api
...
@@ -4,6 +4,7 @@ import { ApiBody, ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiParam, Api
import
{
DepotDto
}
from
'
../dto/Depot.dto
'
;
import
{
DepotDto
}
from
'
../dto/Depot.dto
'
;
import
{
Request
,
Response
}
from
'
express
'
;
import
{
Request
,
Response
}
from
'
express
'
;
import
{
createHash
}
from
'
crypto
'
;
import
{
createHash
}
from
'
crypto
'
;
import
{
ReturnMessageDto
}
from
'
src/dto/ReturnMessage.dto
'
;
function
md5HexOfString
(
s
:
string
)
{
function
md5HexOfString
(
s
:
string
)
{
return
createHash
(
'
md5
'
).
update
(
s
).
digest
(
'
hex
'
);
return
createHash
(
'
md5
'
).
update
(
s
).
digest
(
'
hex
'
);
...
@@ -11,7 +12,6 @@ function md5HexOfString(s: string) {
...
@@ -11,7 +12,6 @@ function md5HexOfString(s: string) {
/**
/**
* 以“稳定字节串”为准计算 ETag,并发送响应。
* 以“稳定字节串”为准计算 ETag,并发送响应。
* - 不捕获异常,让 Nest 接管错误处理
* - 若 If-None-Match 命中,返回 304
* - 若 If-None-Match 命中,返回 304
* - 若未显式设置 Cache-Control,则使用传入的默认值
* - 若未显式设置 Cache-Control,则使用传入的默认值
*/
*/
...
@@ -22,7 +22,14 @@ async function stableSend(
...
@@ -22,7 +22,14 @@ async function stableSend(
defaultCache
=
'
public, max-age=31536000, immutable
'
,
defaultCache
=
'
public, max-age=31536000, immutable
'
,
contentType
=
'
application/json; charset=utf-8
'
contentType
=
'
application/json; charset=utf-8
'
):
Promise
<
void
>
{
):
Promise
<
void
>
{
const
bodyResolved
=
await
body
;
let
bodyResolved
:
any
;
try
{
bodyResolved
=
await
body
;
}
catch
(
e
)
{
// this is error occurred
res
.
status
(
500
).
json
(
new
ReturnMessageDto
(
500
,
'
Internal Server Error
'
));
return
;
}
const
bodyString
=
typeof
bodyResolved
===
'
string
'
?
bodyResolved
:
JSON
.
stringify
(
bodyResolved
);
const
bodyString
=
typeof
bodyResolved
===
'
string
'
?
bodyResolved
:
JSON
.
stringify
(
bodyResolved
);
const
hash
=
md5HexOfString
(
bodyString
);
const
hash
=
md5HexOfString
(
bodyString
);
const
quoted
=
`"
${
hash
}
"`
;
const
quoted
=
`"
${
hash
}
"`
;
...
@@ -56,19 +63,9 @@ async function stableSend(
...
@@ -56,19 +63,9 @@ async function stableSend(
export
class
UpdateController
{
export
class
UpdateController
{
constructor
(
private
readonly
updateService
:
UpdateService
)
{}
constructor
(
private
readonly
updateService
:
UpdateService
)
{}
private
async
stableReturn
<
T
>
(
res
:
Response
,
prom
:
Promise
<
T
>
|
T
,
cache
=
'
public, max-age=31536000, immutable
'
)
{
const
result
=
await
prom
;
const
stringified
=
JSON
.
stringify
(
result
);
const
hash
=
createHash
(
'
md5
'
).
update
(
stringified
).
digest
(
'
hex
'
);
res
.
setHeader
(
'
ETag
'
,
`"
${
hash
}
"`
);
if
(
res
.
getHeader
(
'
Cache-Control
'
)
===
undefined
)
res
.
setHeader
(
'
Cache-Control
'
,
cache
);
res
.
end
(
stringified
);
// return result;
}
@
Get
(
'
apps.json
'
)
@
Get
(
'
apps.json
'
)
@
ApiOperation
({
summary
:
'
获取 apps.json
'
,
description
:
'
懒得解释这是啥了……
'
})
@
ApiOperation
({
summary
:
'
获取 apps.json
'
,
description
:
'
懒得解释这是啥了……
'
})
async
getAppsJson
(@
Req
()
req
:
Request
,
@
Res
(
{
passthrough
:
true
}
)
res
:
Response
)
{
async
getAppsJson
(@
Req
()
req
:
Request
,
@
Res
()
res
:
Response
)
{
await
stableSend
(
req
,
res
,
this
.
updateService
.
getAppsJson
(),
'
public, max-age=600, stale-while-revalidate=600, stale-if-error=604800
'
);
await
stableSend
(
req
,
res
,
this
.
updateService
.
getAppsJson
(),
'
public, max-age=600, stale-while-revalidate=600, stale-if-error=604800
'
);
return
;
return
;
}
}
...
@@ -81,7 +78,7 @@ export class UpdateController {
...
@@ -81,7 +78,7 @@ export class UpdateController {
// @Header('Cache-Control', 'public, max-age=31536000, immutable') // 可留给 stableSend 兜底
// @Header('Cache-Control', 'public, max-age=31536000, immutable') // 可留给 stableSend 兜底
async
getChecksum
(
async
getChecksum
(
@
Req
()
req
:
Request
,
@
Req
()
req
:
Request
,
@
Res
(
{
passthrough
:
true
}
)
res
:
Response
,
@
Res
()
res
:
Response
,
@
Param
(
'
id
'
)
id
:
string
,
@
Param
(
'
id
'
)
id
:
string
,
@
Query
(
new
ValidationPipe
({
transform
:
true
}))
depot
:
DepotDto
,
@
Query
(
new
ValidationPipe
({
transform
:
true
}))
depot
:
DepotDto
,
@
Param
(
'
version
'
)
version
:
string
,
@
Param
(
'
version
'
)
version
:
string
,
...
...
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