fix (restful): Intercept IP-API query failed message when querying node info

This commit is contained in:
Peng-YM 2022-07-12 18:34:22 +08:00
parent f7333c0617
commit 3d58534dfe
5 changed files with 26 additions and 12 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.11.0",
"version": "2.11.1",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@ -175,6 +175,7 @@ async function gistBackup(req, res) {
async function getNodeInfo(req, res) {
const proxy = req.body;
const lang = req.query.lang || 'zh-CN';
let shareUrl;
try {
shareUrl = producer.URI.produce(proxy);
@ -186,13 +187,26 @@ async function getNodeInfo(req, res) {
const $http = HTTP();
const info = await $http
.get({
url: `http://ip-api.com/json/${proxy.server}?lang=zh-CN`,
url: `http://ip-api.com/json/${encodeURIComponent(
proxy.server,
)}?lang=${lang}`,
headers: {
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15',
},
})
.then((resp) => JSON.parse(resp.body));
.then((resp) => {
const data = JSON.parse(resp.body);
if (data.status !== 'success') {
throw new Error(data.message);
}
// remove unnecessary fields
delete data.status;
delete data.query;
return data;
});
success(res, {
shareUrl,
info,

File diff suppressed because one or more lines are too long