Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sort_script problem #281

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,6 @@ void readYAMLConf(YAML::Node &node)
if(section["include_remarks"].IsSequence())
section["include_remarks"] >> gIncludeRemarks;
gFilterScript = safe_as<bool>(section["enable_filter"]) ? safe_as<std::string>(section["filter_script"]) : "";
if(startsWith(gFilterScript, "path:"))
gFilterScript = fileGet(gFilterScript.substr(5), false);
section["base_path"] >> gBasePath;
section["clash_rule_base"] >> gClashBase;
section["surge_rule_base"] >> gSurgeBase;
Expand Down Expand Up @@ -1362,12 +1360,12 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
std::string argIncludeRemark = UrlDecode(getUrlArg(argument, "include")), argExcludeRemark = UrlDecode(getUrlArg(argument, "exclude"));
std::string argCustomGroups = urlsafe_base64_decode(getUrlArg(argument, "groups")), argCustomRulesets = urlsafe_base64_decode(getUrlArg(argument, "ruleset")), argExternalConfig = UrlDecode(getUrlArg(argument, "config"));
std::string argDeviceID = getUrlArg(argument, "dev_id"), argFilename = getUrlArg(argument, "filename"), argUpdateInterval = getUrlArg(argument, "interval"), argUpdateStrict = getUrlArg(argument, "strict");
std::string argRenames = UrlDecode(getUrlArg(argument, "rename")), argFilterScript = UrlDecode(getUrlArg(argument, "filter_script"));
std::string argRenames = UrlDecode(getUrlArg(argument, "rename")), argFilterScript = UrlDecode(getUrlArg(argument, "filter_script")), argSortScript = UrlDecode(getUrlArg(argument, "sort_script"));

/// switches with default value
tribool argUpload = getUrlArg(argument, "upload"), argEmoji = getUrlArg(argument, "emoji"), argAddEmoji = getUrlArg(argument, "add_emoji"), argRemoveEmoji = getUrlArg(argument, "remove_emoji");
tribool argAppendType = getUrlArg(argument, "append_type"), argTFO = getUrlArg(argument, "tfo"), argUDP = getUrlArg(argument, "udp"), argGenNodeList = getUrlArg(argument, "list");
tribool argSort = getUrlArg(argument, "sort"), argUseSortScript = getUrlArg(argument, "sort_script");
tribool argSort = getUrlArg(argument, "sort");
tribool argGenClashScript = getUrlArg(argument, "script"), argEnableInsert = getUrlArg(argument, "insert");
tribool argSkipCertVerify = getUrlArg(argument, "scv"), argFilterDeprecated = getUrlArg(argument, "fdn"), argExpandRulesets = getUrlArg(argument, "expand"), argAppendUserinfo = getUrlArg(argument, "append_info");
tribool argPrependInsert = getUrlArg(argument, "prepend"), argGenClassicalRuleProvider = getUrlArg(argument, "classic"), argTLS13 = getUrlArg(argument, "tls13");
Expand Down Expand Up @@ -1435,9 +1433,13 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
ext.tls13.parse(argTLS13).parse(gTLS13);

ext.sort_flag = argSort.get(gEnableSort);
argUseSortScript.define(gSortScript.size() != 0);
if(ext.sort_flag && argUseSortScript)
ext.sort_script = gSortScript;
std::string sortScript = gSortScript;
if(authorized && !argSortScript.empty())
sortScript = argSortScript;
if(startsWith(sortScript, "path:"))
sortScript = fileGet(sortScript.substr(5), false);
if(ext.sort_flag)
ext.sort_script = sortScript;
ext.filter_deprecated = argFilterDeprecated.get(gFilterDeprecated);
ext.clash_new_field_name = argClashNewField.get(gClashUseNewField);
ext.clash_script = argGenClashScript.get();
Expand Down
4 changes: 2 additions & 2 deletions src/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ void preprocessNodes(std::vector<nodeInfo> &nodes, const extra_settings &ext)
duk_pcall(ctx, 2);
return duktape_get_res_int(ctx);
};
std::sort(nodes.begin(), nodes.end(), comparer);
std::stable_sort(nodes.begin(), nodes.end(), comparer);
failed = false;
}
else
Expand All @@ -1114,7 +1114,7 @@ void preprocessNodes(std::vector<nodeInfo> &nodes, const extra_settings &ext)
//failed
}
}
if(failed) std::sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
if(failed) std::stable_sort(nodes.begin(), nodes.end(), [](const nodeInfo &a, const nodeInfo &b)
{
return a.remarks < b.remarks;
});
Expand Down