feat: 上传文件到minio

This commit is contained in:
2024-10-07 01:54:13 +08:00
parent 477ad00d86
commit 8beb65e637
11 changed files with 195 additions and 104 deletions

View File

@@ -5,17 +5,17 @@ type MinioListOpt = {
prefix: string;
recursive?: boolean;
};
type MinioFile = {
export type MinioFile = {
name: string;
size: number;
lastModified: Date;
etag: string;
};
type MinioDirectory = {
export type MinioDirectory = {
prefix: string;
size: number;
};
type MinioList = (MinioFile | MinioDirectory)[];
export type MinioList = (MinioFile | MinioDirectory)[];
export const getMinioList = async (opts: MinioListOpt): Promise<MinioList> => {
const prefix = opts.prefix;
const recursive = opts.recursive ?? false;
@@ -41,3 +41,15 @@ export const getMinioList = async (opts: MinioListOpt): Promise<MinioList> => {
});
});
};
export const getFileStat = async (prefix: string): Promise<any> => {
try {
const obj = await minioClient.statObject(bucketName, prefix);
return obj;
} catch (e) {
if (e.code === 'NotFound') {
return null;
}
console.error('get File Stat Error not handle', e);
return null;
}
};