summaryrefslogtreecommitdiff
path: root/src/server/file
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-05-03 20:12:08 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-05-03 20:12:08 +0900
commitfaabb039a59560e8e311fb2bad8caa58371f0caa (patch)
treeb0b7b3f0c288f66da333c0a7659a328377091ebd /src/server/file
parentサムネイルを予め生成するように (diff)
downloadsharkey-faabb039a59560e8e311fb2bad8caa58371f0caa.tar.gz
sharkey-faabb039a59560e8e311fb2bad8caa58371f0caa.tar.bz2
sharkey-faabb039a59560e8e311fb2bad8caa58371f0caa.zip
:v:
Diffstat (limited to 'src/server/file')
-rw-r--r--src/server/file/send-drive-file.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/server/file/send-drive-file.ts b/src/server/file/send-drive-file.ts
index 8719ddf70c..c6f368b418 100644
--- a/src/server/file/send-drive-file.ts
+++ b/src/server/file/send-drive-file.ts
@@ -35,12 +35,23 @@ export default async function(ctx: Koa.Context) {
return;
}
+ const sendRaw = async () => {
+ const bucket = await getDriveFileBucket();
+ const readable = bucket.openDownloadStream(fileId);
+ readable.on('error', commonReadableHandlerGenerator(ctx));
+ ctx.set('Content-Type', file.contentType);
+ ctx.body = readable;
+ };
+
if ('thumbnail' in ctx.query) {
- // 動画か画像以外
- if (!/^image\/.*$/.test(file.contentType) && !/^video\/.*$/.test(file.contentType)) {
+ // 画像以外
+ if (!file.contentType.startsWith('image/')) {
const readable = fs.createReadStream(`${__dirname}/assets/thumbnail-not-available.png`);
ctx.set('Content-Type', 'image/png');
ctx.body = readable;
+ } else if (file.contentType == 'image/gif') {
+ // GIF
+ await sendRaw();
} else {
const thumb = await DriveFileThumbnail.findOne({ 'metadata.originalId': fileId });
if (thumb != null) {
@@ -48,9 +59,7 @@ export default async function(ctx: Koa.Context) {
const bucket = await getDriveFileThumbnailBucket();
ctx.body = bucket.openDownloadStream(thumb._id);
} else {
- ctx.set('Content-Type', file.contentType);
- const bucket = await getDriveFileBucket();
- ctx.body = bucket.openDownloadStream(fileId);
+ await sendRaw();
}
}
} else {
@@ -58,10 +67,6 @@ export default async function(ctx: Koa.Context) {
ctx.set('Content-Disposition', 'attachment');
}
- const bucket = await getDriveFileBucket();
- const readable = bucket.openDownloadStream(fileId);
- readable.on('error', commonReadableHandlerGenerator(ctx));
- ctx.set('Content-Type', file.contentType);
- ctx.body = readable;
+ await sendRaw();
}
}