chore: oss 库 完善

This commit is contained in:
xiaojunnuo
2025-04-27 01:31:46 +08:00
parent 5abce916a8
commit 2943e0e58d
13 changed files with 232 additions and 82 deletions

View File

@@ -9,6 +9,7 @@ export type OssClientRemoveByOpts = {
};
export type OssFileItem = {
//文件全路径
path: string;
size: number;
//毫秒时间戳
@@ -71,17 +72,18 @@ export abstract class BaseOssClient<A> implements IOssClient {
// do nothing
}
abstract remove(fileName: string): Promise<void>;
abstract remove(fileName: string, opts?: { joinRootDir?: boolean }): Promise<void>;
abstract upload(fileName: string, fileContent: Buffer): Promise<void>;
abstract download(fileName: string, savePath: string): Promise<void>;
abstract listDir(dir: string): Promise<OssFileItem[]>;
async removeBy(removeByOpts: OssClientRemoveByOpts): Promise<void> {
const list = await this.listDir(removeByOpts.dir);
// removeByOpts.beforeDays = 0;
const beforeDate = dayjs().subtract(removeByOpts.beforeDays, "day");
for (const item of list) {
if (item.lastModified && item.lastModified < beforeDate.valueOf()) {
await this.remove(item.path);
await this.remove(item.path, { joinRootDir: false });
}
}
}