ระบบประเมิน กรณีอัปโหลดเอกสารทับอันเดิม (ทดสอบ)
This commit is contained in:
parent
94f5724033
commit
7fa0e2f242
2 changed files with 66 additions and 9 deletions
|
|
@ -20,6 +20,7 @@ import {
|
|||
downloadFile,
|
||||
listFile,
|
||||
updateFile,
|
||||
updateFile2
|
||||
} from "../services/storage";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { Evaluation } from "../entities/Evaluation";
|
||||
|
|
@ -221,7 +222,7 @@ export class DocumentController extends Controller {
|
|||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
}
|
||||
|
||||
let used: string[] = [];
|
||||
// let used: string[] = [];
|
||||
|
||||
const evaluation = AppDataSource.getRepository(Evaluation);
|
||||
|
||||
|
|
@ -230,20 +231,45 @@ export class DocumentController extends Controller {
|
|||
});
|
||||
|
||||
let fileList = !body.replace
|
||||
? body.fileList.map(({ fileName, ...props }) => {
|
||||
? await Promise.all(body.fileList.map(async({ fileName, ...props }) => {
|
||||
const dotIndex = fileName.lastIndexOf(".");
|
||||
const originalName =
|
||||
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(0, dotIndex) : fileName;
|
||||
const extension =
|
||||
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : "";
|
||||
|
||||
let i = 1;
|
||||
// let i = 1;
|
||||
let copyFileName = fileName;
|
||||
while (
|
||||
list.findIndex((v) => v.fileName === fileName) !== -1 ||
|
||||
used.includes(fileName)
|
||||
list.findIndex((v) => v.fileName === fileName) !== -1 /*||
|
||||
used.includes(fileName)*/
|
||||
) {
|
||||
fileName = `${originalName} (${i++})`;
|
||||
if (dotIndex !== -1) fileName += extension;
|
||||
// fileName = `${originalName} (${i++})`;
|
||||
// if (dotIndex !== -1) fileName += extension;
|
||||
let copy = 0;
|
||||
while (
|
||||
list.findIndex(
|
||||
(v) =>
|
||||
v.fileName ===
|
||||
`${originalName} (${copy + 1})` + (dotIndex !== -1 ? extension : ""),
|
||||
) !== -1
|
||||
) {
|
||||
copy++;
|
||||
}
|
||||
copyFileName = `${originalName} (${copy + 1})` + extension;
|
||||
|
||||
const result = await updateFile2(
|
||||
["ระบบประเมิน", volume, id],
|
||||
fileName,
|
||||
{ ...props, title: copyFileName },
|
||||
["ระบบประเมิน", volume, id],
|
||||
copyFileName,
|
||||
);
|
||||
|
||||
if (!result) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถแก้ไขไฟล์ได้");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (author) {
|
||||
props.author = `${author.prefix}${author.fullName}`;
|
||||
|
|
@ -251,9 +277,9 @@ export class DocumentController extends Controller {
|
|||
props.author = "ไม่พบข้อมูล";
|
||||
}
|
||||
|
||||
used.push(fileName);
|
||||
// used.push(fileName);
|
||||
return { fileName: fileName, ...props };
|
||||
})
|
||||
}))
|
||||
: body.fileList;
|
||||
|
||||
const map = fileList.map(async ({ fileName, ...props }) => [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue