mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 13:50:12 +08:00
feat: add remote rule-set mirror option
This commit is contained in:
parent
fb6cdcb3b5
commit
864a1033da
@ -68,4 +68,29 @@ namespace Configs {
|
||||
const std::shared_ptr<BuildConfigStatus> &status);
|
||||
|
||||
void BuildOutbound(const std::shared_ptr<ProxyEntity> &ent, const std::shared_ptr<BuildConfigStatus> &status, QJsonObject& outbound, const QString& tag);
|
||||
|
||||
inline QString get_jsdelivr_link(QString link)
|
||||
{
|
||||
if(dataStore->routing->ruleset_mirror == Mirrors::GITHUB)
|
||||
return link;
|
||||
if(auto url = QUrl(link); url.isValid() && url.host() == "raw.githubusercontent.com")
|
||||
{
|
||||
QStringList list = url.path().split('/');
|
||||
int index = 0;
|
||||
QString result = "https://cdn.jsdelivr.net/gh";
|
||||
foreach(QString item, list)
|
||||
{
|
||||
if(!item.isEmpty())
|
||||
{
|
||||
if(index == 2)
|
||||
result += "@" + item;
|
||||
else
|
||||
result += "/" + item;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return link;
|
||||
}
|
||||
} // namespace Configs
|
||||
|
||||
@ -39,4 +39,13 @@ namespace Configs {
|
||||
SIMPLEDL,
|
||||
};
|
||||
}
|
||||
|
||||
namespace Mirrors
|
||||
{
|
||||
enum Mirrors
|
||||
{
|
||||
GITHUB,
|
||||
JSDELIVR,
|
||||
};
|
||||
}
|
||||
} // namespace Configs
|
||||
|
||||
@ -24,6 +24,7 @@ namespace Configs {
|
||||
QString domain_strategy = "AsIs";
|
||||
QString outbound_domain_strategy = "AsIs";
|
||||
int sniffing_mode = SniffingMode::FOR_ROUTING;
|
||||
int ruleset_mirror = Mirrors::JSDELIVR;
|
||||
|
||||
explicit Routing(int preset = 0);
|
||||
|
||||
|
||||
@ -95,6 +95,30 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="ruleset_mirror_l">
|
||||
<property name="toolTip">
|
||||
<string notr="true"><html><head/><body><p>Change will apply on next launch</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remote Rule-set Mirror</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QComboBox" name="ruleset_mirror">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>GitHub</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>jsDelivr</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@ -753,7 +753,7 @@ namespace Configs {
|
||||
};
|
||||
}
|
||||
else {
|
||||
QString srsUrl = QString::fromStdString(ruleSetMap.at(item.toStdString()));
|
||||
QString srsUrl = get_jsdelivr_link(QString::fromStdString(ruleSetMap.at(item.toStdString())));
|
||||
ruleSetArray += QJsonObject{
|
||||
{"type", "remote"},
|
||||
{"tag", get_rule_set_name(srsUrl)},
|
||||
|
||||
@ -343,6 +343,7 @@ namespace Configs {
|
||||
_add(new configItem("domain_strategy", &this->domain_strategy, itemType::string));
|
||||
_add(new configItem("outbound_domain_strategy", &this->outbound_domain_strategy, itemType::string));
|
||||
_add(new configItem("sniffing_mode", &this->sniffing_mode, itemType::integer));
|
||||
_add(new configItem("ruleset_mirror", &this->ruleset_mirror, itemType::integer));
|
||||
_add(new configItem("use_dns_object", &this->use_dns_object, itemType::boolean));
|
||||
_add(new configItem("dns_object", &this->dns_object, itemType::string));
|
||||
_add(new configItem("dns_final_out", &this->dns_final_out, itemType::string));
|
||||
|
||||
@ -421,7 +421,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
{
|
||||
QString err;
|
||||
for(int retry = 0; retry < 5; retry++) {
|
||||
auto resp = NetworkRequestHelper::HttpGet("https://raw.githubusercontent.com/throneproj/routeprofiles/rule-set/list");
|
||||
auto resp = NetworkRequestHelper::HttpGet(Configs::get_jsdelivr_link("https://raw.githubusercontent.com/throneproj/routeprofiles/rule-set/list"));
|
||||
if (resp.error.isEmpty()) {
|
||||
std::vector<uint8_t> respvec;
|
||||
respvec.assign(resp.data.begin(), resp.data.end());
|
||||
|
||||
@ -104,6 +104,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent, const std::map<std::stri
|
||||
}
|
||||
});
|
||||
ui->sniffing_mode->setCurrentIndex(Configs::dataStore->routing->sniffing_mode);
|
||||
ui->ruleset_mirror->setCurrentIndex(Configs::dataStore->routing->ruleset_mirror);
|
||||
ui->outbound_domain_strategy->setCurrentText(Configs::dataStore->routing->outbound_domain_strategy);
|
||||
ui->domainStrategyCombo->setCurrentText(Configs::dataStore->routing->domain_strategy);
|
||||
ui->use_dns_object->setChecked(Configs::dataStore->routing->use_dns_object);
|
||||
@ -190,6 +191,7 @@ void DialogManageRoutes::accept() {
|
||||
}
|
||||
|
||||
Configs::dataStore->routing->sniffing_mode = ui->sniffing_mode->currentIndex();
|
||||
Configs::dataStore->routing->ruleset_mirror = ui->ruleset_mirror->currentIndex();
|
||||
Configs::dataStore->routing->domain_strategy = ui->domainStrategyCombo->currentText();
|
||||
Configs::dataStore->routing->outbound_domain_strategy = ui->outbound_domain_strategy->currentText();
|
||||
Configs::dataStore->routing->use_dns_object = ui->use_dns_object->isChecked();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user