mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-03 02:02:24 +00:00
Enhancements
Add support for suffix tag in Clash rule provider. Add request._args variable to templates to read all arguments passed from URL. Add startsWith/endsWith as template functions. Add reporting HTTP status code when failed to upload to Gist.
This commit is contained in:
3 files changed
+29
-6
No files matched your search
+7
-3
@@ -165,7 +165,7 @@ std::string getRuleset(RESPONSE_CALLBACK_ARGS)
|
|||||||
switch(hash_(vArray[0]))
|
switch(hash_(vArray[0]))
|
||||||
{
|
{
|
||||||
case "DOMAIN-SUFFIX"_hash:
|
case "DOMAIN-SUFFIX"_hash:
|
||||||
strLine = " - '." + vArray[1] + "'\n - '" + vArray[1] + "'";
|
strLine = " - '+." + vArray[1] + "'";
|
||||||
break;
|
break;
|
||||||
case "DOMAIN"_hash:
|
case "DOMAIN"_hash:
|
||||||
strLine = " - '" + vArray[1] + "'";
|
strLine = " - '" + vArray[1] + "'";
|
||||||
@@ -1220,7 +1220,10 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
|||||||
{
|
{
|
||||||
pos = x.find("=");
|
pos = x.find("=");
|
||||||
if(pos == x.npos)
|
if(pos == x.npos)
|
||||||
|
{
|
||||||
|
req_arg_map[x] = "";
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
if(x.substr(0, pos) == "token")
|
if(x.substr(0, pos) == "token")
|
||||||
continue;
|
continue;
|
||||||
req_arg_map[x.substr(0, pos)] = x.substr(pos + 1);
|
req_arg_map[x.substr(0, pos)] = x.substr(pos + 1);
|
||||||
@@ -2333,8 +2336,9 @@ std::string renderTemplate(RESPONSE_CALLBACK_ARGS)
|
|||||||
{
|
{
|
||||||
pos = x.find("=");
|
pos = x.find("=");
|
||||||
if(pos == x.npos)
|
if(pos == x.npos)
|
||||||
continue;
|
req_arg_map[x] = "";
|
||||||
req_arg_map[x.substr(0, pos)] = x.substr(pos + 1);
|
else
|
||||||
|
req_arg_map[x.substr(0, pos)] = x.substr(pos + 1);
|
||||||
}
|
}
|
||||||
tpl_args.request_params = req_arg_map;
|
tpl_args.request_params = req_arg_map;
|
||||||
|
|
||||||
|
|||||||
+20
-1
@@ -29,8 +29,19 @@ int render_template(const std::string &content, const template_args &vars, std::
|
|||||||
nlohmann::json data;
|
nlohmann::json data;
|
||||||
for(auto &x : vars.global_vars)
|
for(auto &x : vars.global_vars)
|
||||||
parse_json_pointer(data["global"], x.first, x.second);
|
parse_json_pointer(data["global"], x.first, x.second);
|
||||||
|
std::string all_args;
|
||||||
for(auto &x : vars.request_params)
|
for(auto &x : vars.request_params)
|
||||||
parse_json_pointer(data["request"], x.first, x.second);
|
{
|
||||||
|
all_args += x.first;
|
||||||
|
if(x.second.size())
|
||||||
|
{
|
||||||
|
parse_json_pointer(data["request"], x.first, x.second);
|
||||||
|
all_args += "=" + x.second;
|
||||||
|
}
|
||||||
|
all_args += "&";
|
||||||
|
}
|
||||||
|
all_args.erase(all_args.size() - 1);
|
||||||
|
parse_json_pointer(data["request"], "_args", all_args);
|
||||||
for(auto &x : vars.local_vars)
|
for(auto &x : vars.local_vars)
|
||||||
parse_json_pointer(data["local"], x.first, x.second);
|
parse_json_pointer(data["local"], x.first, x.second);
|
||||||
|
|
||||||
@@ -116,6 +127,14 @@ int render_template(const std::string &content, const template_args &vars, std::
|
|||||||
{
|
{
|
||||||
return managed_config_prefix + args.at(0)->get<std::string>();
|
return managed_config_prefix + args.at(0)->get<std::string>();
|
||||||
});
|
});
|
||||||
|
m_callbacks.add_callback("startsWith", 2, [](inja::Arguments &args)
|
||||||
|
{
|
||||||
|
return startsWith(args.at(0)->get<std::string>(), args.at(1)->get<std::string>());
|
||||||
|
});
|
||||||
|
m_callbacks.add_callback("endsWith", 2, [](inja::Arguments &args)
|
||||||
|
{
|
||||||
|
return endsWith(args.at(0)->get<std::string>(), args.at(1)->get<std::string>());
|
||||||
|
});
|
||||||
m_callbacks.add_callback("fetch", 1, template_webGet);
|
m_callbacks.add_callback("fetch", 1, template_webGet);
|
||||||
m_callbacks.add_callback("parseHostname", 1, parseHostname);
|
m_callbacks.add_callback("parseHostname", 1, parseHostname);
|
||||||
m_parser_config.include_scope_limit = true;
|
m_parser_config.include_scope_limit = true;
|
||||||
|
|||||||
+2
-2
@@ -74,7 +74,7 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
|
|||||||
if(retVal != 201)
|
if(retVal != 201)
|
||||||
{
|
{
|
||||||
//std::cerr<<"Create new Gist failed! Return data:\n"<<retData<<"\n";
|
//std::cerr<<"Create new Gist failed! Return data:\n"<<retData<<"\n";
|
||||||
writeLog(0, "Create new Gist failed! Return data:\n" + retData, LOG_LEVEL_ERROR);
|
writeLog(0, "Create new Gist failed!\nReturn code: " + std::to_string(retVal) + "\nReturn data:\n" + retData, LOG_LEVEL_ERROR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
|
|||||||
if(retVal != 200)
|
if(retVal != 200)
|
||||||
{
|
{
|
||||||
//std::cerr<<"Modify gist failed! Return data:\n"<<retData<<"\n";
|
//std::cerr<<"Modify gist failed! Return data:\n"<<retData<<"\n";
|
||||||
writeLog(0, "Modify Gist failed! Return data:\n" + retData, LOG_LEVEL_ERROR);
|
writeLog(0, "Modify Gist failed!\nReturn code: " + std::to_string(retVal) + "\nReturn data:\n" + retData, LOG_LEVEL_ERROR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user