mirror of
https://github.com/MetaCubeX/subconverter.git
synced 2025-11-04 18:19:42 +08:00
Enhancements
Fix HEAD method to /sub not working. Remove unused interfaces.
This commit is contained in:
parent
f9713b43b9
commit
be878e1005
@ -1493,62 +1493,6 @@ void proxyToQuanX(std::vector<Proxy> &nodes, INIReader &ini, std::vector<Ruleset
|
||||
|
||||
if(ext.enable_rule_generator)
|
||||
rulesetToSurge(ini, ruleset_content_array, -1, ext.overwrite_original_rules, ext.managed_config_prefix);
|
||||
|
||||
//process scripts
|
||||
string_multimap scripts;
|
||||
std::string content, title, url;
|
||||
const std::string pattern = "^(.*? url script-.*? )(.*?)$";
|
||||
if(ini.SectionExist("rewrite_local") && !ext.quanx_dev_id.empty())
|
||||
{
|
||||
ini.GetItems("rewrite_local", scripts);
|
||||
ini.EraseSection("rewrite_local");
|
||||
ini.SetCurrentSection("rewrite_local");
|
||||
for(auto &x : scripts)
|
||||
{
|
||||
title = x.first;
|
||||
if(title != "{NONAME}")
|
||||
content = title + "=" + x.second;
|
||||
else
|
||||
content = x.second;
|
||||
|
||||
if(regMatch(content, pattern))
|
||||
{
|
||||
url = regReplace(content, pattern, "$2");
|
||||
if(isLink(url))
|
||||
{
|
||||
url = ext.managed_config_prefix + "/qx-script?id=" + ext.quanx_dev_id + "&url=" + urlSafeBase64Encode(url);
|
||||
content = regReplace(content, pattern, "$1") + url;
|
||||
}
|
||||
}
|
||||
ini.Set("{NONAME}", content);
|
||||
}
|
||||
}
|
||||
eraseElements(scripts);
|
||||
string_size pos;
|
||||
if(ini.SectionExist("rewrite_remote") && !ext.quanx_dev_id.empty())
|
||||
{
|
||||
ini.GetItems("rewrite_remote", scripts);
|
||||
ini.EraseSection("rewrite_remote");
|
||||
ini.SetCurrentSection("rewrite_remote");
|
||||
for(auto &x : scripts)
|
||||
{
|
||||
title = x.first;
|
||||
if(title != "{NONAME}")
|
||||
content = title + "=" + x.second;
|
||||
else
|
||||
content = x.second;
|
||||
|
||||
if(isLink(content))
|
||||
{
|
||||
pos = content.find(",");
|
||||
url = ext.managed_config_prefix + "/qx-rewrite?id=" + ext.quanx_dev_id + "&url=" + urlSafeBase64Encode(content.substr(0, pos));
|
||||
if(pos != content.npos)
|
||||
url += content.substr(pos);
|
||||
content = url;
|
||||
}
|
||||
ini.Set("{NONAME}", content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string proxyToSSD(std::vector<Proxy> &nodes, std::string &group, std::string &userinfo, extra_settings &ext)
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -58,12 +58,12 @@ void safe_set_times(RegexMatchConfigs data)
|
||||
global.timeNodeRules.swap(data);
|
||||
}
|
||||
|
||||
std::shared_future<std::string> fetchFileAsync(const std::string &path, const std::string &proxy, int cache_ttl, bool async)
|
||||
std::shared_future<std::string> fetchFileAsync(const std::string &path, const std::string &proxy, int cache_ttl, bool find_local, bool async)
|
||||
{
|
||||
std::shared_future<std::string> 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<std::string> 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();
|
||||
}
|
||||
|
||||
@ -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<std::string> 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<std::string> 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
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user