forked from FoundKeyGang/FoundKey
/files/ 下のヘッダ設定タイミングを修正 (#5650)
This commit is contained in:
parent
4229065a69
commit
cbbdc98744
2 changed files with 13 additions and 13 deletions
|
@ -12,19 +12,14 @@ import sendDriveFile from './send-drive-file';
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
app.use(async (ctx, next) => {
|
|
||||||
// Cache 365days
|
|
||||||
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
|
||||||
await next();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Init router
|
// Init router
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
router.get('/app-default.jpg', ctx => {
|
router.get('/app-default.jpg', ctx => {
|
||||||
const file = fs.createReadStream(`${__dirname}/assets/dummy.png`);
|
const file = fs.createReadStream(`${__dirname}/assets/dummy.png`);
|
||||||
ctx.set('Content-Type', 'image/jpeg');
|
|
||||||
ctx.body = file;
|
ctx.body = file;
|
||||||
|
ctx.set('Content-Type', 'image/jpeg');
|
||||||
|
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:key', sendDriveFile);
|
router.get('/:key', sendDriveFile);
|
||||||
|
|
|
@ -11,6 +11,7 @@ const assets = `${__dirname}/../../server/file/assets/`;
|
||||||
const commonReadableHandlerGenerator = (ctx: Koa.Context) => (e: Error): void => {
|
const commonReadableHandlerGenerator = (ctx: Koa.Context) => (e: Error): void => {
|
||||||
serverLogger.error(e);
|
serverLogger.error(e);
|
||||||
ctx.status = 500;
|
ctx.status = 500;
|
||||||
|
ctx.set('Cache-Control', 'max-age=300');
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function(ctx: Koa.Context) {
|
export default async function(ctx: Koa.Context) {
|
||||||
|
@ -25,12 +26,14 @@ export default async function(ctx: Koa.Context) {
|
||||||
|
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
|
ctx.set('Cache-Control', 'max-age=86400');
|
||||||
await send(ctx as any, '/dummy.png', { root: assets });
|
await send(ctx as any, '/dummy.png', { root: assets });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file.storedInternal) {
|
if (!file.storedInternal) {
|
||||||
ctx.status = 204;
|
ctx.status = 204;
|
||||||
|
ctx.set('Cache-Control', 'max-age=86400');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,19 +41,21 @@ export default async function(ctx: Koa.Context) {
|
||||||
const isWebpublic = file.webpublicAccessKey === key;
|
const isWebpublic = file.webpublicAccessKey === key;
|
||||||
|
|
||||||
if (isThumbnail) {
|
if (isThumbnail) {
|
||||||
|
ctx.body = InternalStorage.read(key);
|
||||||
ctx.set('Content-Type', 'image/jpeg');
|
ctx.set('Content-Type', 'image/jpeg');
|
||||||
|
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
||||||
ctx.set('Content-Disposition', contentDisposition('inline', `${rename(file.name, { suffix: '-thumb', extname: '.jpeg' })}`));
|
ctx.set('Content-Disposition', contentDisposition('inline', `${rename(file.name, { suffix: '-thumb', extname: '.jpeg' })}`));
|
||||||
ctx.body = InternalStorage.read(key);
|
|
||||||
} else if (isWebpublic) {
|
} else if (isWebpublic) {
|
||||||
ctx.set('Content-Type', file.type === 'image/apng' ? 'image/png' : file.type);
|
|
||||||
ctx.set('Content-Disposition', contentDisposition('inline', `${rename(file.name, { suffix: '-web' })}`));
|
|
||||||
ctx.body = InternalStorage.read(key);
|
ctx.body = InternalStorage.read(key);
|
||||||
|
ctx.set('Content-Type', file.type === 'image/apng' ? 'image/png' : file.type);
|
||||||
|
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
||||||
|
ctx.set('Content-Disposition', contentDisposition('inline', `${rename(file.name, { suffix: '-web' })}`));
|
||||||
} else {
|
} else {
|
||||||
ctx.set('Content-Disposition', contentDisposition('inline', `${file.name}`));
|
|
||||||
|
|
||||||
const readable = InternalStorage.read(file.accessKey!);
|
const readable = InternalStorage.read(file.accessKey!);
|
||||||
readable.on('error', commonReadableHandlerGenerator(ctx));
|
readable.on('error', commonReadableHandlerGenerator(ctx));
|
||||||
ctx.set('Content-Type', file.type);
|
|
||||||
ctx.body = readable;
|
ctx.body = readable;
|
||||||
|
ctx.set('Content-Type', file.type);
|
||||||
|
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
||||||
|
ctx.set('Content-Disposition', contentDisposition('inline', `${file.name}`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue