fs_upload支持redirect字段,添加stream2buffer函数

This commit is contained in:
undefined committed 2020-09-02 23:12:39 +08:00
1 parent 86689e8d4c
commit 327fec1fea
5 files changed
+32 -6

No files matched your search

+7 -1
View File
@@ -39,7 +39,8 @@ class FileUploadHandler extends Handler {
}
@param('title', Types.String)
async post(domainId: string, title: string) {
@param('redirect', Types.String, true)
async post(domainId: string, title: string, redirect?: string) {
if (!this.request.files.file) throw new BadRequestError();
const quota = await this.getQuota();
const lfdoc = await fs.promises.stat(this.request.files.file.path);
@@ -53,6 +54,11 @@ class FileUploadHandler extends Handler {
}
const fdoc = await file.getMeta(ufid);
this.response.template = 'fs_upload.html';
if (redirect) {
this.response.redirect = redirect.includes('?')
? `${redirect}&ufid=${ufid}`
: `${redirect}?ufid=${ufid}`;
}
this.response.body = {
fdoc, ufid, usage: udoc.usage, quota,
};
+9
View File
@@ -170,3 +170,12 @@ export function isClass(obj: any, strict = false) {
}
return false;
}
export function streamToBuffer(stream): Promise<Buffer> {
return new Promise((resolve, reject) => {
const buffers = [];
stream.on('error', reject);
stream.on('data', (data) => buffers.push(data));
stream.on('end', () => resolve(Buffer.concat(buffers)));
});
}