mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add PRIV_UNLIMITED_QUOTA check
This commit is contained in:
1 parent
9b2839846b
commit
22201794ce
2 files changed
+3
-3
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.14.18",
|
"version": "3.14.19",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -50,14 +50,14 @@ export class FilesHandler extends Handler {
|
|||||||
async postUploadFile(domainId: string, filename: string) {
|
async postUploadFile(domainId: string, filename: string) {
|
||||||
this.checkPriv(PRIV.PRIV_CREATE_FILE);
|
this.checkPriv(PRIV.PRIV_CREATE_FILE);
|
||||||
if ((this.user._files?.length || 0) >= system.get('limit.user_files')) {
|
if ((this.user._files?.length || 0) >= system.get('limit.user_files')) {
|
||||||
throw new ForbiddenError('File limit exceeded.');
|
if (!this.user.hasPriv(PRIV.PRIV_UNLIMITED_QUOTA)) throw new ForbiddenError('File limit exceeded.');
|
||||||
}
|
}
|
||||||
const file = this.request.files?.file;
|
const file = this.request.files?.file;
|
||||||
if (!file) throw new ValidationError('file');
|
if (!file) throw new ValidationError('file');
|
||||||
const f = statSync(file.filepath);
|
const f = statSync(file.filepath);
|
||||||
const size = Math.sum((this.user._files || []).map((i) => i.size)) + f.size;
|
const size = Math.sum((this.user._files || []).map((i) => i.size)) + f.size;
|
||||||
if (size >= system.get('limit.user_files_size')) {
|
if (size >= system.get('limit.user_files_size')) {
|
||||||
throw new ForbiddenError('File size limit exceeded.');
|
if (!this.user.hasPriv(PRIV.PRIV_UNLIMITED_QUOTA)) throw new ForbiddenError('File size limit exceeded.');
|
||||||
}
|
}
|
||||||
if (!filename) filename = file.originalFilename || String.random(16);
|
if (!filename) filename = file.originalFilename || String.random(16);
|
||||||
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', null, 'Bad filename');
|
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', null, 'Bad filename');
|
||||||
|
|||||||
Reference in new issue
Block a user