feat: user app get

This commit is contained in:
熊潇 2025-05-30 00:28:57 +08:00
parent 41783728c8
commit 90729df51a
2 changed files with 27 additions and 3 deletions

View File

@ -40,15 +40,26 @@ app
.define(async (ctx) => { .define(async (ctx) => {
const tokenUser = ctx.state.tokenUser; const tokenUser = ctx.state.tokenUser;
const id = ctx.query.id; const id = ctx.query.id;
if (!id) { const { key, version } = ctx.query?.data || {};
if (!id && (!key || !version)) {
throw new CustomError('id is required'); throw new CustomError('id is required');
} }
const am = await AppListModel.findByPk(id); let am: AppListModel;
if (id) {
am = await AppListModel.findByPk(id);
} else if (key && version) {
am = await AppListModel.findOne({
where: {
key,
version,
uid: tokenUser.id,
},
});
}
if (!am) { if (!am) {
throw new CustomError('app not found'); throw new CustomError('app not found');
} }
ctx.body = prefixFix(am, tokenUser.username); ctx.body = prefixFix(am, tokenUser.username);
return ctx;
}) })
.addTo(app); .addTo(app);

View File

@ -79,6 +79,19 @@ export class AppModel extends Model {
}); });
return _; return _;
} }
async getPublic() {
const value = this.toJSON();
// 删除不需要的字段
const data = value.data;
if (data && data.permission) {
delete data.permission.usernames;
delete data.permission.password;
delete data.permission['expiration-time'];
}
value.data = data;
return value;
}
} }
AppModel.init( AppModel.init(
{ {