Skip to content

Commit

Permalink
stype(view): simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
  • Loading branch information
1715173329 committed Mar 11, 2025
1 parent ef5e07a commit 0f695f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions htdocs/luci-static/resources/view/homeproxy/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ return view.extend({
if (!value)
return _('Expecting: %s').format(_('non-empty value'));

let ipv6_support = this.map.lookupOption('ipv6_support', section_id)[0].formvalue(section_id);
let ipv6_support = this.section.formvalue(section_id, 'ipv6_support');
try {
let url = new URL(value.replace(/^.*:\/\//, 'http://'));
if (stubValidator.apply('hostname', url.hostname))
Expand Down Expand Up @@ -443,7 +443,7 @@ return view.extend({
}
so.validate = function(section_id, value) {
if (section_id && value) {
let node = this.map.lookupOption('node', section_id)[0].formvalue(section_id);
let node = this.section.formvalue(section_id, 'node');

let conflict = false;
uci.sections(data[0], 'routing_node', (res) => {
Expand Down Expand Up @@ -497,7 +497,7 @@ return view.extend({
so.placeholder = '180';
so.validate = function(section_id, value) {
if (section_id && value) {
let idle_timeout = this.map.lookupOption('urltest_idle_timeout', section_id)[0].formvalue(section_id) || '1800';
let idle_timeout = this.section.formvalue(section_id, 'idle_timeout') || '1800';
if (parseInt(value) > parseInt(idle_timeout))
return _('Test interval must be less or equal than idle timeout.');
}
Expand Down Expand Up @@ -1312,8 +1312,7 @@ return view.extend({
return callWriteDomainList('proxy_list', value);
}
so.remove = function(/* ... */) {
let routing_mode = this.map.lookupOption('routing_mode', 'config')[0].formvalue('config');

let routing_mode = this.section.formvalue('config', 'routing_mode');
if (routing_mode !== 'custom')
return callWriteDomainList('proxy_list', '');
return true;
Expand Down Expand Up @@ -1345,8 +1344,7 @@ return view.extend({
return callWriteDomainList('direct_list', value);
}
so.remove = function(/* ... */) {
let routing_mode = this.map.lookupOption('routing_mode', 'config')[0].formvalue('config');

let routing_mode = this.section.formvalue('config', 'routing_mode');
if (routing_mode !== 'custom')
return callWriteDomainList('direct_list', '');
return true;
Expand Down
4 changes: 2 additions & 2 deletions htdocs/luci-static/resources/view/homeproxy/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,12 @@ function renderNodeSettings(section, data, features, main_node, routing_mode) {
o.depends({'type': 'socks', 'socks_version': '5'});
o.validate = function(section_id, value) {
if (section_id) {
let type = this.map.lookupOption('type', section_id)[0].formvalue(section_id);
let type = this.section.formvalue(section_id, 'type');
let required_type = [ 'shadowsocks', 'shadowtls', 'trojan' ];

if (required_type.includes(type)) {
if (type === 'shadowsocks') {
let encmode = this.map.lookupOption('shadowsocks_encrypt_method', section_id)[0].formvalue(section_id);
let encmode = this.section.formvalue(section_id, 'shadowsocks_encrypt_method');
if (encmode === 'none')
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions htdocs/luci-static/resources/view/homeproxy/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ return view.extend({
}
o.validate = function(section_id, value) {
if (section_id) {
let type = this.map.lookupOption('type', section_id)[0].formvalue(section_id);
let type = this.section.formvalue(section_id, 'type');
let required_type = [ 'http', 'mixed', 'naive', 'socks', 'shadowsocks' ];

if (required_type.includes(type)) {
if (type === 'shadowsocks') {
let encmode = this.map.lookupOption('shadowsocks_encrypt_method', section_id)[0].formvalue(section_id);
let encmode = this.section.formvalue(section_id, 'shadowsocks_encrypt_method');
if (encmode === 'none')
return true;
else if (encmode === '2022-blake3-aes-128-gcm')
Expand Down

0 comments on commit 0f695f4

Please sign in to comment.