feat: 更新资源迁移逻辑,优化用户 ID 处理,删除冗余代码

This commit is contained in:
xiongxiao
2026-03-25 02:36:27 +08:00
committed by cnb
parent 55378f4c94
commit b39f7d6028
11 changed files with 107 additions and 181 deletions

View File

@@ -1,6 +1,7 @@
import dayjs from 'dayjs';
import { oss } from '@/modules/s3.ts';
import { StatObjectResult } from '@kevisual/oss';
import { UserId } from '@/routes/user/modules/user-id.ts';
type MinioListOpt = {
prefix: string;
recursive?: boolean;
@@ -62,23 +63,14 @@ export const deleteFile = async (prefix: string): Promise<{ code: number; messag
}
};
// 批量删除文件
export const deleteFiles = async (prefixs: string[]): Promise<any> => {
try {
for (const prefix of prefixs) {
await oss.deleteObject(prefix);
}
return true;
} catch (e) {
console.error('delete Files Error not handle', e);
return false;
}
};
export const deleteFileByPrefix = async (prefix: string): Promise<any> => {
try {
const allFiles = await getMinioList<true>({ prefix, recursive: true });
const files = allFiles.filter((item) => item.name.startsWith(prefix));
await deleteFiles(files.map((item) => item.name));
const objects = await oss.listObjects<true>(prefix, { recursive: true });
if (objects.length > 0) {
for (const obj of objects) {
await oss.deleteObject(obj.name);
}
}
return true;
} catch (e) {
console.error('delete File Error not handle', e);
@@ -93,7 +85,8 @@ type GetMinioListAndSetToAppListOpts = {
// 批量列出文件并设置到appList的files中
export const getMinioListAndSetToAppList = async (opts: GetMinioListAndSetToAppListOpts) => {
const { username, appKey, version } = opts;
const minioList = await getMinioList({ prefix: `${username}/${appKey}/${version}`, recursive: true });
const uid = await UserId.getUserIdByName(username);
const minioList = await getMinioList({ prefix: `data/${uid}/${appKey}/${version}`, recursive: true });
const files = minioList;
return files as MinioFile[];
};
@@ -178,7 +171,8 @@ export const backupUserA = async (usernameA: string, id: string, backName?: stri
* @param username
*/
export const deleteUser = async (username: string) => {
const list = await getMinioList<true>({ prefix: `${username}/`, recursive: true });
const uid = await UserId.getUserIdByName(username);
const list = await getMinioList<true>({ prefix: `data/${uid}/`, recursive: true });
for (const item of list) {
await oss.deleteObject(item.name);
}