checkpoint don't deploy
This commit is contained in:
parent
a20cdef11e
commit
11015df0a8
2 changed files with 36 additions and 18 deletions
|
|
@ -186,28 +186,45 @@ export class FileController extends Controller {
|
||||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ เข้าถึงรายการไฟล์ได้");
|
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ เข้าถึงรายการไฟล์ได้");
|
||||||
}
|
}
|
||||||
|
|
||||||
let used: string[] = [];
|
|
||||||
|
|
||||||
let fileList = !body.replace
|
let fileList = !body.replace
|
||||||
? body.fileList.map(({ fileName, ...props }) => {
|
? await Promise.all(
|
||||||
const dotIndex = fileName.lastIndexOf(".");
|
body.fileList.map(async ({ fileName, ...props }) => {
|
||||||
const originalName =
|
const dotIndex = fileName.lastIndexOf(".");
|
||||||
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(0, dotIndex) : fileName;
|
const originalName =
|
||||||
const extension =
|
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(0, dotIndex) : fileName;
|
||||||
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : "";
|
const extension =
|
||||||
|
dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : "";
|
||||||
|
|
||||||
let i = 1;
|
let copyFileName = fileName;
|
||||||
while (list.findIndex((v) => v.fileName === fileName) !== -1 || used.includes(fileName)) {
|
|
||||||
fileName = `${originalName} (${i++})`;
|
|
||||||
if (dotIndex !== -1) fileName += extension;
|
|
||||||
}
|
|
||||||
|
|
||||||
props.author = "ไม่พบข้อมูล";
|
while (list.findIndex((v) => v.fileName === fileName) !== -1) {
|
||||||
|
let copy = 0;
|
||||||
|
|
||||||
used.push(fileName);
|
while (
|
||||||
|
list.findIndex(
|
||||||
|
(v) =>
|
||||||
|
v.fileName ===
|
||||||
|
`${originalName} (${copy + 1})` + (dotIndex !== -1 ? extension : ""),
|
||||||
|
) !== -1
|
||||||
|
) {
|
||||||
|
copy++;
|
||||||
|
}
|
||||||
|
|
||||||
return { fileName: fileName, ...props };
|
copyFileName = `${originalName} (${copy})` + extension;
|
||||||
})
|
|
||||||
|
const result = await updateFile(path, fileName, Object.assign(props, { title: copyFileName}), path, copyFileName);
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถแก้ไขไฟล์ได้");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
props.author = "ไม่พบข้อมูล";
|
||||||
|
|
||||||
|
return { fileName: fileName, ...props };
|
||||||
|
}),
|
||||||
|
)
|
||||||
: body.fileList;
|
: body.fileList;
|
||||||
|
|
||||||
const map = fileList.map(async ({ fileName, ...props }) => [
|
const map = fileList.map(async ({ fileName, ...props }) => [
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ export async function listFile(path: string[]) {
|
||||||
return (await list("file", path)) as StorageFile[] | boolean;
|
return (await list("file", path)) as StorageFile[] | boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateFile(path: string[], file: string, metadata: FileProps) {
|
export async function updateFile(path: string[], file: string, metadata: FileProps, destPath?: string[], destFile?: string) {
|
||||||
const res = await fetch(`${STORAGE_URL}/storage/file`, {
|
const res = await fetch(`${STORAGE_URL}/storage/file`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -152,6 +152,7 @@ export async function updateFile(path: string[], file: string, metadata: FilePro
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
from: { path, file },
|
from: { path, file },
|
||||||
|
to: destPath && destFile ? { path: destPath, file: destFile,} : undefined,
|
||||||
...metadata,
|
...metadata,
|
||||||
upload: false,
|
upload: false,
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue