feat: user app get
This commit is contained in:
parent
41783728c8
commit
90729df51a
@ -40,15 +40,26 @@ app
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const id = ctx.query.id;
|
||||
if (!id) {
|
||||
const { key, version } = ctx.query?.data || {};
|
||||
if (!id && (!key || !version)) {
|
||||
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) {
|
||||
throw new CustomError('app not found');
|
||||
}
|
||||
ctx.body = prefixFix(am, tokenUser.username);
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
|
@ -79,6 +79,19 @@ export class AppModel extends Model {
|
||||
});
|
||||
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(
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user