Spaces:
Sleeping
Sleeping
File size: 943 Bytes
072e993 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import express from 'express'
import cookieParser from 'cookie-parser'
import contentDisposition from 'content-disposition'
import { resolve } from 'node:path'
export class Middleware extends plugin {
constructor () {
super({
name: '中间件',
priority: 1,
rule: [
{
method: 'use',
use: 'middleware'
},
{
method: 'use',
path: '/download',
use: 'staticDownload'
}
]
})
}
middleware () {
return [
cookieParser(),
express.urlencoded({ limit: '500kb', extended: false }),
express.json({ limit: '500kb' }),
express.static(resolve('public'), { dotfiles: 'ignore', maxAge: '5m' })
]
}
staticDownload () {
return express.static(resolve('public/.download'), {
index: false,
setHeaders: (res, path) => res.setHeader('Content-Disposition', contentDisposition(path))
})
}
} |