不能用的,把60行的requestapi函数换成这个 async function requestAPI(api, params, data) { const method = api.method; const origin = "https://www.2-class.com"; let url = `${origin}/api${api.api}`;
// Replace URL placeholders with actual values for (const key in params) { url = url.replaceAll("${" + key + "}", params[key]); }
// Retrieve browser cookies const cookies = document.cookie;
if (method === "GET") { return await axios({ method: "GET", url, withCredentials: true, // Include cookies in the request headers: { Cookie: cookies, // Pass the cookies in the headers }, }).then((response) => { const rdata = response.data; console.debug(`[${method}] ${url}`, data, rdata);
if (rdata.success === false || rdata.data === null) { const errorMessage = rdata.errorMsg; const errorCode = rdata.errorCode; console.error(`API 返回错误 [${errorCode}]:${errorMessage},请刷新页面重试!`); return null; } else { return rdata; } }).catch((reason) => { showMessage(`请求 API 失败(${reason.code}):${reason.message}\n请将控制台中的具体报错提交!`, "red"); console.error(`请求失败(${reason.status}/${reason.code})→${reason.message}→`, reason.toJSON(), reason.response, reason.stack); }); } else { return await axios({ method: "POST", url, withCredentials: true, // Include cookies in the request headers: { "Content-Type": "application/json;charset=UTF-8", Cookie: cookies, // Pass the cookies in the headers }, data, }).then((response) => { const rdata = response.data; console.debug(`[${method}] ${url}`, data, rdata);
不能用的,把60行的requestapi函数换成这个
async function requestAPI(api, params, data) {
const method = api.method;
const origin = "https://www.2-class.com";
let url = `${origin}/api${api.api}`;
// Replace URL placeholders with actual values
for (const key in params) {
url = url.replaceAll("${" + key + "}", params[key]);
}
// Retrieve browser cookies
const cookies = document.cookie;
if (method === "GET") {
return await axios({
method: "GET",
url,
withCredentials: true, // Include cookies in the request
headers: {
Cookie: cookies, // Pass the cookies in the headers
},
}).then((response) => {
const rdata = response.data;
console.debug(`[${method}] ${url}`, data, rdata);
if (rdata.success === false || rdata.data === null) {
const errorMessage = rdata.errorMsg;
const errorCode = rdata.errorCode;
console.error(`API 返回错误 [${errorCode}]:${errorMessage},请刷新页面重试!`);
return null;
} else {
return rdata;
}
}).catch((reason) => {
showMessage(`请求 API 失败(${reason.code}):${reason.message}\n请将控制台中的具体报错提交!`, "red");
console.error(`请求失败(${reason.status}/${reason.code})→${reason.message}→`, reason.toJSON(), reason.response, reason.stack);
});
} else {
return await axios({
method: "POST",
url,
withCredentials: true, // Include cookies in the request
headers: {
"Content-Type": "application/json;charset=UTF-8",
Cookie: cookies, // Pass the cookies in the headers
},
data,
}).then((response) => {
const rdata = response.data;
console.debug(`[${method}] ${url}`, data, rdata);
if (rdata.success === false || rdata.data === null) {
const errorMessage = rdata.errorMsg;
const errorCode = rdata.errorCode;
console.error(`API 返回错误 [${errorCode}]:${errorMessage},请刷新页面重试!`);
return null;
} else {
return rdata;
}
});
}
}