-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (55 loc) · 2.28 KB
/
index.js
File metadata and controls
58 lines (55 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import processNodeConversion from './src/index.js'
export default {
async fetch(request) {
try {
const url = new URL(request.url);
const target = url.searchParams.get('target');
const inputnode = url.searchParams.get('url');
const nodeArray = inputnode ? inputnode.split(/[,|]/) : [];
if (!target || nodeArray.length === 0) {
return renderUsageInstructions();
}
const result = await processNodeConversion(nodeArray, target);
let data = result.data
if (typeof data == 'object') {
data = JSON.stringify(data)
}
return new Response(data, {
status: result.status,
headers: result.headers,
});
} catch (error) {
return new Response(`Error: ${error.message}`, { status: 500 });
}
},
};
/**
* 返回使用说明
* 同步更新到 Sub-Store :https://github.com/sub-store-org/Sub-Store/commit/dd2ed938e376a225e08e9d498098466b9175b045
* @returns {Response} 包含使用说明的JSON响应
*/
function renderUsageInstructions() {
return new Response(
JSON.stringify(
{
version: 'SubStore v2.21.32',
message: '这是一个基于 cloudflare workers 的 sub-store 节点转换工具,仅转换节点用',
usage: {
target: '输出类型:{singbox|mihomo|v2ray|base64|qx|QX|QuantumultX|surge|Surge|SurgeMac|Loon|Clash|meta|clashmeta|clash.meta|Clash.Meta|ClashMeta|Mihomo|uri|URI|json|JSON|stash|Stash|shadowrocket|Shadowrocket|ShadowRocket|surfboard|Surfboard|egern|Egern}',
url: '输入编码后的订阅链接,多个订阅可用英文逗号(,)分隔',
example: '/?target=v2ray&url=UrlEncode(编码后的订阅)',
examples: [
'/?target=v2ray&url=https%3A%2F%2Fexample.com%2Fsubscription',
'/?target=clash&url=https%3A%2F%2Fexample.com%2Fsub1,https%3A%2F%2Fexample.com%2Fsub1'
]
}
},
null,
4
),
{
status: 200,
headers: { 'Content-Type': 'application/json' },
}
);
}