修复设置自定义通知

This commit is contained in:
whyour
2022-09-20 18:00:36 +08:00
parent 1ebcfd8001
commit e08f0cd308
6 changed files with 68 additions and 68 deletions
+1 -5
View File
@@ -13,15 +13,11 @@ const NotificationSetting = ({ data }: any) => {
const [form] = Form.useForm();
const handleOk = (values: any) => {
const { type, webhookBody, webhookContentType } = values;
const { type } = values;
if (type == 'closed') {
values.type = '';
}
if (type === 'webhook') {
values.webhookHeaders = { ...parseHeaders(values.webhookHeaders) };
values.webhookBody = parseBody(webhookBody, webhookContentType);
}
request
.put(`${config.apiPrefix}user/notification`, {
data: {
-59
View File
@@ -266,64 +266,5 @@ export function depthFirstSearch<
}
})(c);
console.log(keys);
return c;
}
export function parseHeaders(headers: string) {
if (!headers) return {};
const parsed: any = {};
let key;
let val;
let i;
headers && headers.split('\n').forEach(function parser(line) {
i = line.indexOf(':');
key = line.substring(0, i).trim().toLowerCase();
val = line.substring(i + 1).trim();
if (!key) {
return;
}
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
});
return parsed;
};
export function parseBody(body: string, contentType: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded') {
if (!body) return '';
const parsed: any = {};
let key;
let val;
let i;
body && body.split('\n').forEach(function parser(line) {
i = line.indexOf(':');
key = line.substring(0, i).trim().toLowerCase();
val = line.substring(i + 1).trim();
if (!key || parsed[key]) {
return;
}
parsed[key] = val;
});
switch (contentType) {
case 'multipart/form-data':
return Object.keys(parsed).reduce((p, c) => {
p.append(c, parsed[c])
return p;
}, new FormData());
case 'application/x-www-form-urlencoded':
return Object.keys(parsed).reduce((p, c) => {
return p ? `${p}&${c}=${parsed[c]}` : `${c}=${parsed[c]}`;
});
}
return parsed;
};