fix: toAbsolutePath err for linux

This commit is contained in:
YuMao 2025-01-19 14:23:34 +08:00
parent c66c880eb3
commit 47c86b2bc5
2 changed files with 5 additions and 5 deletions

View File

@ -121,7 +121,7 @@ router.post("/upload/:key", async (ctx) => {
if (unzip) {
const instanceFiles = new FileManager(instance.absoluteCwdPath());
instanceFiles.unzip(fileSaveAbsolutePath, path.dirname(fileSaveAbsolutePath), zipCode);
instanceFiles.unzip(fileSaveAbsolutePath, ".", zipCode);
}
ctx.body = "OK";
return;

View File

@ -39,6 +39,9 @@ export default class FileManager {
toAbsolutePath(fileName: string = "") {
const topAbsolutePath = this.topPath;
if (path.normalize(fileName).indexOf(topAbsolutePath) === 0) return fileName;
let finalPath = "";
if (os.platform() === "win32") {
const reg = new RegExp("^[A-Za-z]{1}:[\\\\/]{1}");
@ -47,11 +50,8 @@ export default class FileManager {
} else if (reg.test(fileName)) {
finalPath = path.normalize(fileName);
}
} else {
if (path.isAbsolute(fileName)) {
finalPath = path.normalize(fileName);
}
}
if (!finalPath) {
finalPath = path.normalize(path.join(this.topPath, this.cwd, fileName));
}