28 lines
747 B
TypeScript
28 lines
747 B
TypeScript
import { BUCKET, client } from '$lib/minio';
|
|
|
|
export const checkIfExactDirectoryExists = (dir: string): Promise<boolean> => {
|
|
return new Promise<boolean>((resolve, reject) => {
|
|
const prefix = dir.endsWith('/') ? dir : `${dir}/`;
|
|
|
|
const stream = client.listObjectsV2(BUCKET, prefix, false, '');
|
|
|
|
stream.on('data', (obj) => {
|
|
if (obj.prefix === undefined && obj.name.startsWith(prefix)) {
|
|
stream.destroy();
|
|
resolve(true);
|
|
}
|
|
});
|
|
|
|
stream.on('error', (err) => reject(err));
|
|
|
|
stream.on('end', () => resolve(false));
|
|
});
|
|
};
|
|
|
|
export const getContentOfTextObject = async (bucket: string, objPath: string) => {
|
|
const res = await client.getObject(bucket, objPath);
|
|
|
|
const text = await new Response(res).text();
|
|
return text;
|
|
};
|