URI安全编码解码
This commit is contained in:
parent
9287e3dbc7
commit
a2c8eedb2f
@ -11,7 +11,12 @@ export default defineEventHandler(async event => {
|
||||
|
||||
// 处理 GET 请求
|
||||
if (event.node.req.method === 'GET') {
|
||||
const { id } = event.context.params
|
||||
const id = decodeURI(event.context.params.id)
|
||||
|
||||
// 检查文件是否存在
|
||||
if (!fs.existsSync(path.join(process.cwd(), 'data/gallery/image', id))) {
|
||||
return { error: 'file not found' }
|
||||
}
|
||||
|
||||
// 浏览器缓存一个月
|
||||
event.node.res.setHeader('Cache-Control', 'max-age=2629746,immutable')
|
||||
|
@ -23,8 +23,9 @@ export default defineEventHandler(async event => {
|
||||
const dirpath = await fs.promises.readdir(path.join(process.cwd(), 'data/gallery/image'))
|
||||
const list = await Promise.all(dirpath.map(async file => {
|
||||
const file_path = path.join(process.cwd(), 'data/gallery/image', file)
|
||||
console.log('file_path:', file_path)
|
||||
const dimensions = imageSize(await fs.promises.readFile(file_path))
|
||||
const image = '/api/gallery/' + file
|
||||
const image = encodeURI('/api/gallery/' + file)
|
||||
return { image, ...dimensions }
|
||||
}))
|
||||
console.log('list:', list)
|
||||
|
Loading…
Reference in New Issue
Block a user