mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-06-22 09:20:55 +08:00
Merge pull request #274 from izhangxm/feat_add_proxy_convter_api
增加规则转换与协议转换API接口
This commit is contained in:
commit
31b48d7a6c
@ -16,6 +16,7 @@ import registerPreviewRoutes from './preview';
|
|||||||
import registerSortingRoutes from './sort';
|
import registerSortingRoutes from './sort';
|
||||||
import registerMiscRoutes from './miscs';
|
import registerMiscRoutes from './miscs';
|
||||||
import registerNodeInfoRoutes from './node-info';
|
import registerNodeInfoRoutes from './node-info';
|
||||||
|
import registerParserRoutes from './parser';
|
||||||
|
|
||||||
export default function serve() {
|
export default function serve() {
|
||||||
let port;
|
let port;
|
||||||
@ -38,6 +39,7 @@ export default function serve() {
|
|||||||
registerSyncRoutes($app);
|
registerSyncRoutes($app);
|
||||||
registerNodeInfoRoutes($app);
|
registerNodeInfoRoutes($app);
|
||||||
registerMiscRoutes($app);
|
registerMiscRoutes($app);
|
||||||
|
registerParserRoutes($app);
|
||||||
|
|
||||||
$app.start();
|
$app.start();
|
||||||
|
|
||||||
|
46
backend/src/restful/parser.js
Normal file
46
backend/src/restful/parser.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { success, failed } from '@/restful/response';
|
||||||
|
import { ProxyUtils } from '@/core/proxy-utils';
|
||||||
|
import { RuleUtils } from '@/core/rule-utils';
|
||||||
|
|
||||||
|
export default function register($app) {
|
||||||
|
$app.route('/api/proxy/parse').post(proxy_parser);
|
||||||
|
$app.route('/api/rule/parse').post(rule_parser);
|
||||||
|
}
|
||||||
|
/***
|
||||||
|
* 代理服务器协议转换接口。
|
||||||
|
* 请求方法为POST,数据为json。需要提供data和client字段。
|
||||||
|
* data: string, 协议数据,每行一个或者是clash
|
||||||
|
* client: string, 目标平台名称,见backend/src/core/proxy-utils/producers/index.js
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function proxy_parser(req, res) {
|
||||||
|
const { data, client } = req.body;
|
||||||
|
var result = {};
|
||||||
|
try {
|
||||||
|
var proxies = ProxyUtils.parse(data);
|
||||||
|
var par_res = ProxyUtils.produce(proxies, client);
|
||||||
|
result['par_res'] = par_res;
|
||||||
|
} catch (err) {
|
||||||
|
failed(res, err);
|
||||||
|
}
|
||||||
|
success(res, result);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 规则转换接口。
|
||||||
|
* 请求方法为POST,数据为json。需要提供data和client字段。
|
||||||
|
* data: string, 多行规则字符串
|
||||||
|
* client: string, 目标平台名称,具体见backend/src/core/rule-utils/producers.js
|
||||||
|
*/
|
||||||
|
function rule_parser(req, res) {
|
||||||
|
const { data, client } = req.body;
|
||||||
|
var result = {};
|
||||||
|
try {
|
||||||
|
const rules = RuleUtils.parse(data);
|
||||||
|
var par_res = RuleUtils.produce(rules, client);
|
||||||
|
result['par_res'] = par_res;
|
||||||
|
} catch (err) {
|
||||||
|
failed(res, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
success(res, result);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user