mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修改自定义通知 body 解析逻辑
This commit is contained in:
+16
-14
@@ -819,11 +819,11 @@ function ChangeUserId(desp) {
|
||||
async function qywxamNotify(text, desp) {
|
||||
const MAX_LENGTH = 900;
|
||||
if (desp.length > MAX_LENGTH) {
|
||||
let d = desp.substr(0, MAX_LENGTH) + "\n==More==";
|
||||
let d = desp.substr(0, MAX_LENGTH) + '\n==More==';
|
||||
await do_qywxamNotify(text, d);
|
||||
await qywxamNotify(text, desp.substr(MAX_LENGTH));
|
||||
} else {
|
||||
return await do_qywxamNotify(text,desp);
|
||||
return await do_qywxamNotify(text, desp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1284,18 +1284,15 @@ function chronocatNotify(title, desp) {
|
||||
|
||||
function webhookNotify(text, desp) {
|
||||
return new Promise((resolve) => {
|
||||
const { formatBody, formatUrl } = formatNotifyContentFun(
|
||||
WEBHOOK_URL,
|
||||
WEBHOOK_BODY,
|
||||
text,
|
||||
desp,
|
||||
);
|
||||
if (!formatUrl && !formatBody) {
|
||||
if (!WEBHOOK_URL.includes('$title') && !WEBHOOK_BODY.includes('$title')) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
const headers = parseHeaders(WEBHOOK_HEADERS);
|
||||
const body = parseBody(formatBody, WEBHOOK_CONTENT_TYPE);
|
||||
const body = parseBody(WEBHOOK_BODY, WEBHOOK_CONTENT_TYPE, (v) =>
|
||||
v?.replaceAll('$title', text)?.replaceAll('$content', desp),
|
||||
);
|
||||
const bodyParam = formatBodyFun(WEBHOOK_CONTENT_TYPE, body);
|
||||
const options = {
|
||||
method: WEBHOOK_METHOD,
|
||||
@@ -1307,6 +1304,10 @@ function webhookNotify(text, desp) {
|
||||
};
|
||||
|
||||
if (WEBHOOK_METHOD) {
|
||||
const formatUrl = WEBHOOK_URL.replaceAll(
|
||||
'$title',
|
||||
encodeURIComponent(text),
|
||||
).replaceAll('$content', encodeURIComponent(desp));
|
||||
got(formatUrl, options).then((resp) => {
|
||||
try {
|
||||
if (resp.statusCode !== 200) {
|
||||
@@ -1326,7 +1327,7 @@ function webhookNotify(text, desp) {
|
||||
});
|
||||
}
|
||||
|
||||
function parseString(input) {
|
||||
function parseString(input, valueFormatFn) {
|
||||
const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g;
|
||||
const matches = {};
|
||||
|
||||
@@ -1338,9 +1339,10 @@ function parseString(input) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const _value = value.trim();
|
||||
let _value = value.trim();
|
||||
|
||||
try {
|
||||
_value = valueFormatFn ? valueFormatFn(_value) : _value;
|
||||
const jsonValue = JSON.parse(_value);
|
||||
matches[_key] = jsonValue;
|
||||
} catch (error) {
|
||||
@@ -1375,12 +1377,12 @@ function parseHeaders(headers) {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function parseBody(body, contentType) {
|
||||
function parseBody(body, contentType, valueFormatFn) {
|
||||
if (contentType === 'text/plain' || !body) {
|
||||
return body;
|
||||
}
|
||||
|
||||
const parsed = parseString(body);
|
||||
const parsed = parseString(body, valueFormatFn);
|
||||
|
||||
switch (contentType) {
|
||||
case 'multipart/form-data':
|
||||
|
||||
Reference in New Issue
Block a user