fix: response does not wait process to finish
This commit is contained in:
parent
1c3ac35ed1
commit
adfb70b578
8 changed files with 253 additions and 144 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { EhrFolder } from "../interfaces/ehr-fs";
|
||||
import * as Minio from "minio";
|
||||
import minioClient from "../storage";
|
||||
|
||||
/**
|
||||
|
|
@ -59,7 +60,12 @@ export function listFolder(path?: string): Promise<EhrFolder[]> {
|
|||
|
||||
stream.on("end", async () => {
|
||||
for (let i = 0; i < folder.length; i++) {
|
||||
const stat = await minioClient.statObject("ehr", `${folder[i].pathname}.keep`);
|
||||
const stat = await minioClient
|
||||
.statObject("ehr", `${folder[i].pathname}.keep`)
|
||||
.catch((e) => console.error(`Error List Folder: ${folder[i].pathname}`, e));
|
||||
|
||||
if (!stat) continue;
|
||||
|
||||
folder[i] = {
|
||||
...folder[i],
|
||||
createdAt: stat.metaData.createdat ?? "N/A",
|
||||
|
|
@ -72,3 +78,16 @@ export function listFolder(path?: string): Promise<EhrFolder[]> {
|
|||
stream.on("error", () => reject(new Error("Object storage error occured.")));
|
||||
});
|
||||
}
|
||||
|
||||
export async function listItem(path: string, recursive = false): Promise<Minio.BucketItem[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const stream = minioClient.listObjectsV2("ehr", path, recursive);
|
||||
const item: Minio.BucketItem[] = [];
|
||||
|
||||
stream.on("data", (v) => {
|
||||
if (v && v.name) item.push(v);
|
||||
});
|
||||
stream.on("end", () => resolve(item));
|
||||
stream.on("error", () => reject(new Error("Object storage error occured.")));
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue