mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Provide filename via Content-Disposition when accessing asset (#16809)
* Provide filename via Content-Disposition when accessing asset * Remove unused const --------- Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -93,8 +93,8 @@
|
||||
"@directus/utils": "workspace:*",
|
||||
"@godaddy/terminus": "4.11.2",
|
||||
"@rollup/plugin-alias": "4.0.3",
|
||||
"@rollup/plugin-virtual": "3.0.1",
|
||||
"@rollup/plugin-node-resolve": "15.0.1",
|
||||
"@rollup/plugin-virtual": "3.0.1",
|
||||
"argon2": "0.30.3",
|
||||
"async": "3.2.4",
|
||||
"axios": "1.3.4",
|
||||
@@ -104,6 +104,7 @@
|
||||
"chalk": "4.1.2",
|
||||
"chokidar": "3.5.3",
|
||||
"commander": "9.5.0",
|
||||
"content-disposition": "0.5.4",
|
||||
"cookie-parser": "1.4.6",
|
||||
"cors": "2.8.5",
|
||||
"csv-parser": "3.0.0",
|
||||
@@ -176,6 +177,7 @@
|
||||
"@types/async": "3.2.18",
|
||||
"@types/busboy": "1.5.0",
|
||||
"@types/bytes": "3.1.1",
|
||||
"@types/content-disposition": "0.5.5",
|
||||
"@types/cookie-parser": "1.4.3",
|
||||
"@types/cors": "2.8.13",
|
||||
"@types/deep-diff": "1.0.2",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Range } from '@directus/storage';
|
||||
import { parseJSON } from '@directus/utils';
|
||||
import contentDisposition from 'content-disposition';
|
||||
import { Router } from 'express';
|
||||
import { merge, pick } from 'lodash-es';
|
||||
import { ASSET_TRANSFORM_QUERY_KEYS, SYSTEM_ASSET_ALLOW_LIST } from '../constants.js';
|
||||
@@ -166,7 +167,8 @@ router.get(
|
||||
|
||||
const { stream, file, stat } = await service.getAsset(id, transformation, range);
|
||||
|
||||
res.attachment(req.params['filename'] ?? file.filename_download);
|
||||
const filename = req.params['filename'] ?? file.filename_download;
|
||||
res.attachment(filename);
|
||||
res.setHeader('Content-Type', file.type);
|
||||
res.setHeader('Accept-Ranges', 'bytes');
|
||||
res.setHeader('Cache-Control', getCacheControlHeader(req, getMilliseconds(env['ASSETS_CACHE_TTL']), false, true));
|
||||
@@ -186,7 +188,7 @@ router.get(
|
||||
}
|
||||
|
||||
if ('download' in req.query === false) {
|
||||
res.removeHeader('Content-Disposition');
|
||||
res.setHeader('Content-Disposition', contentDisposition(filename, { type: 'inline' }));
|
||||
}
|
||||
|
||||
if (req.method.toLowerCase() === 'head') {
|
||||
|
||||
Reference in New Issue
Block a user