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

feat: Add host proxy pattern for global proxy configuration #752

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/langs/it_IT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ Cannot initialize WebSocket!=Impossibile inizializzare WebSocket!
Cannot connect to aria2!=Impossibile connettersi a aria2!
Access Denied!=Accesso negato!
You cannot use AriaNg because this browser does not meet the minimum requirements for data storage.=Non puoi utilizzare AriaNg perché questo browser non soddisfa i requisiti minimi di archiviazione dati.

hostProxyPatternName=Modello proxy host
hostProxyPatternDescription=Specificare il modello regex host per il proxy per riga. Se l'host corrisponde al modello, verrà utilizzato il proxy. Esempio: .*\.example\.com|proxy.com:8080 .*\.example\.org|proxy.org:8080
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a blank line before the header of a new group

[error]
unknown=Errore sconosciuto.
operation.timeout=Operazione scaduta.
Expand Down
3 changes: 2 additions & 1 deletion src/langs/zh_Hans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ Cannot initialize WebSocket!=无法初始化 WebSocket!
Cannot connect to aria2!=无法连接到 aria2!
Access Denied!=拒绝访问!
You cannot use AriaNg because this browser does not meet the minimum requirements for data storage.=您无法使用 AriaNg, 因为这个浏览器不满足数据存储的最低要求.

hostProxyPatternName=主机代理模式
hostProxyPatternDescription=为每行代理指定主机正则表达式模式。如果主机与该模式匹配,则将使用代理。示例:.*\.example\.com|proxy.com:8080 .*\.example\.org|proxy.org:8080
[error]
unknown=未知错误.
operation.timeout=操作超时.
Expand Down
3 changes: 2 additions & 1 deletion src/langs/zh_Hant.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ Cannot initialize WebSocket!=無法初始化 WebSocket!
Cannot connect to aria2!=無法連線到 aria2!
Access Denied!=拒絕訪問!
You cannot use AriaNg because this browser does not meet the minimum requirements for data storage.=您無法使用 AriaNg, 因為此瀏覽器不滿足資料儲存的最低要求.

hostProxyPatternName=主機代理模式
hostProxyPatternDescription=為每行代理指定主機正則表達式模式。如果主機與該模式匹配,則將使用代理。示例:.*\.example\.com|proxy.com:8080 .*\.example\.org|proxy.org:8080
[error]
unknown=不詳錯誤.
operation.timeout=操作超時.
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/config/defaultLanguage.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@
'Cannot connect to aria2!': 'Cannot connect to aria2!',
'Access Denied!': 'Access Denied!',
'You cannot use AriaNg because this browser does not meet the minimum requirements for data storage.': 'You cannot use AriaNg because this browser does not meet the minimum requirements for data storage.',
'hostProxyPatternName': 'Host Proxy Pattern',
'hostProxyPatternDescription': 'Specify host regex pattern for proxy per line. If the host matches the pattern, the proxy will be used. Example: .*\\.example\\.com|proxy.com:8080 .*\\.example\\.org|proxy.org:8080',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you just write one example since you already mentioned one item per line

'error': {
'unknown': 'Unknown error occurred.',
'operation.timeout': 'Operation timed out.',
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/controllers/settings-ariang.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@
$rootScope.setTheme(value);
};

$scope.setHostProxyPattern = function (value) {
ariaNgSettingService.setHostProxyPattern(value);
$rootScope.setProxyHostPattern(value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to call $rootScope.setProxyHostPattern(value), because there is no function called setProxyHostPattern in root scope.

};

$scope.setDebugMode = function (value) {
ariaNgSettingService.setDebugMode(value);
};
Expand Down
15 changes: 15 additions & 0 deletions src/scripts/services/aria2RpcService.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@
addUri: function (context, returnContextOnly) {
var urls = context.task ? context.task.urls : null;
var options = buildRequestOptions(context.task ? context.task.options : {}, context);
var proxyRegex= ariaNgSettingService.getHostProxyPattern().trim();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format your code (a space should be appended to the left side of the equal symbol)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to check ariaNgSettingService.getHostProxyPattern() is defined and is not null. I think you can just use the following code to replace Line 321-Line 322

if (ariaNgSettingService.getHostProxyPattern() && ariaNgSettingService.getHostProxyPattern().trim()) {
  // ...
}

if (proxyRegex) {
var patterns = proxyRegex.split('\n');
for (var i = 0; i < patterns.length; i++) {
patterns[i] = patterns[i].trim()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a semicolon at the end of the line

if (patterns[i]) {
var lastIndex = patterns[i].lastIndexOf('|');
if (lastIndex === -1) continue
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not write the if condition and the actual execution code on the same line. You can just write like the following code

if (lastIndex < 0) {
    continue;
}

var hostRegex = patterns[i].slice(0, lastIndex).trim();
var httpProxy = patterns[i].slice(lastIndex + 1).trim();
if (urls[0].match(hostRegex)) options['all-proxy'] = httpProxy
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if the all-proxy is not set? Should the priority of the parameter in tasks be higher than the priority of the global one?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The urls may be null in Line 319, please check if it is null first.


}
}
}

return invoke(buildRequestContext('addUri', context, urls, options), !!returnContextOnly);
},
Expand Down
6 changes: 6 additions & 0 deletions src/scripts/services/ariaNgSettingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@
setTitle: function (value) {
setOption('title', value);
},
getHostProxyPattern: function () {
return getOption('hostProxyPattern');
},
setHostProxyPattern: function (value) {
setOption('hostProxyPattern', value);
},
getBrowserNotification: function () {
return getOption('browserNotification');
},
Expand Down
12 changes: 12 additions & 0 deletions src/views/settings-ariang.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
<em>[<span translate>Preview</span>] <span ng-bind="context.titlePreview"></span></em>
</div>
</div>
<div class="row">
<div class="setting-key setting-key-without-desc col-sm-4">
<span>{{ 'hostProxyPatternName' | translate }}</span>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the actual displayed content in English instead of placeholders to avoid unfriendly content that may be displayed when the language resources are not loaded.

<i class="icon-primary fa fa-question-circle" data-toggle="popover"
data-trigger="hover" data-placement="auto right" data-container="body" data-html="true"
data-content="{{ 'hostProxyPatternDescription' | translate }}"></i>
</div>
<div class="setting-value col-sm-8">
<textarea class="form-control" rows="4" ng-model="context.settings.hostProxyPattern"
ng-change="setHostProxyPattern(context.settings.hostProxyPattern)" ng-keyup="inputKeyUp($event, true)"></textarea>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AriaNgSettingsController does not have a function called "inputKeyUp", you can remove the ng-keyup attribute.

</div>
</div>
<div class="row" ng-if="isSupportNotification()">
<div class="setting-key setting-key-without-desc col-sm-4">
<span translate>Enable Browser Notification</span>
Expand Down