mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 20:06:08 +08:00
增加 -max 指定环境变量
This commit is contained in:
parent
fdf672092a
commit
8ae13fe823
|
@ -30,12 +30,15 @@ export default class NotificationService {
|
||||||
['webhook', this.webhook],
|
['webhook', this.webhook],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
private timeout = 30000;
|
|
||||||
private title = '';
|
private title = '';
|
||||||
private content = '';
|
private content = '';
|
||||||
private params!: Omit<NotificationInfo, 'type'>;
|
private params!: Omit<NotificationInfo, 'type'>;
|
||||||
|
private gotOption = {
|
||||||
|
timeout: 30000,
|
||||||
|
retry: 1,
|
||||||
|
}
|
||||||
|
|
||||||
constructor(@Inject('logger') private logger: winston.Logger) {}
|
constructor(@Inject('logger') private logger: winston.Logger) { }
|
||||||
|
|
||||||
public async notify(
|
public async notify(
|
||||||
title: string,
|
title: string,
|
||||||
|
@ -76,8 +79,7 @@ export default class NotificationService {
|
||||||
const { gotifyUrl, gotifyToken, gotifyPriority } = this.params;
|
const { gotifyUrl, gotifyToken, gotifyPriority } = this.params;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(`${gotifyUrl}/message?token=${gotifyToken}`, {
|
.post(`${gotifyUrl}/message?token=${gotifyToken}`, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `title=${encodeURIComponent(
|
body: `title=${encodeURIComponent(
|
||||||
this.title,
|
this.title,
|
||||||
)}&message=${encodeURIComponent(
|
)}&message=${encodeURIComponent(
|
||||||
|
@ -95,8 +97,7 @@ export default class NotificationService {
|
||||||
const { goCqHttpBotQq, goCqHttpBotToken, goCqHttpBotUrl } = this.params;
|
const { goCqHttpBotQq, goCqHttpBotToken, goCqHttpBotUrl } = this.params;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(`${goCqHttpBotUrl}?${goCqHttpBotQq}`, {
|
.post(`${goCqHttpBotUrl}?${goCqHttpBotQq}`, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: { message: `${this.title}\n${this.content}` },
|
json: { message: `${this.title}\n${this.content}` },
|
||||||
headers: { Authorization: 'Bearer ' + goCqHttpBotToken },
|
headers: { Authorization: 'Bearer ' + goCqHttpBotToken },
|
||||||
})
|
})
|
||||||
|
@ -111,8 +112,7 @@ export default class NotificationService {
|
||||||
: `https://sc.ftqq.com/${serverChanKey}.send`;
|
: `https://sc.ftqq.com/${serverChanKey}.send`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `title=${this.title}&desp=${this.content}`,
|
body: `title=${this.title}&desp=${this.content}`,
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
})
|
})
|
||||||
|
@ -125,8 +125,7 @@ export default class NotificationService {
|
||||||
const url = `https://api2.pushdeer.com/message/push`;
|
const url = `https://api2.pushdeer.com/message/push`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `pushkey=${pushDeerKey}&text=${encodeURIComponent(
|
body: `pushkey=${pushDeerKey}&text=${encodeURIComponent(
|
||||||
this.title,
|
this.title,
|
||||||
)}&desp=${encodeURIComponent(this.content)}&type=markdown`,
|
)}&desp=${encodeURIComponent(this.content)}&type=markdown`,
|
||||||
|
@ -143,8 +142,7 @@ export default class NotificationService {
|
||||||
const url = `${chatUrl}${chatToken}`;
|
const url = `${chatUrl}${chatToken}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `payload={"text":"${this.title}\n${this.content}"}`,
|
body: `payload={"text":"${this.title}\n${this.content}"}`,
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
})
|
})
|
||||||
|
@ -164,8 +162,7 @@ export default class NotificationService {
|
||||||
)}?icon=${barkIcon}?sound=${barkSound}&group=${barkGroup}`;
|
)}?icon=${barkIcon}?sound=${barkSound}&group=${barkGroup}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.get(url, {
|
.get(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
})
|
})
|
||||||
.json();
|
.json();
|
||||||
|
@ -182,9 +179,8 @@ export default class NotificationService {
|
||||||
telegramBotUserId,
|
telegramBotUserId,
|
||||||
} = this.params;
|
} = this.params;
|
||||||
const authStr = telegramBotProxyAuth ? `${telegramBotProxyAuth}@` : '';
|
const authStr = telegramBotProxyAuth ? `${telegramBotProxyAuth}@` : '';
|
||||||
const url = `https://${
|
const url = `https://${telegramBotApiHost ? telegramBotApiHost : 'api.telegram.org'
|
||||||
telegramBotApiHost ? telegramBotApiHost : 'api.telegram.org'
|
}/bot${telegramBotToken}/sendMessage`;
|
||||||
}/bot${telegramBotToken}/sendMessage`;
|
|
||||||
let agent;
|
let agent;
|
||||||
if (telegramBotProxyHost && telegramBotProxyPort) {
|
if (telegramBotProxyHost && telegramBotProxyPort) {
|
||||||
const options: any = {
|
const options: any = {
|
||||||
|
@ -203,8 +199,7 @@ export default class NotificationService {
|
||||||
}
|
}
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `chat_id=${telegramBotUserId}&text=${this.title}\n\n${this.content}&disable_web_page_preview=true`,
|
body: `chat_id=${telegramBotUserId}&text=${this.title}\n\n${this.content}&disable_web_page_preview=true`,
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
agent,
|
agent,
|
||||||
|
@ -226,8 +221,7 @@ export default class NotificationService {
|
||||||
const url = `https://oapi.dingtalk.com/robot/send?access_token=${dingtalkBotToken}${secretParam}`;
|
const url = `https://oapi.dingtalk.com/robot/send?access_token=${dingtalkBotToken}${secretParam}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
msgtype: 'text',
|
msgtype: 'text',
|
||||||
text: {
|
text: {
|
||||||
|
@ -244,8 +238,7 @@ export default class NotificationService {
|
||||||
const url = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${weWorkBotKey}`;
|
const url = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${weWorkBotKey}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
msgtype: 'text',
|
msgtype: 'text',
|
||||||
text: {
|
text: {
|
||||||
|
@ -264,8 +257,7 @@ export default class NotificationService {
|
||||||
const url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken`;
|
const url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken`;
|
||||||
const tokenRes: any = await got
|
const tokenRes: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
corpid,
|
corpid,
|
||||||
corpsecret,
|
corpsecret,
|
||||||
|
@ -315,8 +307,7 @@ export default class NotificationService {
|
||||||
.post(
|
.post(
|
||||||
`https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${tokenRes.access_token}`,
|
`https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${tokenRes.access_token}`,
|
||||||
{
|
{
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
touser,
|
touser,
|
||||||
agentid,
|
agentid,
|
||||||
|
@ -335,8 +326,7 @@ export default class NotificationService {
|
||||||
const url = `https://push.hellyw.com/${iGotPushKey.toLowerCase()}`;
|
const url = `https://push.hellyw.com/${iGotPushKey.toLowerCase()}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `title=${this.title}&content=${this.content}`,
|
body: `title=${this.title}&content=${this.content}`,
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
})
|
})
|
||||||
|
@ -350,8 +340,7 @@ export default class NotificationService {
|
||||||
const url = `https://www.pushplus.plus/send`;
|
const url = `https://www.pushplus.plus/send`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
token: `${pushPlusToken}`,
|
token: `${pushPlusToken}`,
|
||||||
title: `${this.title}`,
|
title: `${this.title}`,
|
||||||
|
@ -387,18 +376,10 @@ export default class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async webhook() {
|
private async webhook() {
|
||||||
const {
|
const { webhookUrl, webhookBody, webhookHeaders, webhookMethod, webhookContentType } =
|
||||||
webhookUrl,
|
this.params;
|
||||||
webhookBody,
|
|
||||||
webhookHeaders,
|
|
||||||
webhookMethod,
|
|
||||||
webhookContentType,
|
|
||||||
} = this.params;
|
|
||||||
|
|
||||||
const { formatBody, formatUrl } = this.formatNotifyContent(
|
const { formatBody, formatUrl } = this.formatNotifyContent(webhookUrl, webhookBody);
|
||||||
webhookUrl,
|
|
||||||
webhookBody,
|
|
||||||
);
|
|
||||||
if (!formatUrl && !formatBody) {
|
if (!formatUrl && !formatBody) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -408,11 +389,10 @@ export default class NotificationService {
|
||||||
const options = {
|
const options = {
|
||||||
method: webhookMethod,
|
method: webhookMethod,
|
||||||
headers,
|
headers,
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
allowGetBody: true,
|
allowGetBody: true,
|
||||||
...bodyParam,
|
...bodyParam
|
||||||
};
|
}
|
||||||
const res = await got(formatUrl, options);
|
const res = await got(formatUrl, options);
|
||||||
return String(res.statusCode).startsWith('20');
|
return String(res.statusCode).startsWith('20');
|
||||||
}
|
}
|
||||||
|
@ -436,12 +416,8 @@ export default class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
formatUrl: url
|
formatUrl: url.replaceAll('$title', encodeURIComponent(this.title)).replaceAll('$content', encodeURIComponent(this.content)),
|
||||||
.replaceAll('$title', encodeURIComponent(this.title))
|
formatBody: body.replaceAll('$title', this.title).replaceAll('$content', this.content),
|
||||||
.replaceAll('$content', encodeURIComponent(this.content)),
|
}
|
||||||
formatBody: body
|
|
||||||
.replaceAll('$title', this.title)
|
|
||||||
.replaceAll('$content', this.content),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,6 @@ export default class SystemService {
|
||||||
try {
|
try {
|
||||||
const result = await got.get(config.lastVersionFile, {
|
const result = await got.get(config.lastVersionFile, {
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
retry: 0,
|
|
||||||
});
|
});
|
||||||
const lastVersionFileContent = result.body;
|
const lastVersionFileContent = result.body;
|
||||||
lastVersion = lastVersionFileContent.match(versionRegx)![1];
|
lastVersion = lastVersionFileContent.match(versionRegx)![1];
|
||||||
|
|
|
@ -142,7 +142,7 @@ run_concurrent() {
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
local envs=$(eval echo "\$${env_param}")
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
||||||
local runArr=($(eval echo $tempArr))
|
local runArr=($(eval echo $tempArr))
|
||||||
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ run_designated() {
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
local envs=$(eval echo "\$${env_param}")
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
||||||
local runArr=($(eval echo $tempArr))
|
local runArr=($(eval echo $tempArr))
|
||||||
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user