Content-Disposition in ObjectStrage (#4524)

* Content-Disposition in ObjectStrage

* encode filename
This commit is contained in:
MeiMei
2019-03-18 15:23:45 +09:00
committed by syuilo
parent bd720491a9
commit c2eec272e6
4 changed files with 23 additions and 10 deletions

View File

@@ -26,6 +26,7 @@ import { driveLogger } from './logger';
import { IImage, ConvertToJpeg, ConvertToWebp, ConvertToPng } from './image-processor';
import Instance from '../../models/instance';
import checkSvg from '../../misc/check-svg';
import { contentDisposition } from '../../misc/content-disposition';
const logger = driveLogger.createSubLogger('register', 'yellow');
@@ -69,7 +70,7 @@ async function save(path: string, name: string, type: string, hash: string, size
//#region Uploads
logger.info(`uploading original: ${key}`);
const uploads = [
upload(key, fs.createReadStream(path), type)
upload(key, fs.createReadStream(path), type, name)
];
if (alts.webpublic) {
@@ -77,7 +78,7 @@ async function save(path: string, name: string, type: string, hash: string, size
webpublicUrl = `${ baseUrl }/${ webpublicKey }`;
logger.info(`uploading webpublic: ${webpublicKey}`);
uploads.push(upload(webpublicKey, alts.webpublic.data, alts.webpublic.type));
uploads.push(upload(webpublicKey, alts.webpublic.data, alts.webpublic.type, name));
}
if (alts.thumbnail) {
@@ -198,13 +199,17 @@ export async function generateAlts(path: string, type: string, generateWeb: bool
/**
* Upload to ObjectStorage
*/
async function upload(key: string, stream: fs.ReadStream | Buffer, type: string) {
async function upload(key: string, stream: fs.ReadStream | Buffer, type: string, filename?: string) {
const minio = new Minio.Client(config.drive.config);
await minio.putObject(config.drive.bucket, key, stream, null, {
const metadata = {
'Content-Type': type,
'Cache-Control': 'max-age=31536000, immutable'
});
} as Minio.ItemBucketMetadata;
if (filename) metadata['Content-Disposition'] = contentDisposition('inline', filename);
await minio.putObject(config.drive.bucket, key, stream, null, metadata);
}
/**