feat: multiple profile imagea

This commit is contained in:
Methapon Metanipat 2024-09-05 14:43:33 +07:00
parent 1581626880
commit 93840f4c8c
2 changed files with 87 additions and 31 deletions

View file

@ -6,6 +6,22 @@ if (!process.env.MINIO_BUCKET) {
const MINIO_BUCKET = process.env.MINIO_BUCKET;
export async function listFile(path: string) {
return await new Promise<string[]>((resolve, reject) => {
const item: string[] = [];
const stream = minio.listObjectsV2(MINIO_BUCKET, path);
stream.on("data", (v) => v && v.name && item.push(v.name));
stream.on("end", () => resolve(item));
stream.on("error", () => reject(new Error("MinIO error.")));
});
}
export async function deleteFile(path: string) {
await minio.removeObject(MINIO_BUCKET, path, { forceDelete: true });
}
export async function deleteFolder(path: string) {
new Promise<string[]>((resolve, reject) => {
const item: string[] = [];
@ -29,4 +45,7 @@ export const fileLocation = {
map: (branchId: string) => `branch/map-img-${branchId}`,
bank: (branchId: string, bankId: string) => `branch/bank-qr-${branchId}-${bankId}`,
},
user: {
profile: (userId: string, name?: string) => `user/profile-image-${userId}/${name || ""}`,
},
};