fix: fix login bugs
This commit is contained in:
@@ -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(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user