mirror of
https://github.com/whyour/qinglong.git
synced 2025-07-07 11:56:08 +08:00
修复 webhook 通知 body 拆分逻辑
This commit is contained in:
parent
81898f9dd7
commit
11c789c71c
|
@ -360,6 +360,31 @@ export function parseHeaders(headers: string) {
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseString(input: string): Record<string, string> {
|
||||||
|
const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g;
|
||||||
|
const matches: Record<string, string> = {};
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
export function parseBody(
|
export function parseBody(
|
||||||
body: string,
|
body: string,
|
||||||
contentType:
|
contentType:
|
||||||
|
@ -372,28 +397,7 @@ export function parseBody(
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed: any = {};
|
const parsed = parseString(body);
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case 'multipart/form-data':
|
case 'multipart/form-data':
|
||||||
|
|
|
@ -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) {
|
function parseHeaders(headers) {
|
||||||
if (!headers) return {};
|
if (!headers) return {};
|
||||||
|
|
||||||
|
@ -1344,28 +1369,7 @@ function parseBody(body, contentType) {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = {};
|
const parsed = parseString(body);
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case 'multipart/form-data':
|
case 'multipart/form-data':
|
||||||
|
|
|
@ -578,7 +578,9 @@ def aibotk(title: str, content: str) -> None:
|
||||||
or not push_config.get("AIBOTK_TYPE")
|
or not push_config.get("AIBOTK_TYPE")
|
||||||
or not push_config.get("AIBOTK_NAME")
|
or not push_config.get("AIBOTK_NAME")
|
||||||
):
|
):
|
||||||
print("智能微秘书 的 AIBOTK_KEY 或者 AIBOTK_TYPE 或者 AIBOTK_NAME 未设置!!\n取消推送")
|
print(
|
||||||
|
"智能微秘书 的 AIBOTK_KEY 或者 AIBOTK_TYPE 或者 AIBOTK_NAME 未设置!!\n取消推送"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
print("智能微秘书 服务启动")
|
print("智能微秘书 服务启动")
|
||||||
|
|
||||||
|
@ -748,29 +750,25 @@ def parse_headers(headers):
|
||||||
return parsed
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
|
def parse_string(input_string):
|
||||||
|
matches = {}
|
||||||
|
pattern = r'(\w+):\s*((?:(?!\n\w+:).)*)'
|
||||||
|
regex = re.compile(pattern)
|
||||||
|
for match in regex.finditer(input_string):
|
||||||
|
key, value = match.group(1).strip(), match.group(2).strip()
|
||||||
|
try:
|
||||||
|
json_value = json.loads(value)
|
||||||
|
matches[key] = json_value
|
||||||
|
except:
|
||||||
|
matches[key] = value
|
||||||
|
return matches
|
||||||
|
|
||||||
|
|
||||||
def parse_body(body, content_type):
|
def parse_body(body, content_type):
|
||||||
if not body or content_type == "text/plain":
|
if not body or content_type == "text/plain":
|
||||||
return body
|
return body
|
||||||
|
|
||||||
parsed = {}
|
parsed = parse_string(input_string)
|
||||||
lines = body.split("\n")
|
|
||||||
|
|
||||||
for line in lines:
|
|
||||||
i = line.find(":")
|
|
||||||
if i == -1:
|
|
||||||
continue
|
|
||||||
|
|
||||||
key = line[:i].strip()
|
|
||||||
val = line[i + 1 :].strip()
|
|
||||||
|
|
||||||
if not key or key in parsed:
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
json_value = json.loads(val)
|
|
||||||
parsed[key] = json_value
|
|
||||||
except:
|
|
||||||
parsed[key] = val
|
|
||||||
|
|
||||||
if content_type == "application/x-www-form-urlencoded":
|
if content_type == "application/x-www-form-urlencoded":
|
||||||
data = urlencode(parsed, doseq=True)
|
data = urlencode(parsed, doseq=True)
|
||||||
|
|
|
@ -68,13 +68,13 @@ const Log = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSelect = (value: any, node: any) => {
|
const onSelect = (value: any, node: any) => {
|
||||||
setCurrentNode(node);
|
|
||||||
setSelect(value);
|
|
||||||
|
|
||||||
if (node.key === select || !value) {
|
if (node.key === select || !value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCurrentNode(node);
|
||||||
|
setSelect(value);
|
||||||
|
|
||||||
if (node.type === 'directory') {
|
if (node.type === 'directory') {
|
||||||
setValue(intl.get('请选择日志文件'));
|
setValue(intl.get('请选择日志文件'));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -115,13 +115,13 @@ const Script = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSelect = (value: any, node: any) => {
|
const onSelect = (value: any, node: any) => {
|
||||||
setSelect(node.key);
|
|
||||||
setCurrentNode(node);
|
|
||||||
|
|
||||||
if (node.key === select || !value) {
|
if (node.key === select || !value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSelect(node.key);
|
||||||
|
setCurrentNode(node);
|
||||||
|
|
||||||
if (node.type === 'directory') {
|
if (node.type === 'directory') {
|
||||||
setValue(intl.get('请选择脚本文件'));
|
setValue(intl.get('请选择脚本文件'));
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user