mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-30 17:03:09 +02:00
✌️
This commit is contained in:
parent
15e4cf1243
commit
faabb039a5
1 changed files with 15 additions and 10 deletions
|
@ -35,12 +35,23 @@ export default async function(ctx: Koa.Context) {
|
||||||
return;
|
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 ('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`);
|
const readable = fs.createReadStream(`${__dirname}/assets/thumbnail-not-available.png`);
|
||||||
ctx.set('Content-Type', 'image/png');
|
ctx.set('Content-Type', 'image/png');
|
||||||
ctx.body = readable;
|
ctx.body = readable;
|
||||||
|
} else if (file.contentType == 'image/gif') {
|
||||||
|
// GIF
|
||||||
|
await sendRaw();
|
||||||
} else {
|
} else {
|
||||||
const thumb = await DriveFileThumbnail.findOne({ 'metadata.originalId': fileId });
|
const thumb = await DriveFileThumbnail.findOne({ 'metadata.originalId': fileId });
|
||||||
if (thumb != null) {
|
if (thumb != null) {
|
||||||
|
@ -48,9 +59,7 @@ export default async function(ctx: Koa.Context) {
|
||||||
const bucket = await getDriveFileThumbnailBucket();
|
const bucket = await getDriveFileThumbnailBucket();
|
||||||
ctx.body = bucket.openDownloadStream(thumb._id);
|
ctx.body = bucket.openDownloadStream(thumb._id);
|
||||||
} else {
|
} else {
|
||||||
ctx.set('Content-Type', file.contentType);
|
await sendRaw();
|
||||||
const bucket = await getDriveFileBucket();
|
|
||||||
ctx.body = bucket.openDownloadStream(fileId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -58,10 +67,6 @@ export default async function(ctx: Koa.Context) {
|
||||||
ctx.set('Content-Disposition', 'attachment');
|
ctx.set('Content-Disposition', 'attachment');
|
||||||
}
|
}
|
||||||
|
|
||||||
const bucket = await getDriveFileBucket();
|
await sendRaw();
|
||||||
const readable = bucket.openDownloadStream(fileId);
|
|
||||||
readable.on('error', commonReadableHandlerGenerator(ctx));
|
|
||||||
ctx.set('Content-Type', file.contentType);
|
|
||||||
ctx.body = readable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue