Fix: upload timeout

This commit is contained in:
Lazy 2023-11-30 11:16:11 +08:00
parent 5f78781ecf
commit 3249d95629
5 changed files with 8 additions and 3 deletions

View File

@ -342,6 +342,7 @@ export const useFileManager = (instanceId?: string, daemonId?: string) => {
await uploadFile({
data: uploadFormData,
timeout: Number.MAX_VALUE,
url: `${parseForwardAddress(uploadCfg.value.addr, "http")}/upload/${
uploadCfg.value.password
}`,

View File

@ -28,7 +28,7 @@ const beforeUpload: UploadProps["beforeUpload"] = async (file) => {
uploadFormData.append("file", file);
await execute({
data: uploadFormData,
timeout: 60 * 60 * 1000,
timeout: Number.MAX_VALUE,
onUploadProgress: (progressEvent: any) => {
percentComplete.value = Math.round((progressEvent.loaded * 100) / progressEvent.total);
}

View File

@ -152,6 +152,7 @@ const selectedFile = async () => {
unzip: isImportMode ? UNZIP.ON : UNZIP.OFF,
code: zipCode.value
},
timeout: Number.MAX_VALUE,
data: uploadFormData,
url: `${parseForwardAddress(cfg.value.addr, "http")}/upload/${cfg.value.password}`,
onUploadProgress: (progressEvent: any) => {

View File

@ -15,6 +15,7 @@ import {
setFrontendLayoutConfig
} from "../../service/frontend_layout";
import { ROLE } from "../../entity/user";
import { SAVE_DIR_PATH } from "../../service/frontend_layout";
const router = new Router({ prefix: "/overview" });
@ -102,7 +103,7 @@ router.post("/upload_assets", permission({ level: ROLE.ADMIN }), async (ctx) =>
if (!tmpFiles.path || !fs.existsSync(tmpFiles.path)) throw new Error("The file does not exist");
const tmpFile = tmpFiles;
const newFileName = v4() + path.extname(tmpFile.name);
const saveDirPath = path.join(process.cwd(), "public/upload_files/");
const saveDirPath = path.join(process.cwd(), SAVE_DIR_PATH);
if (!fs.existsSync(saveDirPath)) fs.mkdirsSync(saveDirPath);
await fs.move(tmpFile.path, path.join(saveDirPath, newFileName));
ctx.body = newFileName;

View File

@ -8,6 +8,8 @@ import fs from "fs-extra";
const LAYOUT_CONFIG_NAME = "layout.json";
export const SAVE_DIR_PATH = "public/upload_files/";
function getRandomId() {
return v4();
}
@ -42,7 +44,7 @@ export function setFrontendLayoutConfig(config: IPageLayoutConfig[]) {
export function resetFrontendLayoutConfig() {
storage.deleteFile(LAYOUT_CONFIG_NAME);
const filesDir = path.join(process.cwd(), "public/upload_files/");
const filesDir = path.join(process.cwd(), SAVE_DIR_PATH);
for (const fileName of fs.readdirSync(filesDir)) {
fs.remove(path.join(filesDir, fileName), () => {});
}