mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: requests
This commit is contained in:
parent
cf288a3f73
commit
1a8407a782
@ -66,7 +66,7 @@ export function cacheFunc(ttl: number, customKey: string = '') {
|
|||||||
return descriptor;
|
return descriptor;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function isValidOldConfig(config: any) {
|
export function isValidOldConfig(config: any) {
|
||||||
if (typeof config !== 'object') {
|
if (typeof config !== 'object') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ function isValidOldConfig(config: any) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function migrateConfig(oldConfig: any) {
|
export function migrateConfig(oldConfig: any) {
|
||||||
const newConfig = {
|
const newConfig = {
|
||||||
http: {
|
http: {
|
||||||
enable: oldConfig.enableHttp,
|
enable: oldConfig.enableHttp,
|
||||||
|
@ -30,7 +30,7 @@ export class RequestUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 请求和回复都是JSON data传原始内容 自动编码json
|
// 请求和回复都是JSON data传原始内容 自动编码json
|
||||||
static async HttpGetJson<T>(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}, isJsonRet: boolean = true): Promise<T> {
|
static async HttpGetJson<T>(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}, isJsonRet: boolean = true, isArgJson: boolean = true): Promise<T> {
|
||||||
let option = new URL(url);
|
let option = new URL(url);
|
||||||
const protocol = url.startsWith('https://') ? https : http;
|
const protocol = url.startsWith('https://') ? https : http;
|
||||||
const options = {
|
const options = {
|
||||||
@ -69,7 +69,12 @@ export class RequestUtil {
|
|||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
|
if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
|
||||||
req.write(JSON.stringify(data));
|
if (isArgJson) {
|
||||||
|
req.write(JSON.stringify(data));
|
||||||
|
} else {
|
||||||
|
req.write(data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
@ -77,7 +82,6 @@ export class RequestUtil {
|
|||||||
|
|
||||||
// 请求返回都是原始内容
|
// 请求返回都是原始内容
|
||||||
static async HttpGetText(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}) {
|
static async HttpGetText(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}) {
|
||||||
//console.log(url);
|
return this.HttpGetJson<string>(url, method, data, headers, false, false);
|
||||||
return this.HttpGetJson<string>(url, method, data, headers, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user