diff --git a/back/data/system.ts b/back/data/system.ts index cfac3956..bca6c4d6 100644 --- a/back/data/system.ts +++ b/back/data/system.ts @@ -2,13 +2,13 @@ import { sequelize } from '.'; import { DataTypes, Model, ModelDefined } from 'sequelize'; import { NotificationInfo } from './notify'; -export class AuthInfo { +export class SystemInfo { ip?: string; type: AuthDataType; info?: SystemModelInfo; id?: number; - constructor(options: AuthInfo) { + constructor(options: SystemInfo) { this.ip = options.ip; this.info = options.info; this.type = options.type; @@ -50,7 +50,7 @@ export type SystemModelInfo = SystemConfigInfo & Partial & LoginLogInfo; -export interface SystemInstance extends Model, AuthInfo { } +export interface SystemInstance extends Model, SystemInfo { } export const SystemModel = sequelize.define('Auth', { ip: DataTypes.STRING, type: DataTypes.STRING, diff --git a/back/services/cron.ts b/back/services/cron.ts index 2e607f75..0045b4f9 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -375,7 +375,10 @@ export default class CronService { public async getDb(query: FindOptions['where']): Promise { const doc: any = await CrontabModel.findOne({ where: { ...query } }); - return doc && (doc.get({ plain: true }) as Crontab); + if (!doc) { + throw new Error(`${JSON.stringify(query)} not found`); + } + return doc.get({ plain: true }); } public async run(ids: number[]) { @@ -437,7 +440,7 @@ export default class CronService { const cp = spawn( `real_log_path=${logPath} no_delay=true ${this.makeCommand( cron, - true + true, )}`, { shell: '/bin/bash' }, ); diff --git a/back/services/cronView.ts b/back/services/cronView.ts index 35bcc37e..f147b529 100644 --- a/back/services/cronView.ts +++ b/back/services/cronView.ts @@ -63,7 +63,10 @@ export default class CronViewService { query: FindOptions['where'], ): Promise { const doc: any = await CrontabViewModel.findOne({ where: { ...query } }); - return doc && (doc.get({ plain: true }) as CrontabView); + if (!doc) { + throw new Error(`${JSON.stringify(query)} not found`); + } + return doc.get({ plain: true }); } public async disabled(ids: number[]) { diff --git a/back/services/dependence.ts b/back/services/dependence.ts index 7a935330..5b3c2edd 100644 --- a/back/services/dependence.ts +++ b/back/services/dependence.ts @@ -183,7 +183,10 @@ export default class DependenceService { query: FindOptions['where'], ): Promise { const doc: any = await DependenceModel.findOne({ where: { ...query } }); - return doc && (doc.get({ plain: true }) as Dependence); + if (!doc) { + throw new Error(`${JSON.stringify(query)} not found`); + } + return doc.get({ plain: true }); } private async updateLog(ids: number[], log: string): Promise { diff --git a/back/services/env.ts b/back/services/env.ts index 7b33f331..fdfd0a90 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -165,7 +165,10 @@ export default class EnvService { public async getDb(query: FindOptions['where']): Promise { const doc: any = await EnvModel.findOne({ where: { ...query } }); - return doc && (doc.get({ plain: true }) as Env); + if (!doc) { + throw new Error(`${JSON.stringify(query)} not found`); + } + return doc.get({ plain: true }); } public async disabled(ids: string[]) { diff --git a/back/services/open.ts b/back/services/open.ts index e9f97ce5..83276f41 100644 --- a/back/services/open.ts +++ b/back/services/open.ts @@ -26,7 +26,7 @@ export default class OpenService { public async insert(payload: App): Promise { const doc = await AppModel.create(payload, { returning: true }); - return doc.get({ plain: true }) as App; + return doc.get({ plain: true }); } public async update(payload: App): Promise { @@ -45,7 +45,10 @@ export default class OpenService { public async getDb(query: any): Promise { const doc: any = await AppModel.findOne({ where: query }); - return doc && (doc.get({ plain: true }) as App); + if (!doc) { + throw new Error(`${JSON.stringify(query)} not found`); + } + return doc.get({ plain: true }); } public async remove(ids: number[]) { diff --git a/back/services/system.ts b/back/services/system.ts index afc3e571..c968f901 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -24,7 +24,7 @@ import { import { NotificationInfo } from '../data/notify'; import { AuthDataType, - AuthInfo, + SystemInfo, SystemInstance, SystemModel, SystemModelInfo, @@ -47,18 +47,21 @@ export default class SystemService { public async getSystemConfig() { const doc = await this.getDb({ type: AuthDataType.systemConfig }); - return doc || ({} as SystemInstance); + return doc; } - private async updateAuthDb(payload: AuthInfo): Promise { + private async updateAuthDb(payload: SystemInfo): Promise { await SystemModel.upsert({ ...payload }); const doc = await this.getDb({ type: payload.type }); return doc; } - public async getDb(query: any): Promise { - const doc: any = await SystemModel.findOne({ where: { ...query } }); - return doc && doc.get({ plain: true }); + public async getDb(query: any): Promise { + const doc = await SystemModel.findOne({ where: { ...query } }); + if (!doc) { + throw new Error(`${JSON.stringify(query)} not found`); + } + return doc.get({ plain: true }); } public async updateNotificationMode(notificationInfo: NotificationInfo) { diff --git a/back/services/user.ts b/back/services/user.ts index e5bfa1f3..74a95c67 100644 --- a/back/services/user.ts +++ b/back/services/user.ts @@ -13,7 +13,7 @@ import jwt from 'jsonwebtoken'; import { authenticator } from '@otplib/preset-default'; import { AuthDataType, - AuthInfo, + SystemInfo, SystemModel, SystemModelInfo, LoginStatus, @@ -223,7 +223,7 @@ export default class UserService { return []; } - private async insertDb(payload: AuthInfo): Promise { + private async insertDb(payload: SystemInfo): Promise { const doc = await SystemModel.create({ ...payload }, { returning: true }); return doc; } @@ -351,10 +351,10 @@ export default class UserService { public async getNotificationMode(): Promise { const doc = await this.getDb({ type: AuthDataType.notification }); - return (doc && doc.info) || {}; + return doc.info as NotificationInfo; } - private async updateAuthDb(payload: AuthInfo): Promise { + private async updateAuthDb(payload: SystemInfo): Promise { let doc = await SystemModel.findOne({ type: payload.type }); if (doc) { const updateResult = await SystemModel.update(payload, { @@ -368,9 +368,12 @@ export default class UserService { return doc; } - public async getDb(query: any): Promise { - const doc: any = await SystemModel.findOne({ where: { ...query } }); - return doc && (doc.get({ plain: true }) as any); + public async getDb(query: any): Promise { + const doc = await SystemModel.findOne({ where: { ...query } }); + if (!doc) { + throw new Error(`${JSON.stringify(query)} not found`); + } + return doc.get({ plain: true }); } public async updateNotificationMode(notificationInfo: NotificationInfo) { diff --git a/shell/update.sh b/shell/update.sh index e7a85ae7..45e1a9f3 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -161,7 +161,7 @@ update_raw() { if [[ $url == http:* ]]; then proxyStr="-e \"http_proxy=${proxy}\"" elif [[ $url == https:* ]]; then - proxyStr="-e \"http_proxy=${proxy};https_proxy=${proxy}\"" + proxyStr="-e \"https_proxy=${proxy}\"" fi fi @@ -255,7 +255,7 @@ reload_qinglong() { reload_pm2 } -## 更新qinglong +## 更新 qinglong update_qinglong() { rm -rf ${dir_tmp}/* local mirror="gitee"