This repository has been archived by the owner on Jul 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
104 lines (104 loc) · 9.3 KB
/
index.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var url_1 = require("url");
var base64 = /** @class */ (function () {
function base64() {
}
base64.encode = function (string) {
var base64String;
if (!string)
string = '';
base64String = Buffer.from(string).toString('base64');
return base64String;
};
base64.decode = function (base64String) {
var clearString;
if (!base64String)
base64String = '';
clearString = Buffer.from(base64String, 'base64').toString('utf8');
return clearString;
};
return base64;
}());
var encode = base64.encode, decode = base64.decode;
var SsUrl = /** @class */ (function () {
function SsUrl() {
}
SsUrl.genSS = function (config) {
var settings = "" + encode(config.method + ":" + config.password);
var hostname = config.server + ":" + config.server_port;
var name = '';
var plugin = '';
if (config.plugin) {
plugin = "?plugin=" + config.plugin;
}
if (config.plugin && config.plugin_param) {
plugin = plugin + encodeURIComponent(';' + config.plugin_param);
}
if (config.name) {
name = '#' + encodeURI(config.name ? config.name : '');
}
return "ss://" + settings + "@" + hostname + plugin + name;
};
SsUrl.genSSR = function (config) {
var hostname = config.server + ":" + config.server_port;
var settings = config.protocol + ":" + config.method + ":" + encode(config.obfs) + ":" + config.password;
var params = '?obfsparam=' + encode(config.obfs_param) +
'&protoparam=' + encode(config.protocol_param) +
'&remarks=' + encode(config.name) +
'&group=' + encode(config.group);
var URI = hostname + ":" + settings + "/" + params;
return 'ssr://' + encode(URI);
};
SsUrl.parseSS = function (url) {
var URI = url.replace('ss://', '').split('@');
var params = new url_1.URLSearchParams(URI[1].split('?')[1]);
var parsedURL = {
method: /*------*/ decode(URI[0])
.split(':')[0],
password: /*----*/ decode(URI[0])
.split(':')[1],
server: /*------*/ URI[1]
.split('#')[0]
.split(':')[0],
server_port: /*-*/ Number(URI[1]
.split('#')[0]
.split(':')[1]
.split('?')[0])
};
var name = URI[1].split('#')[1];
if (name)
parsedURL.name = decodeURI(name);
if (params.has('plugin')) {
parsedURL.plugin = params.get('plugin')
.split(';')[0];
var pluginRaramEncoded = URI[1].split('?')[1]
.split('#')[0];
if (pluginRaramEncoded) {
parsedURL.plugin_param = decodeURIComponent(pluginRaramEncoded)
// "plugin=v2ray;" <<< path=/v2ray/;host=example.com;tls
.replace("plugin=" + parsedURL.plugin + ";", '');
}
}
return parsedURL;
};
SsUrl.parseSSR = function (url) {
var URI = decode(url.replace('ssr://', '')).split(':');
var params = new url_1.URLSearchParams(URI[5].split('/')[1]);
return {
server: /*---------*/ URI[0],
server_port: /*----*/ Number(URI[1]),
protocol: /*-------*/ URI[2],
method: /*---------*/ URI[3],
obfs: /*-----------*/ decode(URI[4]),
password: /*-------*/ URI[5].split('/')[0],
name: /*-----------*/ decode(params.get('remarks')),
obfs_param: /*-----*/ decode(params.get('obfsparam')),
protocol_param: /*-*/ decode(params.get('protoparam')),
group: /*----------*/ decode(params.get('group'))
};
};
return SsUrl;
}());
exports.default = SsUrl;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDJCQUFzQztBQXVCdEM7SUFBQTtJQWNBLENBQUM7SUFiVSxhQUFNLEdBQWIsVUFBYyxNQUFjO1FBQ3hCLElBQUksWUFBWSxDQUFBO1FBQ2hCLElBQUksQ0FBQyxNQUFNO1lBQUUsTUFBTSxHQUFHLEVBQUUsQ0FBQTtRQUN4QixZQUFZLEdBQUcsTUFBTSxDQUFDLElBQ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