From be878e1005bc8b5e9ef59c10014b992d57a34b18 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:47:12 +0800 Subject: [PATCH] Enhancements Fix HEAD method to /sub not working. Remove unused interfaces. --- src/generator/config/subexport.cpp | 56 ------------------------- src/handler/interfaces.cpp | 66 ------------------------------ src/handler/interfaces.h | 2 - src/handler/multithread.cpp | 8 ++-- src/handler/multithread.h | 4 +- src/main.cpp | 6 +-- 6 files changed, 8 insertions(+), 134 deletions(-) diff --git a/src/generator/config/subexport.cpp b/src/generator/config/subexport.cpp index 621945b..c0a0442 100644 --- a/src/generator/config/subexport.cpp +++ b/src/generator/config/subexport.cpp @@ -1493,62 +1493,6 @@ void proxyToQuanX(std::vector &nodes, INIReader &ini, std::vector &nodes, std::string &group, std::string &userinfo, extra_settings &ext) diff --git a/src/handler/interfaces.cpp b/src/handler/interfaces.cpp index c299421..8da0557 100644 --- a/src/handler/interfaces.cpp +++ b/src/handler/interfaces.cpp @@ -1245,72 +1245,6 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS) return subconverter(request, response); } -std::string getScript(RESPONSE_CALLBACK_ARGS) -{ - std::string &argument = request.argument; - - std::string url = urlSafeBase64Decode(getUrlArg(argument, "url")), dev_id = getUrlArg(argument, "id"); - std::string output_content; - - std::string proxy = parseProxy(global.proxyConfig); - - output_content = fetchFile(url, proxy, global.cacheConfig); - - if(!dev_id.size()) - dev_id = global.quanXDevID; - - const std::string pattern = "(\\/\\*[\\s\\S]*?)^(.*?@supported )(.*?\\s?)$([\\s\\S]*\\*\\/\\s?"; - if(dev_id.size()) - { - if(regFind(output_content, pattern)) - output_content = regReplace(output_content, pattern, "$1$2" + dev_id + "$4"); - else - output_content = "/**\n * @supported " + dev_id + "\n * THIS COMMENT IS GENERATED BY SUBCONVERTER\n */\n\n" + output_content; - } - return output_content; -} - -std::string getRewriteRemote(RESPONSE_CALLBACK_ARGS) -{ - std::string &argument = request.argument; - - std::string url = urlSafeBase64Decode(getUrlArg(argument, "url")), dev_id = getUrlArg(argument, "id"); - std::string output_content; - - std::string proxy = parseProxy(global.proxyConfig); - - output_content = fetchFile(url, proxy, global.cacheConfig); - - if(!dev_id.size()) - dev_id = global.quanXDevID; - - if(dev_id.size()) - { - std::stringstream ss; - std::string strLine; - const std::string pattern = "^(.*? url script-.*? )(.*?)$"; - string_size lineSize; - char delimiter = getLineBreak(output_content); - - ss << output_content; - output_content.clear(); - while(getline(ss, strLine, delimiter)) - { - lineSize = strLine.size(); - if(lineSize && strLine[lineSize - 1] == '\r') //remove line break - strLine.erase(--lineSize); - - if(!strLine.empty() && regMatch(strLine, pattern)) - { - url = global.managedConfigPrefix + "/qx-script?id=" + dev_id + "&url=" + urlSafeBase64Encode(regReplace(strLine, pattern, "$2")); - strLine = regReplace(strLine, pattern, "$1") + url; - } - output_content.append(strLine + "\n"); - } - } - return output_content; -} - /* std::string jinja2_webGet(const std::string &url) { diff --git a/src/handler/interfaces.h b/src/handler/interfaces.h index bba8f96..08102fb 100644 --- a/src/handler/interfaces.h +++ b/src/handler/interfaces.h @@ -17,10 +17,8 @@ int simpleGenerator(); std::string convertRuleset(const std::string &content, int type); std::string getConvertedRuleset(RESPONSE_CALLBACK_ARGS); -std::string getScript(RESPONSE_CALLBACK_ARGS); std::string getProfile(RESPONSE_CALLBACK_ARGS); std::string getRuleset(RESPONSE_CALLBACK_ARGS); -std::string getRewriteRemote(RESPONSE_CALLBACK_ARGS); std::string subconverter(RESPONSE_CALLBACK_ARGS); std::string simpleToClashR(RESPONSE_CALLBACK_ARGS); diff --git a/src/handler/multithread.cpp b/src/handler/multithread.cpp index 8f10d52..e5610a3 100644 --- a/src/handler/multithread.cpp +++ b/src/handler/multithread.cpp @@ -58,12 +58,12 @@ void safe_set_times(RegexMatchConfigs data) global.timeNodeRules.swap(data); } -std::shared_future fetchFileAsync(const std::string &path, const std::string &proxy, int cache_ttl, bool async) +std::shared_future fetchFileAsync(const std::string &path, const std::string &proxy, int cache_ttl, bool find_local, bool async) { std::shared_future retVal; /*if(vfs::vfs_exist(path)) retVal = std::async(std::launch::async, [path](){return vfs::vfs_get(path);}); - else */if(fileExist(path, true)) + else */if(find_local && fileExist(path, true)) retVal = std::async(std::launch::async, [path](){return fileGet(path, true);}); else if(isLink(path)) retVal = std::async(std::launch::async, [path, proxy, cache_ttl](){return webGet(path, proxy, cache_ttl);}); @@ -74,7 +74,7 @@ std::shared_future fetchFileAsync(const std::string &path, const st return retVal; } -std::string fetchFile(const std::string &path, const std::string &proxy, int cache_ttl) +std::string fetchFile(const std::string &path, const std::string &proxy, int cache_ttl, bool find_local) { - return fetchFileAsync(path, proxy, cache_ttl, false).get(); + return fetchFileAsync(path, proxy, cache_ttl, find_local, false).get(); } diff --git a/src/handler/multithread.h b/src/handler/multithread.h index 394b6fe..1e6e31c 100644 --- a/src/handler/multithread.h +++ b/src/handler/multithread.h @@ -22,7 +22,7 @@ void safe_set_emojis(RegexMatchConfigs data); void safe_set_renames(RegexMatchConfigs data); void safe_set_streams(RegexMatchConfigs data); void safe_set_times(RegexMatchConfigs data); -std::shared_future fetchFileAsync(const std::string &path, const std::string &proxy, int cache_ttl, bool async = false); -std::string fetchFile(const std::string &path, const std::string &proxy, int cache_ttl); +std::shared_future fetchFileAsync(const std::string &path, const std::string &proxy, int cache_ttl, bool find_local = true, bool async = false); +std::string fetchFile(const std::string &path, const std::string &proxy, int cache_ttl, bool find_local = true); #endif // MULTITHREAD_H_INCLUDED diff --git a/src/main.cpp b/src/main.cpp index d6f2a81..2dfe4c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -262,6 +262,8 @@ int main(int argc, char *argv[]) webServer.append_response("GET", "/sub", "text/plain;charset=utf-8", subconverter); + webServer.append_response("HEAD", "/sub", "text/plain", subconverter); + webServer.append_response("GET", "/sub2clashr", "text/plain;charset=utf-8", simpleToClashR); webServer.append_response("GET", "/surge2clash", "text/plain;charset=utf-8", surgeConfToClash); @@ -270,10 +272,6 @@ int main(int argc, char *argv[]) webServer.append_response("GET", "/getprofile", "text/plain;charset=utf-8", getProfile); - webServer.append_response("GET", "/qx-script", "text/plain;charset=utf-8", getScript); - - webServer.append_response("GET", "/qx-rewrite", "text/plain;charset=utf-8", getRewriteRemote); - webServer.append_response("GET", "/render", "text/plain;charset=utf-8", renderTemplate); webServer.append_response("GET", "/convert", "text/plain;charset=utf-8", getConvertedRuleset);