add size limit for audio/video
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
"added": "Successfully added audio",
|
||||
"removed": "Successfully removed audio",
|
||||
"notFound": "Video not found",
|
||||
"fileTooLarge": "File too large {{ file }}",
|
||||
"failedToAdd": "Failed to add audio, {{ error }}",
|
||||
"fileNotFound": "File not found {{file}}",
|
||||
"fileNotSupported": "File not supported {{file}}",
|
||||
@@ -45,6 +46,7 @@
|
||||
"added": "Successfully added video",
|
||||
"removed": "Successfully removed video",
|
||||
"notFound": "Video not found",
|
||||
"fileTooLarge": "File too large {{ file }}",
|
||||
"failedToAdd": "Failed to add video, {{ error }}",
|
||||
"fileNotFound": "File not found {{file}}",
|
||||
"fileNotSupported": "File not supported {{file}}",
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"added": "成功添加音频",
|
||||
"removed": "成功删除音频",
|
||||
"notFound": "未找到音频",
|
||||
"fileTooLarge": "文件太大了 {{ file }}",
|
||||
"failedToAdd": "添加音频失败, {{error}}",
|
||||
"fileNotFound": "无法访问文件 {{file}}",
|
||||
"fileNotSupported": "文件不支持 {{file}}",
|
||||
@@ -45,6 +46,7 @@
|
||||
"added": "成功添加视频",
|
||||
"removed": "成功删除视频",
|
||||
"notFound": "未找到视频",
|
||||
"fileTooLarge": "文件太大了 {{ file }}",
|
||||
"failedToAdd": "添加视频失败, {{error}}",
|
||||
"fileNotFound": "无法访问文件 {{file}}",
|
||||
"fileNotSupported": "文件不支持 {{file}}",
|
||||
|
||||
@@ -29,6 +29,8 @@ import webApi from "@main/web-api";
|
||||
import { startCase } from "lodash";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
const SIZE_LIMIT = 1024 * 1024 * 50; // 50MB
|
||||
|
||||
const logger = log.scope("db/models/audio");
|
||||
@Table({
|
||||
modelName: "Audio",
|
||||
@@ -240,6 +242,11 @@ export class Audio extends Model<Audio> {
|
||||
throw new Error(t("models.audio.fileNotSupported", { file: filePath }));
|
||||
}
|
||||
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.size > SIZE_LIMIT) {
|
||||
throw new Error(t("models.audio.fileTooLarge", { file: filePath }));
|
||||
}
|
||||
|
||||
const md5 = await hashFile(filePath, { algo: "md5" });
|
||||
|
||||
// Generate ID
|
||||
|
||||
@@ -29,6 +29,8 @@ import webApi from "@main/web-api";
|
||||
import { startCase } from "lodash";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
const SIZE_LIMIT = 1024 * 1024 * 100; // 100MB
|
||||
|
||||
const logger = log.scope("db/models/video");
|
||||
@Table({
|
||||
modelName: "Video",
|
||||
@@ -262,6 +264,11 @@ export class Video extends Model<Video> {
|
||||
throw new Error(t("models.video.fileNotSupported", { file: filePath }));
|
||||
}
|
||||
|
||||
const stats = fs.statSync(filePath);
|
||||
if (stats.size > SIZE_LIMIT) {
|
||||
throw new Error(t("models.video.fileTooLarge", { file: filePath }));
|
||||
}
|
||||
|
||||
const md5 = await hashFile(filePath, { algo: "md5" });
|
||||
|
||||
// Generate ID
|
||||
|
||||
Reference in New Issue
Block a user