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