mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2025-10-28 12:22:37 +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:
@@ -165,7 +165,7 @@ std::string getRuleset(RESPONSE_CALLBACK_ARGS)
|
||||
switch(hash_(vArray[0]))
|
||||
{
|
||||
case "DOMAIN-SUFFIX"_hash:
|
||||
strLine = " - '." + vArray[1] + "'\n - '" + vArray[1] + "'";
|
||||
strLine = " - '+." + vArray[1] + "'";
|
||||
break;
|
||||
case "DOMAIN"_hash:
|
||||
strLine = " - '" + vArray[1] + "'";
|
||||
@@ -1220,7 +1220,10 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
|
||||
{
|
||||
pos = x.find("=");
|
||||
if(pos == x.npos)
|
||||
{
|
||||
req_arg_map[x] = "";
|
||||
continue;
|
||||
}
|
||||
if(x.substr(0, pos) == "token")
|
||||
continue;
|
||||
req_arg_map[x.substr(0, pos)] = x.substr(pos + 1);
|
||||
@@ -2333,8 +2336,9 @@ std::string renderTemplate(RESPONSE_CALLBACK_ARGS)
|
||||
{
|
||||
pos = x.find("=");
|
||||
if(pos == x.npos)
|
||||
continue;
|
||||
req_arg_map[x.substr(0, pos)] = x.substr(pos + 1);
|
||||
req_arg_map[x] = "";
|
||||
else
|
||||
req_arg_map[x.substr(0, pos)] = x.substr(pos + 1);
|
||||
}
|
||||
tpl_args.request_params = req_arg_map;
|
||||
|
||||
|
||||
@@ -29,8 +29,19 @@ int render_template(const std::string &content, const template_args &vars, std::
|
||||
nlohmann::json data;
|
||||
for(auto &x : vars.global_vars)
|
||||
parse_json_pointer(data["global"], x.first, x.second);
|
||||
std::string all_args;
|
||||
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)
|
||||
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>();
|
||||
});
|
||||
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("parseHostname", 1, parseHostname);
|
||||
m_parser_config.include_scope_limit = true;
|
||||
|
||||
@@ -74,7 +74,7 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
|
||||
if(retVal != 201)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
|
||||
if(retVal != 200)
|
||||
{
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user