This commit is contained in:
Peng-YM
2020-08-19 21:34:35 +08:00
parent fe2f37984f
commit d71fb0a1cf
13 changed files with 307 additions and 215 deletions

12
backend/.idea/backend.iml generated Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
backend/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/backend.iml" filepath="$PROJECT_DIR$/.idea/backend.iml" />
</modules>
</component>
</project>

6
backend/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

72
backend/.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="8b97a098-48b2-4e64-a9ef-522fe2d30b52" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/sub-store.js" beforeDir="false" afterPath="$PROJECT_DIR$/sub-store.js" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="ProjectId" id="1gJLR8mqORpDqtMcT5mk25VXwmL" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="ASKED_ADD_EXTERNAL_FILES" value="true" />
<property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="8b97a098-48b2-4e64-a9ef-522fe2d30b52" name="Default Changelist" comment="" />
<created>1597827738046</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1597827738046</updated>
<workItem from="1597827739128" duration="775000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
</project>

View File

@@ -10,7 +10,6 @@
*/
const $ = API("sub-store");
// Constants
const SUBS_KEY = "subs";
const COLLECTIONS_KEY = "collections";
@@ -22,9 +21,6 @@ if (!$.read(COLLECTIONS_KEY)) $.write({}, COLLECTIONS_KEY);
// BACKEND API
const $app = express();
// subscriptions
$app.get("/download/:name", downloadSub)
$app.route("/sub/:name")
.get(getSub)
.patch(updateSub)
@@ -35,6 +31,9 @@ $app.route("/sub")
.post(newSub)
.delete(deleteAllSubs);
// subscriptions
$app.get("/download/:name", downloadSub);
// collections
$app.get("/download/collection/:name", downloadCollection);
$app.route("/collection/:name")
@@ -53,7 +52,6 @@ $app.all("/", (req, res) => {
$app.start();
// SOME CONSTANTS
const FALL_BACK_TARGET = "Raw";
const DEFAULT_SUPPORTED_PLATFORMS = {
QX: true,
Loon: true,
@@ -405,7 +403,6 @@ function ProxyParser(targetPlatform) {
// skip unsupported proxies
// if proxy.supported is undefined, assume that all platforms are supported.
if (typeof proxy.supported === 'undefined' || proxy.supported[targetPlatform]) {
delete proxy.supported;
result.push(proxy);
break;
}
@@ -418,9 +415,6 @@ function ProxyParser(targetPlatform) {
console.log(`ERROR: Failed to find a rule to parse line: \n${line}\n`);
}
}
if (result.length === 0) {
throw new Error(`ERROR: Input does not contains any valid node for platform ${targetPlatform}`)
}
return result;
}
@@ -429,7 +423,7 @@ function ProxyParser(targetPlatform) {
if (p.targetPlatform === targetPlatform) {
return proxies.map(proxy => {
try {
return p.output(proxy)
return p.output(proxy);
} catch (err) {
console.log(`ERROR: cannot produce proxy: ${JSON.stringify(proxy)}\nReason: ${err}`);
return "";
@@ -1238,6 +1232,7 @@ function QX_Producer() {
}
function Loon_Producer() {
$.notify("LOON")
const targetPlatform = "Loon";
const output = (proxy) => {
let obfs_opts, tls_opts;
@@ -1730,7 +1725,7 @@ function getPlatformFromHeaders(headers) {
const keys = Object.keys(headers);
let UA = "";
for (let k of keys) {
if (k.match(/USER-AGENT/i)) {
if (/USER-AGENT/i.test(k)) {
UA = headers[k];
break;
}
@@ -1743,7 +1738,7 @@ function getPlatformFromHeaders(headers) {
return "Loon";
} else {
// browser
return FALL_BACK_TARGET;
return "Raw";
}
}
@@ -2078,6 +2073,10 @@ function express(port = 3000) {
// dispatch url to route
const dispatch = (request, start = 0) => {
let {method, url, headers, body} = request;
if (/json/i.test(headers['Content-Type'])) {
body = JSON.parse(body);
}
method = method.toUpperCase();
const {path, query} = extractURL(url);
let handler = null;
@@ -2093,6 +2092,7 @@ function express(port = 3000) {
}
}
if (handler) {
$.notify(`DISPATCHING:`, `${method}, ${url}`, path);
// dispatch to next handler
const next = () => {
dispatch(method, url, i);
@@ -2106,7 +2106,7 @@ function express(port = 3000) {
handler.callback(req, res, next).catch(err => {
res.status(500).json({
status: "failed",
message: err
message: "Internal Server Error"
});
});
} else {