refactor: drop supported presigned url return

Now use its endpoint to upload file instead.
The server still not loaded by the api as it redirect to presigned url.
This commit is contained in:
Methapon Metanipat 2024-09-05 09:55:45 +07:00
parent 2af4e750b0
commit 8750c2cf98
2 changed files with 74 additions and 57 deletions

31
src/utils/minio.ts Normal file
View file

@ -0,0 +1,31 @@
import minio from "../services/minio";
if (!process.env.MINIO_BUCKET) {
throw Error("Require MinIO bucket.");
}
const MINIO_BUCKET = process.env.MINIO_BUCKET;
export async function deleteFolder(path: string) {
new Promise<string[]>((resolve, reject) => {
const item: string[] = [];
const stream = minio.listObjectsV2(MINIO_BUCKET, path, true);
stream.on("data", (v) => v && v.name && item.push(v.name));
stream.on("end", () => resolve(item));
stream.on("error", () => reject(new Error("MinIO error.")));
}).then((list) => {
list.map(async (v) => {
await minio.removeObject(MINIO_BUCKET, v, { forceDelete: true });
});
});
}
export const fileLocation = {
branch: {
line: (id: string) => `branch/line-qr-${id}`,
image: (id: string) => `branch/branch-img-${id}`,
map: (id: string) => `branch/map-img-${id}`,
},
};