mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-27 14:46:06 +08:00
同步推送设置配置到环境变量
This commit is contained in:
parent
728a619bf8
commit
de08c873b0
|
@ -13,6 +13,8 @@ import {
|
||||||
} from '../data/env';
|
} from '../data/env';
|
||||||
import groupBy from 'lodash/groupBy';
|
import groupBy from 'lodash/groupBy';
|
||||||
import { FindOptions, Op } from 'sequelize';
|
import { FindOptions, Op } from 'sequelize';
|
||||||
|
import { NotificationInfo } from '../data/notify';
|
||||||
|
import { omit, snakeCase } from 'lodash';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class EnvService {
|
export default class EnvService {
|
||||||
|
@ -229,4 +231,19 @@ export default class EnvService {
|
||||||
await fs.writeFile(config.jsEnvFile, js_env_string);
|
await fs.writeFile(config.jsEnvFile, js_env_string);
|
||||||
await fs.writeFile(config.pyEnvFile, py_env_string);
|
await fs.writeFile(config.pyEnvFile, py_env_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async updateFromNotification(notificationInfo: NotificationInfo){
|
||||||
|
const obj = omit(notificationInfo,['type']) as any
|
||||||
|
const keys = Object.keys(obj)
|
||||||
|
for(const key of keys){
|
||||||
|
const ukey=snakeCase(key).toUpperCase()
|
||||||
|
const raw=await EnvModel.findOne({where:{name:ukey}})
|
||||||
|
if(!raw){
|
||||||
|
await EnvModel.create({name:ukey,value:obj[key],status:EnvStatus.normal})
|
||||||
|
}else{
|
||||||
|
await EnvModel.update({value:obj[key],status:EnvStatus.normal},{where:{name:ukey}})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await this.set_envs()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import dayjs from 'dayjs';
|
||||||
import IP2Region from 'ip2region';
|
import IP2Region from 'ip2region';
|
||||||
import requestIp from 'request-ip';
|
import requestIp from 'request-ip';
|
||||||
import uniq from 'lodash/uniq';
|
import uniq from 'lodash/uniq';
|
||||||
|
import EnvService from '../services/env';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class UserService {
|
export default class UserService {
|
||||||
|
@ -38,6 +39,7 @@ export default class UserService {
|
||||||
@Inject('logger') private logger: winston.Logger,
|
@Inject('logger') private logger: winston.Logger,
|
||||||
private scheduleService: ScheduleService,
|
private scheduleService: ScheduleService,
|
||||||
private sockService: SockService,
|
private sockService: SockService,
|
||||||
|
private envService: EnvService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async login(
|
public async login(
|
||||||
|
@ -385,9 +387,11 @@ export default class UserService {
|
||||||
const isSuccess = await this.notificationService.testNotify(
|
const isSuccess = await this.notificationService.testNotify(
|
||||||
notificationInfo,
|
notificationInfo,
|
||||||
'青龙',
|
'青龙',
|
||||||
`【蛟龙】测试通知 https://t.me/jiao_long`,
|
`【蛟龙】测试通知 https://t.me/jiao_long ${code}`,
|
||||||
);
|
);
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
|
await this.envService.updateFromNotification(notificationInfo)
|
||||||
|
|
||||||
const result = await this.updateAuthDb({
|
const result = await this.updateAuthDb({
|
||||||
type: AuthDataType.notification,
|
type: AuthDataType.notification,
|
||||||
info: { ...notificationInfo },
|
info: { ...notificationInfo },
|
||||||
|
|
|
@ -757,7 +757,7 @@ function iGotNotify(text, desp, params = {}) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function pushPlusNotify(text, desp) {
|
function pushPlusNotify(text, desp, params) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const { PUSH_PLUS_TOKEN, PUSH_PLUS_USER } = push_config;
|
const { PUSH_PLUS_TOKEN, PUSH_PLUS_USER } = push_config;
|
||||||
if (PUSH_PLUS_TOKEN) {
|
if (PUSH_PLUS_TOKEN) {
|
||||||
|
@ -767,6 +767,7 @@ function pushPlusNotify(text, desp) {
|
||||||
title: `${text}`,
|
title: `${text}`,
|
||||||
content: `${desp}`,
|
content: `${desp}`,
|
||||||
topic: `${PUSH_PLUS_USER}`,
|
topic: `${PUSH_PLUS_USER}`,
|
||||||
|
template: params.template || 'html',
|
||||||
};
|
};
|
||||||
const options = {
|
const options = {
|
||||||
url: `https://www.pushplus.plus/send`,
|
url: `https://www.pushplus.plus/send`,
|
||||||
|
@ -1297,7 +1298,7 @@ async function sendNotify(text, desp, params = {}) {
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
serverNotify(text, desp), // 微信server酱
|
serverNotify(text, desp), // 微信server酱
|
||||||
pushPlusNotify(text, desp), // pushplus
|
pushPlusNotify(text, desp, params), // pushplus
|
||||||
wePlusBotNotify(text, desp), // 微加机器人
|
wePlusBotNotify(text, desp), // 微加机器人
|
||||||
barkNotify(text, desp, params), // iOS Bark APP
|
barkNotify(text, desp, params), // iOS Bark APP
|
||||||
tgBotNotify(text, desp), // telegram 机器人
|
tgBotNotify(text, desp), // telegram 机器人
|
||||||
|
|
Loading…
Reference in New Issue
Block a user