V 2.2.7 lama iopaint 去水印
This commit is contained in:
+28
-7
@@ -51,27 +51,45 @@ let basicApi = {
|
||||
/**
|
||||
* 使用electron的net模块实现的post方法
|
||||
* @param {*} url 请求的url
|
||||
* @param {*} data 传输的数据(json格式)
|
||||
* @param {*} data 传输的数据,,所有格式
|
||||
* @param {*} headers 请求头
|
||||
* @returns
|
||||
*/
|
||||
post: (url, data = {}, headers = {}) => {
|
||||
post: (url, data = {}, headers = {}, others = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = net.request({
|
||||
let req_obj = {
|
||||
method: 'POST',
|
||||
url: url,
|
||||
headers: Object.assign({
|
||||
'Content-Type': 'application/json',
|
||||
}, headers)
|
||||
});
|
||||
}
|
||||
req_obj = Object.assign(req_obj, others);
|
||||
const request = net.request(req_obj);
|
||||
|
||||
request.write(JSON.stringify(data));
|
||||
|
||||
request.on('response', (response) => {
|
||||
let responseData = '';
|
||||
let responseData;
|
||||
if (response.headers["content-type"] === "application/json") {
|
||||
|
||||
responseData = '';
|
||||
} else if (response.headers["content-type"].startsWith("image/")) {
|
||||
// 处理图片数据
|
||||
responseData = []
|
||||
}
|
||||
else {
|
||||
throw new Error("未知的请求返回数据类型");
|
||||
}
|
||||
|
||||
response.on('data', (chunk) => {
|
||||
responseData += chunk;
|
||||
if (response.headers['content-type'] === 'application/json') {
|
||||
// 处理 JSON 数据
|
||||
responseData += chunk;
|
||||
} else if (response.headers['content-type'].startsWith('image/')) {
|
||||
// 处理图片数据
|
||||
responseData.push(chunk);
|
||||
}
|
||||
});
|
||||
|
||||
response.on('end', () => {
|
||||
@@ -83,8 +101,11 @@ let basicApi = {
|
||||
let parsedData;
|
||||
if (response.headers['content-type'].includes('application/json')) {
|
||||
parsedData = JSON.parse(responseData);
|
||||
} else if (response.headers['content-type'].startsWith('image/')) {
|
||||
// parsedData = responseData;
|
||||
parsedData = Buffer.concat(responseData);
|
||||
} else {
|
||||
parsedData = responseData;
|
||||
throw new Error("未知的请求返回数据类型");
|
||||
}
|
||||
|
||||
resolve({
|
||||
|
||||
Reference in New Issue
Block a user