From eb3023b863083a0830ff4e1b4a5ce3a71f75e7bc Mon Sep 17 00:00:00 2001 From: Anya Lin Date: Thu, 26 Dec 2024 10:30:43 +0800 Subject: [PATCH] feat: add `inline` providers type --- .../luci-static/resources/view/fchomo/node.js | 18 ++++++++++++++++++ .../root/etc/fchomo/scripts/generate_client.uc | 6 +++++- luci-app-fchomo/root/etc/init.d/fchomo | 4 +++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/node.js b/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/node.js index 48bbb6b..b74c438 100644 --- a/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/node.js +++ b/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/node.js @@ -837,6 +837,7 @@ return view.extend({ so = ss.taboption('field_general', form.ListValue, 'type', _('Type')); so.value('file', _('Local')); so.value('http', _('Remote')); + so.value('inline', _('Inline')); so.default = 'http'; so = ss.option(form.DummyValue, '_value', _('Value')); @@ -848,6 +849,8 @@ return view.extend({ return uci.get(data[0], section_id, '.name'); case 'http': return uci.get(data[0], section_id, 'url'); + case 'inline': + return uci.get(data[0], section_id, '.name'); default: return null; } @@ -875,6 +878,21 @@ return view.extend({ so.depends('type', 'file'); so.modalonly = true; + so = ss.taboption('field_general', form.TextValue, 'payload', 'payload:', + _('Please type %s.') + .format('https://wiki.metacubex.one/config/proxy-providers/content/', _('Payload'))); + so.renderWidget = function(/* ... */) { + var frameEl = form.TextValue.prototype.renderWidget.apply(this, arguments); + + frameEl.querySelector('textarea').style.fontFamily = hm.monospacefonts.join(','); + + return frameEl; + } + so.placeholder = '- name: "ss1"\n type: ss\n server: server\n port: 443\n cipher: chacha20-ietf-poly1305\n password: "password"\n# ' + _('Content will not be verified, Please make sure you enter it correctly.'); + so.rmempty = false; + so.depends('type', 'inline'); + so.modalonly = true; + so = ss.taboption('field_general', form.Value, 'url', _('Provider URL')); so.validate = L.bind(hm.validateUrl, so); so.rmempty = false; diff --git a/luci-app-fchomo/root/etc/fchomo/scripts/generate_client.uc b/luci-app-fchomo/root/etc/fchomo/scripts/generate_client.uc index 1652ace..c088be9 100755 --- a/luci-app-fchomo/root/etc/fchomo/scripts/generate_client.uc +++ b/luci-app-fchomo/root/etc/fchomo/scripts/generate_client.uc @@ -657,7 +657,11 @@ uci.foreach(uciconf, uciprov, (cfg) => { /* General fields */ config["proxy-providers"][cfg['.name']] = { type: cfg.type, - path: HM_DIR + '/provider/' + cfg['.name'], + ...(cfg.payload ? { + payload: trim(cfg.payload) + } : { + path: HM_DIR + '/provider/' + cfg['.name'] + }), url: cfg.url, "size-limit": bytesizeToByte(cfg.size_limit) || null, interval: (cfg.type === 'http') ? durationToSecond(cfg.interval) || 86400 : null, diff --git a/luci-app-fchomo/root/etc/init.d/fchomo b/luci-app-fchomo/root/etc/init.d/fchomo index 57bcb7c..e591c8e 100755 --- a/luci-app-fchomo/root/etc/init.d/fchomo +++ b/luci-app-fchomo/root/etc/init.d/fchomo @@ -117,7 +117,9 @@ start_service() { | .sniffer["skip-domain"][] style="double" | with(.dns["nameserver-policy"] | keys; .. style="double") | .dns["fallback-filter"].domain[] style="double" - | with(.["rule-providers"][] | select(.payload); .payload style="literal")' | sed -E 's,^(\s*payload:) \|-,\1,' \ + | with(.["proxy-providers"][] | select(.payload); .payload style="literal") + | with(.["rule-providers"][] | select(.payload); .payload style="literal")' \ + | sed -E 's,^(\s*payload:) \|-,\1,' \ > "$RUN_DIR/mihomo-c.yaml" yq eval-all -i '. as $item ireduce ({}; . * $item )' "$RUN_DIR/mihomo-c.yaml" "$TEMPS_DIR/"*.yaml