mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-11 15:29:01 +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",
|
||||
"version": "2.10.2",
|
||||
"version": "2.11.0",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -21,8 +21,13 @@ import registerSettingRoutes, {
|
||||
import registerPreviewRoutes from './preview';
|
||||
import registerSortingRoutes from './sort';
|
||||
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 producer from '@/core/proxy-utils/producers';
|
||||
|
||||
export default function serve() {
|
||||
const $app = express({ substore: $ });
|
||||
@ -37,7 +42,7 @@ export default function serve() {
|
||||
registerArtifactRoutes($app);
|
||||
|
||||
// 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/backup', gistBackup); // gist backup actions
|
||||
$app.get('/api/utils/refresh', refresh);
|
||||
@ -168,11 +173,38 @@ async function gistBackup(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
async function IP_API(req, res) {
|
||||
const server = decodeURIComponent(req.params.server);
|
||||
async function getNodeInfo(req, res) {
|
||||
const proxy = req.body;
|
||||
let shareUrl;
|
||||
try {
|
||||
shareUrl = producer.URI.produce(proxy);
|
||||
} catch (err) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
try {
|
||||
const $http = HTTP();
|
||||
const result = await $http
|
||||
.get(`http://ip-api.com/json/${server}?lang=zh-CN`)
|
||||
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));
|
||||
res.json(result);
|
||||
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