Skip to content

Commit 44284c2

Browse files
committed
fix: 修复文件大小和更新日期不展示的问题
1 parent 3c4a05f commit 44284c2

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

backend/src/cgi.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ async function main() {
7373
if (type) {
7474
console.log(`Content-Type: ${type}`)
7575
console.log(`Content-Length: ${body.size}`)
76+
console.log('Access-Control-Expose-Headers: X-Size,X-Update-Date,X-Create-Date')
77+
console.log(`X-Size: ${body.size}`)
78+
console.log(`X-Update-Date: ${body.mtime}`)
79+
console.log(`X-Create-Date: ${body.birthtime}`)
7680
console.log('')
7781
body.stream.pipe(process.stdout)
7882
} else {

backend/src/koa.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ app.use(async (ctx) => {
2222
if (type) {
2323
ctx.set('Content-Type', type)
2424
ctx.set('Content-Length', body.size)
25+
ctx.set('Access-Control-Expose-Headers', 'X-Size,X-Update-Date,X-Create-Date')
26+
ctx.set('X-Size', body.size)
27+
ctx.set('X-Update-Date', body.mtime)
28+
ctx.set('X-Create-Date', body.birthtime)
2529
ctx.body = body.stream
2630
} else {
2731
ctx.set('Content-Type', 'application/json; charset=utf-8')

backend/src/router/read.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module.exports = async function ({ query }) {
1919

2020
if (query.cache) {
2121
const maxAge = 365 * 24 * 60 * 60
22-
2322
console.log(`Cache-Control: public, max-age=${maxAge}, immutable`)
2423
console.log(`Expires: ${new Date(Date.now() + maxAge * 1000).toUTCString()}`)
2524
console.log(`ETag: "${stat.size}-${stat.mtime.getTime()}"`)
@@ -31,7 +30,8 @@ module.exports = async function ({ query }) {
3130
msg: '操作成功',
3231
data: {
3332
size: stat.size,
34-
time: stat.mtime.toUTCString(),
33+
mtime: stat.mtime.toUTCString(),
34+
birthtime: stat.birthtime.toUTCString(),
3535
filename: filePath.split('/').pop(),
3636
stream: fs.createReadStream(filePath),
3737
},

frontend/components.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ export {}
1212
/* prettier-ignore */
1313
declare module 'vue' {
1414
export interface GlobalComponents {
15-
2: typeof import('./src/components/icons/OfficeWord copy 2.vue')['default']
1615
ClickMove: typeof import('./src/components/ClickMove.vue')['default']
1716
Code: typeof import('./src/components/icons/Code.vue')['default']
18-
copy: typeof import('./src/components/icons/Feiniu copy.vue')['default']
1917
ElButton: typeof import('element-plus/es')['ElButton']
2018
ElDialog: typeof import('element-plus/es')['ElDialog']
2119
ElIcon: typeof import('element-plus/es')['ElIcon']
@@ -50,10 +48,8 @@ declare module 'vue' {
5048

5149
// For TSX support
5250
declare global {
53-
const 2: typeof import('./src/components/icons/OfficeWord copy 2.vue')['default']
5451
const ClickMove: typeof import('./src/components/ClickMove.vue')['default']
5552
const Code: typeof import('./src/components/icons/Code.vue')['default']
56-
const copy: typeof import('./src/components/icons/Feiniu copy.vue')['default']
5753
const ElButton: typeof import('element-plus/es')['ElButton']
5854
const ElDialog: typeof import('element-plus/es')['ElDialog']
5955
const ElIcon: typeof import('element-plus/es')['ElIcon']

frontend/src/hooks/useCode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export default function useCode(option: OptionModel) {
5555
return
5656
}
5757

58-
code.byte = headers['content-length'] ? Number(headers['content-length']) : undefined
59-
code.date = headers['last-modified'] ? dayjs(headers['last-modified']) : undefined
58+
code.byte = headers['x-size'] ? Number(headers['x-size']) : undefined
59+
code.date = headers['x-update-date'] ? dayjs(headers['x-update-date']) : undefined
6060

6161
code.blob = data
6262
code.path = path

0 commit comments

Comments
 (0)