From 3f775a0e6c62b41ab777a9f6aff7d52ce4cc8426 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 5 Jan 2025 22:03:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/open.ts | 2 +- back/services/open.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/back/data/open.ts b/back/data/open.ts index d5149648..2c0ba9aa 100644 --- a/back/data/open.ts +++ b/back/data/open.ts @@ -24,7 +24,7 @@ export interface AppToken { 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 {} export const AppModel = sequelize.define('App', { diff --git a/back/services/open.ts b/back/services/open.ts index 5658f53c..2f63ae9c 100644 --- a/back/services/open.ts +++ b/back/services/open.ts @@ -159,9 +159,17 @@ export default class OpenService { value: string; expiration: number; }> { - const [systemApp] = await AppModel.findOrCreate({ - where: { name: 'system', scopes: ['crons', 'system'] }, - }); + let systemApp = ( + 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({ client_id: systemApp.client_id, client_secret: systemApp.client_secret,