UNPKG

@herbertgao/surgio

Version:

Generating rules for Surge, Clash, Quantumult like a PRO

53 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseSSRUri = void 0; const logger_1 = require("@surgio/logger"); const types_1 = require("../types"); const index_1 = require("./index"); const logger = (0, logger_1.createLogger)({ service: 'surgio:utils:ssr' }); /** * 协议:https://github.com/shadowsocksr-backup/shadowsocks-rss/wiki/SSR-QRcode-scheme * ssr://xxx:xxx:xxx:xxx:xxx:xxx/?a=1&b=2 * ssr://xxx:xxx:xxx:xxx:xxx:xxx */ const parseSSRUri = (str) => { const scheme = (0, index_1.fromUrlSafeBase64)(str.replace('ssr://', '')); const configArray = scheme.split('/'); const basicInfo = configArray[0].split(':'); logger.debug('SSR URI', scheme); // 去除首部分 configArray.shift(); const extraString = configArray.join('/'); const extras = extraString ? getUrlParameters(extraString) : {}; const password = (0, index_1.fromUrlSafeBase64)(basicInfo.pop()); const obfs = basicInfo.pop(); const method = basicInfo.pop(); const protocol = basicInfo.pop(); const port = basicInfo.pop(); const hostname = basicInfo.join(':'); const nodeName = extras.remarks ? (0, index_1.fromUrlSafeBase64)(extras.remarks) : `${hostname}:${port}`; return { type: types_1.NodeTypeEnum.Shadowsocksr, nodeName, hostname, port, protocol, method, obfs, password, protoparam: (0, index_1.fromUrlSafeBase64)(extras.protoparam ?? '').replace(/\s/g, ''), obfsparam: (0, index_1.fromUrlSafeBase64)(extras.obfsparam ?? '').replace(/\s/g, ''), }; }; exports.parseSSRUri = parseSSRUri; function getUrlParameters(url) { const result = {}; url.replace(/[?&]+([^=&]+)=([^&#]*)/gi, (origin, k, v) => { result[k] = v; return origin; }); return result; } //# sourceMappingURL=ssr.js.map