34 lines
967 B
TypeScript
34 lines
967 B
TypeScript
import { oss } from '@/modules/s3.ts';
|
|
import { UserId } from '@/routes/user/modules/user-id.ts';
|
|
import { mvUserAToUserB } from '@/routes/file/index.ts';
|
|
|
|
// 迁移资源,原本的是 ${username}/appKey 改为 ${userId}/appKey
|
|
|
|
/**
|
|
* 迁移对象存储
|
|
*/
|
|
const migrateOss = async () => {
|
|
const list = await oss.listObjects('')
|
|
const _names = list.filter(item => item.size === 0)
|
|
type Name = {
|
|
prefix: string;
|
|
size: 0;
|
|
id?: string;
|
|
}
|
|
const names: Name[] = _names as any;
|
|
for (const name of names) {
|
|
const username = name.prefix.split('/')[0];
|
|
const id = await UserId.getUserIdByName(username);
|
|
if (id) {
|
|
name.id = id;
|
|
console.log(`migrating ${name.prefix} to data/${id}`);
|
|
await mvUserAToUserB(username, `data/${id}`, true);
|
|
console.log(`migrated ${name.prefix} to data/${id}`);
|
|
}
|
|
}
|
|
}
|
|
// await firstMigration();
|
|
// await secondMigration();
|
|
await migrateOss();
|
|
|
|
console.log('Migration completed'); |