mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 22:19:00 +08:00
Add Clash and Subscription producer
This commit is contained in:
parent
8b626ffad3
commit
33ae67ab60
@ -20,6 +20,7 @@ $.http = HTTP({
|
||||
const SETTINGS_KEY = "settings";
|
||||
const SUBS_KEY = "subs";
|
||||
const COLLECTIONS_KEY = "collections";
|
||||
|
||||
const AVAILABLE_FILTERS = {
|
||||
"Keyword Filter": KeywordFilter,
|
||||
"Useless Filter": UselessFilter,
|
||||
@ -41,13 +42,17 @@ const AVAILABLE_OPERATORS = {
|
||||
"Script Operator": ScriptOperator,
|
||||
};
|
||||
|
||||
const AVAILABLE_PRODUCERS = [
|
||||
Raw_Producer, URI_Producer,
|
||||
Surge_Producer, Loon_Producer, QX_Producer, Clash_Producer, Sub_Producer
|
||||
];
|
||||
|
||||
// SOME INITIALIZATIONS
|
||||
if (!$.read(SUBS_KEY)) $.write({}, SUBS_KEY);
|
||||
if (!$.read(COLLECTIONS_KEY)) $.write({}, COLLECTIONS_KEY);
|
||||
if (!$.read(SETTINGS_KEY)) $.write({}, SETTINGS_KEY);
|
||||
|
||||
// BACKEND API
|
||||
$.info("Initializing Express...");
|
||||
|
||||
// download
|
||||
$app.get("/download/collection/:name", downloadCollection);
|
||||
@ -88,7 +93,6 @@ $app.all("/", async (req, res) => {
|
||||
res.send("Hello from Sub-Store! Made with ❤️ by Peng-YM.");
|
||||
});
|
||||
|
||||
$.info("Express initialized");
|
||||
$app.start();
|
||||
|
||||
async function IP_API(req, res) {
|
||||
@ -324,13 +328,7 @@ async function parseSub(sub, platform) {
|
||||
}
|
||||
|
||||
// Producers
|
||||
$parser.addProducers([
|
||||
QX_Producer,
|
||||
Loon_Producer,
|
||||
Surge_Producer,
|
||||
Raw_Producer,
|
||||
URI_Producer,
|
||||
]);
|
||||
$parser.addProducers(AVAILABLE_PRODUCERS);
|
||||
return $parser.produce(proxies);
|
||||
}
|
||||
|
||||
@ -676,6 +674,7 @@ function ProxyParser(targetPlatform) {
|
||||
function produce(proxies) {
|
||||
for (const p of producers) {
|
||||
if (p.targetPlatform === targetPlatform) {
|
||||
if (typeof p.type === 'undefined' || p.type === "SINGLE") {
|
||||
return proxies
|
||||
.map((proxy) => {
|
||||
try {
|
||||
@ -691,6 +690,10 @@ function ProxyParser(targetPlatform) {
|
||||
})
|
||||
.filter((v) => v.length > 0) // discard empty lines
|
||||
.join("\n");
|
||||
} else if (p.type === 'ALL') {
|
||||
return p.output(proxies);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
@ -1860,7 +1863,7 @@ function URI_Producer() {
|
||||
result += `#${encodeURIComponent(proxy.name)}`;
|
||||
break;
|
||||
case "ssr":
|
||||
result = `${proxy.server}:${proxy.port}:${proxy.protocol}:${
|
||||
result = `ssr://${proxy.server}:${proxy.port}:${proxy.protocol}:${
|
||||
proxy.cipher
|
||||
}:${proxy.obfs}:${Base64.safeEncode(proxy.password)}/`;
|
||||
result += `?remarks=${proxy.name}${
|
||||
@ -1872,7 +1875,6 @@ function URI_Producer() {
|
||||
? "&protocolparam=" + Base64.safeEncode(proxy["protocol-param"])
|
||||
: ""
|
||||
}`;
|
||||
result = "vmess://" + Base64.safeEncode(result);
|
||||
break;
|
||||
case "vmess":
|
||||
// V2RayN URI format
|
||||
@ -1891,7 +1893,7 @@ function URI_Producer() {
|
||||
result.path = proxy["ws-path"] || "/";
|
||||
result.host = proxy["ws-headers"].Host || proxy.server;
|
||||
}
|
||||
result = Base64.safeEncode(JSON.stringify(result));
|
||||
result = "vmess://" + Base64.safeEncode(JSON.stringify(result));
|
||||
break;
|
||||
case "trojan":
|
||||
result = `trojan://${proxy.password}@${proxy.server}:${proxy.port}#${proxy.name}`;
|
||||
@ -1904,6 +1906,35 @@ function URI_Producer() {
|
||||
return {targetPlatform, output};
|
||||
}
|
||||
|
||||
function Clash_Producer() {
|
||||
const targetPlatform = "Clash";
|
||||
const type = "ALL";
|
||||
const output = (proxies) => {
|
||||
return "proxies:\n" + proxies.map(proxy => {
|
||||
delete proxy.supported;
|
||||
return " - " + JSON.stringify(proxy) + "\n";
|
||||
}).join("");
|
||||
};
|
||||
return {targetPlatform, type, output};
|
||||
}
|
||||
|
||||
function Sub_Producer() {
|
||||
const targetPlatform = "Sub";
|
||||
const type = "ALL";
|
||||
const output = (proxies) => {
|
||||
const urls = proxies.map(proxy => {
|
||||
try {
|
||||
return URI_Producer().output(proxy) + "\n";
|
||||
} catch (e) {
|
||||
return "";
|
||||
}
|
||||
}).join("");
|
||||
const Base64 = new Base64Code();
|
||||
return Base64.encode(urls);
|
||||
};
|
||||
return {targetPlatform, type, output};
|
||||
}
|
||||
|
||||
/**************************** Operators ***************************************/
|
||||
// force to set some properties (e.g., scert, udp, tfo, etc.)
|
||||
function SetPropertyOperator({key, value}) {
|
||||
@ -2488,9 +2519,11 @@ function HTTP(defaultOptions = {}) {
|
||||
const timeout = options.timeout;
|
||||
const events = {
|
||||
...{
|
||||
onRequest: () => {},
|
||||
onRequest: () => {
|
||||
},
|
||||
onResponse: (resp) => resp,
|
||||
onTimeout: () => {},
|
||||
onTimeout: () => {
|
||||
},
|
||||
},
|
||||
...options.events,
|
||||
};
|
||||
@ -3102,6 +3135,7 @@ function Gist(backupKey, token) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/******************************** Base 64 *********************************************/
|
||||
// Base64 Coding Library
|
||||
// https://github.com/dankogai/js-base64#readme
|
||||
|
2
backend/sub-store.min.js
vendored
2
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