mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修复 webhook 通知 body 拆分逻辑
This commit is contained in:
+26
-22
@@ -1315,6 +1315,31 @@ function webhookNotify(text, desp) {
|
||||
});
|
||||
}
|
||||
|
||||
function parseString(input) {
|
||||
const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g;
|
||||
const matches = {};
|
||||
|
||||
let match;
|
||||
while ((match = regex.exec(input)) !== null) {
|
||||
const [, key, value] = match;
|
||||
const _key = key.trim();
|
||||
if (!_key || matches[_key]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const _value = value.trim();
|
||||
|
||||
try {
|
||||
const jsonValue = JSON.parse(_value);
|
||||
matches[_key] = jsonValue;
|
||||
} catch (error) {
|
||||
matches[_key] = _value;
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
function parseHeaders(headers) {
|
||||
if (!headers) return {};
|
||||
|
||||
@@ -1344,28 +1369,7 @@ function parseBody(body, contentType) {
|
||||
return body;
|
||||
}
|
||||
|
||||
const parsed = {};
|
||||
let key;
|
||||
let val;
|
||||
let i;
|
||||
|
||||
body &&
|
||||
body.split('\n').forEach(function parser(line) {
|
||||
i = line.indexOf(':');
|
||||
key = line.substring(0, i).trim();
|
||||
val = line.substring(i + 1).trim();
|
||||
|
||||
if (!key || parsed[key]) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const jsonValue = JSON.parse(val);
|
||||
parsed[key] = jsonValue;
|
||||
} catch (error) {
|
||||
parsed[key] = val;
|
||||
}
|
||||
});
|
||||
const parsed = parseString(body);
|
||||
|
||||
switch (contentType) {
|
||||
case 'multipart/form-data':
|
||||
|
||||
Reference in New Issue
Block a user