summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/services')
-rw-r--r--src/services/drive/add-file.ts15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts
index 0938b18415..5be71bc0a2 100644
--- a/src/services/drive/add-file.ts
+++ b/src/services/drive/add-file.ts
@@ -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);
}
/**