mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-12 02:09:03 +08:00
feat (restful): Add /api/utils/node-info for querying proxy node info
This commit is contained in:
parent
8c844eb23a
commit
f7d4b66db6
6
backend/dist/cron-sync-artifacts.min.js
vendored
6
backend/dist/cron-sync-artifacts.min.js
vendored
File diff suppressed because one or more lines are too long
6
backend/dist/sub-store-parser.loon.min.js
vendored
6
backend/dist/sub-store-parser.loon.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.10.2",
|
"version": "2.11.0",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -21,8 +21,13 @@ import registerSettingRoutes, {
|
|||||||
import registerPreviewRoutes from './preview';
|
import registerPreviewRoutes from './preview';
|
||||||
import registerSortingRoutes from './sort';
|
import registerSortingRoutes from './sort';
|
||||||
import { failed, success } from '@/restful/response';
|
import { failed, success } from '@/restful/response';
|
||||||
import { InternalServerError, RequestInvalidError } from '@/restful/errors';
|
import {
|
||||||
|
InternalServerError,
|
||||||
|
NetworkError,
|
||||||
|
RequestInvalidError,
|
||||||
|
} from '@/restful/errors';
|
||||||
import resourceCache from '@/utils/resource-cache';
|
import resourceCache from '@/utils/resource-cache';
|
||||||
|
import producer from '@/core/proxy-utils/producers';
|
||||||
|
|
||||||
export default function serve() {
|
export default function serve() {
|
||||||
const $app = express({ substore: $ });
|
const $app = express({ substore: $ });
|
||||||
@ -37,7 +42,7 @@ export default function serve() {
|
|||||||
registerArtifactRoutes($app);
|
registerArtifactRoutes($app);
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
$app.get('/api/utils/IP_API/:server', IP_API); // IP-API reverse proxy
|
$app.post('/api/utils/node-info', getNodeInfo);
|
||||||
$app.get('/api/utils/env', getEnv); // get runtime environment
|
$app.get('/api/utils/env', getEnv); // get runtime environment
|
||||||
$app.get('/api/utils/backup', gistBackup); // gist backup actions
|
$app.get('/api/utils/backup', gistBackup); // gist backup actions
|
||||||
$app.get('/api/utils/refresh', refresh);
|
$app.get('/api/utils/refresh', refresh);
|
||||||
@ -168,11 +173,38 @@ async function gistBackup(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function IP_API(req, res) {
|
async function getNodeInfo(req, res) {
|
||||||
const server = decodeURIComponent(req.params.server);
|
const proxy = req.body;
|
||||||
const $http = HTTP();
|
let shareUrl;
|
||||||
const result = await $http
|
try {
|
||||||
.get(`http://ip-api.com/json/${server}?lang=zh-CN`)
|
shareUrl = producer.URI.produce(proxy);
|
||||||
.then((resp) => JSON.parse(resp.body));
|
} catch (err) {
|
||||||
res.json(result);
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const $http = HTTP();
|
||||||
|
const info = await $http
|
||||||
|
.get({
|
||||||
|
url: `http://ip-api.com/json/${proxy.server}?lang=zh-CN`,
|
||||||
|
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));
|
||||||
|
success(res, {
|
||||||
|
shareUrl,
|
||||||
|
info,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
failed(
|
||||||
|
res,
|
||||||
|
new NetworkError(
|
||||||
|
'FAILED_TO_GET_NODE_INFO',
|
||||||
|
`Failed to get node info`,
|
||||||
|
`Reason: ${err}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
6
backend/sub-store.min.js
vendored
6
backend/sub-store.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user