Image for web publish (#3402)
* Image for Web * Add comment * Make main to original
This commit is contained in:
parent
0863e5d379
commit
bcb04924ff
14 changed files with 283 additions and 43 deletions
|
@ -3,6 +3,7 @@ import * as send from 'koa-send';
|
|||
import * as mongodb from 'mongodb';
|
||||
import DriveFile, { getDriveFileBucket } from '../../models/drive-file';
|
||||
import DriveFileThumbnail, { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail';
|
||||
import DriveFileWebpublic, { getDriveFileWebpublicBucket } from '../../models/drive-file-webpublic';
|
||||
|
||||
const assets = `${__dirname}/../../server/file/assets/`;
|
||||
|
||||
|
@ -41,6 +42,11 @@ export default async function(ctx: Koa.Context) {
|
|||
}
|
||||
|
||||
const sendRaw = async () => {
|
||||
if (file.metadata && file.metadata.accessKey && file.metadata.accessKey != ctx.query['original']) {
|
||||
ctx.status = 403;
|
||||
return;
|
||||
}
|
||||
|
||||
const bucket = await getDriveFileBucket();
|
||||
const readable = bucket.openDownloadStream(fileId);
|
||||
readable.on('error', commonReadableHandlerGenerator(ctx));
|
||||
|
@ -60,6 +66,19 @@ export default async function(ctx: Koa.Context) {
|
|||
} else {
|
||||
await sendRaw();
|
||||
}
|
||||
} else if ('web' in ctx.query) {
|
||||
const web = await DriveFileWebpublic.findOne({
|
||||
'metadata.originalId': fileId
|
||||
});
|
||||
|
||||
if (web != null) {
|
||||
ctx.set('Content-Type', file.contentType);
|
||||
|
||||
const bucket = await getDriveFileWebpublicBucket();
|
||||
ctx.body = bucket.openDownloadStream(web._id);
|
||||
} else {
|
||||
await sendRaw();
|
||||
}
|
||||
} else {
|
||||
if ('download' in ctx.query) {
|
||||
ctx.set('Content-Disposition', 'attachment');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue