mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
fs_upload支持redirect字段,添加stream2buffer函数
This commit is contained in:
1 parent
86689e8d4c
commit
327fec1fea
5 files changed
+32
-6
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.12.24",
|
||||
"version": "2.12.25",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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)));
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user