修复创建系统应用

This commit is contained in:
whyour 2025-01-05 22:03:41 +08:00
parent fa79de3f05
commit 3f775a0e6c
2 changed files with 12 additions and 4 deletions

View File

@ -24,7 +24,7 @@ export interface AppToken {
expiration: number; expiration: number;
} }
export type AppScope = 'envs' | 'crons' | 'configs' | 'scripts' | 'logs'; export type AppScope = 'envs' | 'crons' | 'configs' | 'scripts' | 'logs' | 'system';
export interface AppInstance extends Model<App, App>, App {} export interface AppInstance extends Model<App, App>, App {}
export const AppModel = sequelize.define<AppInstance>('App', { export const AppModel = sequelize.define<AppInstance>('App', {

View File

@ -159,9 +159,17 @@ export default class OpenService {
value: string; value: string;
expiration: number; expiration: number;
}> { }> {
const [systemApp] = await AppModel.findOrCreate({ let systemApp = (
where: { name: 'system', scopes: ['crons', 'system'] }, await AppModel.findOne({
}); where: { name: 'system' },
})
)?.get({ plain: true });
if (!systemApp) {
systemApp = await this.create({
name: 'system',
scopes: ['crons', 'system'],
} as App);
}
const { data } = await this.authToken({ const { data } = await this.authToken({
client_id: systemApp.client_id, client_id: systemApp.client_id,
client_secret: systemApp.client_secret, client_secret: systemApp.client_secret,