Merge branch 'feat/overhaul-storage' into feat/storage-endpoint
This commit is contained in:
commit
e0c60eb241
26 changed files with 1276 additions and 1055 deletions
|
|
@ -78,17 +78,23 @@ export class CabinetController extends Controller {
|
|||
name: string;
|
||||
},
|
||||
) {
|
||||
const meta = {
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
};
|
||||
|
||||
const created = await minioClient
|
||||
.putObject(DEFAULT_BUCKET!, `${replaceIllegalChars(body.name)}/.keep`, "", 0, {
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
})
|
||||
.putObject(DEFAULT_BUCKET!, `${replaceIllegalChars(body.name)}/.keep`, "", 0, meta)
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
if (!created) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("CreateFolder", { pathname: `${replaceIllegalChars(body.name)}/` });
|
||||
io?.emit("CreateFolder", {
|
||||
pathname: `${replaceIllegalChars(body.name)}/`,
|
||||
name: replaceIllegalChars(body.name),
|
||||
...meta,
|
||||
});
|
||||
|
||||
return this.setStatus(HttpStatusCode.CREATED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,17 +93,23 @@ export class DrawerController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบตำแหน่งที่ต้องการสร้างลิ้นชัก");
|
||||
}
|
||||
|
||||
const meta = {
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
};
|
||||
|
||||
const created = await minioClient
|
||||
.putObject(DEFAULT_BUCKET!, `${basePath}${replaceIllegalChars(body.name)}/.keep`, "", 0, {
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
})
|
||||
.putObject(DEFAULT_BUCKET!, `${basePath}${replaceIllegalChars(body.name)}/.keep`, "", 0, meta)
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
if (!created) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("CreateFolder", { pathname: `${basePath}${replaceIllegalChars(body.name)}/` });
|
||||
io?.emit("CreateFolder", {
|
||||
pathname: `${basePath}${replaceIllegalChars(body.name)}/`,
|
||||
name: replaceIllegalChars(body.name),
|
||||
...meta,
|
||||
});
|
||||
|
||||
return this.setStatus(HttpStatusCode.CREATED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import { StorageFile } from "../interfaces/storage-fs";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
|
||||
import { copyCond, pathExist, replaceIllegalChars } from "../utils/minio";
|
||||
import { getInstance } from "../lib/websocket";
|
||||
|
||||
const DEFAULT_BUCKET = process.env.MINIO_BUCKET;
|
||||
const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX;
|
||||
|
|
@ -200,6 +201,9 @@ export class FileController extends Controller {
|
|||
refresh: "wait_for",
|
||||
});
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("FileUploadRequest", metadata);
|
||||
|
||||
return {
|
||||
...body,
|
||||
createdAt: metadata.createdAt,
|
||||
|
|
@ -288,6 +292,10 @@ export class FileController extends Controller {
|
|||
|
||||
if (search && search.hits.hits.length > 0 && search.hits.hits[0]._source) {
|
||||
const { _index: index, _id: id } = search.hits.hits[0];
|
||||
const meta = {
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
};
|
||||
await esClient
|
||||
.update({
|
||||
index,
|
||||
|
|
@ -297,12 +305,24 @@ export class FileController extends Controller {
|
|||
pathname: destination,
|
||||
path: basePath,
|
||||
fileName: replaceIllegalChars(file),
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
...meta,
|
||||
},
|
||||
refresh: "wait_for",
|
||||
})
|
||||
.then(() => minioClient.removeObject(DEFAULT_BUCKET!, pathname));
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("FileUpdateMove", {
|
||||
from: search.hits.hits[0]._source,
|
||||
to: {
|
||||
...search.hits.hits[0]._source,
|
||||
...metadata,
|
||||
pathname: destination,
|
||||
path: basePath,
|
||||
fileName: replaceIllegalChars(file),
|
||||
...meta,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await minioClient.removeObject(DEFAULT_BUCKET!, pathname);
|
||||
}
|
||||
|
|
@ -317,16 +337,25 @@ export class FileController extends Controller {
|
|||
|
||||
if (search && search.hits.hits.length > 0 && search.hits.hits[0]._source) {
|
||||
const { _index: index, _id: id } = search.hits.hits[0];
|
||||
const meta = {
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
};
|
||||
await esClient.update({
|
||||
index,
|
||||
id,
|
||||
doc: {
|
||||
...metadata,
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
},
|
||||
doc: { ...metadata, ...meta },
|
||||
refresh: "wait_for",
|
||||
});
|
||||
|
||||
const updated: StorageFile = {
|
||||
...search.hits.hits[0]._source,
|
||||
...metadata,
|
||||
...meta,
|
||||
};
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("FileUpdate", updated);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -98,17 +98,23 @@ export class FolderController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบตำแหน่งที่ต้องการสร้างลิ้นชัก");
|
||||
}
|
||||
|
||||
const meta = {
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
};
|
||||
|
||||
const created = await minioClient
|
||||
.putObject(DEFAULT_BUCKET!, `${basePath}${replaceIllegalChars(body.name)}/.keep`, "", 0, {
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
})
|
||||
.putObject(DEFAULT_BUCKET!, `${basePath}${replaceIllegalChars(body.name)}/.keep`, "", 0, meta)
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
if (!created) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("CreateFolder", { pathname: `${basePath}${replaceIllegalChars(body.name)}/` });
|
||||
io?.emit("CreateFolder", {
|
||||
pathname: `${basePath}${replaceIllegalChars(body.name)}/`,
|
||||
name: replaceIllegalChars(body.name),
|
||||
...meta,
|
||||
});
|
||||
|
||||
return this.setStatus(HttpStatusCode.CREATED);
|
||||
}
|
||||
|
|
@ -185,7 +191,7 @@ export class FolderController extends Controller {
|
|||
|
||||
const io = getInstance();
|
||||
io?.emit("EditFolder", {
|
||||
from: `${cabinetName}/${drawerName}/${folderName}`,
|
||||
from: `${cabinetName}/${drawerName}/${folderName}/`,
|
||||
to: `${cabinetName}/${drawerName}/${replaceIllegalChars(body.name)}/`,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -96,18 +96,23 @@ export class SubFolderController extends Controller {
|
|||
if (!(await pathExist(DEFAULT_BUCKET!, basePath))) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบตำแหน่งที่ต้องการสร้างลิ้นชัก");
|
||||
}
|
||||
const meta = {
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
};
|
||||
|
||||
const created = await minioClient
|
||||
.putObject(DEFAULT_BUCKET!, `${basePath}${replaceIllegalChars(body.name)}/.keep`, "", 0, {
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
})
|
||||
.putObject(DEFAULT_BUCKET!, `${basePath}${replaceIllegalChars(body.name)}/.keep`, "", 0, meta)
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
if (!created) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("CreateFolder", { pathname: `${basePath}${replaceIllegalChars(body.name)}/` });
|
||||
io?.emit("CreateFolder", {
|
||||
pathname: `${basePath}${replaceIllegalChars(body.name)}/`,
|
||||
name: replaceIllegalChars(body.name),
|
||||
...meta,
|
||||
});
|
||||
|
||||
return this.setStatus(HttpStatusCode.CREATED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import { StorageFile } from "../interfaces/storage-fs";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
|
||||
import { copyCond, pathExist, replaceIllegalChars } from "../utils/minio";
|
||||
import { getInstance } from "../lib/websocket";
|
||||
|
||||
const DEFAULT_BUCKET = process.env.MINIO_BUCKET;
|
||||
const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX;
|
||||
|
|
@ -206,6 +207,9 @@ export class SubFolderFileController extends Controller {
|
|||
refresh: "wait_for",
|
||||
});
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("FileUploadRequest", metadata);
|
||||
|
||||
return {
|
||||
...body,
|
||||
createdAt: metadata.createdAt,
|
||||
|
|
@ -292,7 +296,10 @@ export class SubFolderFileController extends Controller {
|
|||
query: { match: { pathname } },
|
||||
})
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
const meta = {
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
};
|
||||
if (search && search.hits.hits.length > 0 && search.hits.hits[0]._source) {
|
||||
const { _index: index, _id: id } = search.hits.hits[0];
|
||||
await esClient
|
||||
|
|
@ -304,12 +311,24 @@ export class SubFolderFileController extends Controller {
|
|||
pathname: destination,
|
||||
path: basePath,
|
||||
fileName: replaceIllegalChars(file),
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
...meta,
|
||||
},
|
||||
refresh: "wait_for",
|
||||
})
|
||||
.then(() => minioClient.removeObject(DEFAULT_BUCKET!, pathname));
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("FileUpdateMove", {
|
||||
from: search.hits.hits[0]._source,
|
||||
to: {
|
||||
...search.hits.hits[0]._source,
|
||||
...metadata,
|
||||
pathname: destination,
|
||||
path: basePath,
|
||||
fileName: replaceIllegalChars(file),
|
||||
...meta,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await minioClient.removeObject(DEFAULT_BUCKET!, pathname);
|
||||
}
|
||||
|
|
@ -324,6 +343,10 @@ export class SubFolderFileController extends Controller {
|
|||
|
||||
if (search && search.hits.hits.length > 0 && search.hits.hits[0]._source) {
|
||||
const { _index: index, _id: id } = search.hits.hits[0];
|
||||
const meta = {
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
};
|
||||
await esClient.update({
|
||||
index,
|
||||
id,
|
||||
|
|
@ -334,6 +357,14 @@ export class SubFolderFileController extends Controller {
|
|||
},
|
||||
refresh: "wait_for",
|
||||
});
|
||||
const updated: StorageFile = {
|
||||
...search.hits.hits[0]._source,
|
||||
...metadata,
|
||||
...meta,
|
||||
};
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("FileUpdate", updated);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ async function handleNotFoundRecord(
|
|||
if (!result) return false;
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("FileUpdate", metadata);
|
||||
io?.emit("FileUpload", metadata);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ async function handleFoundRecord(
|
|||
if (!result) return false;
|
||||
|
||||
const io = getInstance();
|
||||
io?.emit("FileUpdate", metadata);
|
||||
io?.emit("FileUpload", metadata);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue