fix: fix login bugs

This commit is contained in:
2025-05-23 00:08:27 +08:00
parent b934687314
commit 262ef1d118
6 changed files with 56 additions and 15 deletions

View File

@@ -43,6 +43,42 @@ export class AppModel extends Model {
declare proxy: boolean;
declare user: string;
declare status: string;
static async moveToNewUser(oldUserName: string, newUserName: string) {
const appIds = await AppModel.findAll({
where: {
user: oldUserName,
},
attributes: ['id'],
});
for (const app of appIds) {
const appData = await AppModel.findByPk(app.id);
appData.user = newUserName;
const data = appData.data;
data.files = await AppModel.getNewFiles(data.files, {
oldUser: oldUserName,
newUser: newUserName,
});
appData.data = { ...data };
await appData.save({ fields: ['data', 'user'] });
}
}
static async getNewFiles(files: { name: string; path: string }[] = [], opts: { oldUser: string; newUser: string } = { oldUser: '', newUser: '' }) {
const { oldUser, newUser } = opts;
const _ = files.map((item) => {
if (item.path.startsWith('http')) {
return item;
}
if (oldUser && item.path.startsWith(oldUser)) {
return item;
}
const paths = item.path.split('/');
return {
...item,
path: newUser + '/' + paths.slice(1).join('/'),
};
});
return _;
}
}
AppModel.init(
{