💐 Sync 2026-10-06 12:33:44

This commit is contained in:
github-actions[bot] committed 2026-10-06 12:33:44 +08:00
1 parent 8be03ce939
commit 7fe69dbb3a
246 files changed
+50330 -3414

No files matched your search

@@ -12,13 +12,22 @@ module("luci.controller.admin.substore", package.seeall)
local i18n = require("luci.i18n")
local function _(s) return i18n.translate(s) end
-- 后端(substore.* 模块)返回的是**语言中立的英文 msgid** —— 它们不能
-- require("luci.i18n"),因为 substore-cron.sh 会在没有 LuCI 环境的独立 lua
-- 进程里跑 core.sync。翻译在这里做:控制器是 ?err= 这条回显链路的边界。
--
-- msg.translate 对**已经翻译过**的串是幂等的(见 msg.lua),所以下面那些
-- `err or _("…")` 的 fallback 传进来也不会被二次翻译。
local msg = require("substore.msg")
local function tmsg(s) return msg.translate(s, _) end
-- 返回列表页。err 非空时把错误带到列表页显示(§18:失败必须让用户看见,
-- 不能「失败了却看起来像成功」)。沿用 LuCI 既有的 query + 模板渲染,不引入新 framework。
local function back_to_list(err)
local http = require("luci.http")
local url = luci.dispatcher.build_url("admin", "services", "substore", "list")
if err ~= nil and tostring(err) ~= "" then
url = url .. "?err=" .. luci.util.urlencode(tostring(err))
url = url .. "?err=" .. luci.util.urlencode(tmsg(err))
end
http.redirect(url)
end
@@ -348,7 +357,7 @@ local function back_to_nodes(http, err)
if v and v ~= "" then qs = qs .. "&" .. k .. "=" .. luci.util.urlencode(v) end
end
if err ~= nil and tostring(err) ~= "" then
qs = qs .. "&err=" .. luci.util.urlencode(tostring(err))
qs = qs .. "&err=" .. luci.util.urlencode(tmsg(err))
end
http.redirect(luci.dispatcher.build_url("admin", "services", "substore", "nodes") .. qs)
end
@@ -518,7 +527,10 @@ function action_update()
core.save_meta(id, { error = tostring(res), last_update = os.time() })
elseif not res then
-- 正常返回但失败:第三个返回值是错误信息
core.save_meta(id, { error = tostring(err or _("Update failed")), last_update = os.time() })
-- 存进 meta.error 的必须是**语言中立的 msgid**(不是 _() 的结果):
-- 它会一直留在列表文件里,而读它的页面未必是同一个语言环境。
-- 翻译交给读的那一端(视图里的 msg.translate)。
core.save_meta(id, { error = tostring(err or "Update failed"), last_update = os.time() })
end
end
back_to_list(post_fail_msg)
@@ -2,6 +2,10 @@
<%
local http = require("luci.http")
local core = require("substore.core")
-- meta.error / human_duration 返回的都是语言中立的 msgid(可能是组合消息),
-- 翻译在视图侧做 —— 后端模块不能 require("luci.i18n"),见 msg.lua 的文件头。
local msg = require("substore.msg")
local function tmsg(s) return msg.translate(s, luci.i18n.translate) end
local id = http.formvalue("id") or ""
local it = id ~= "" and core.get(id) or nil
local is_edit = it ~= nil
@@ -36,7 +40,7 @@
traffic_str = util.human_bytes(rem)
end
if it.expire then
time_str = util.human_duration((tonumber(it.expire) or 0) - os.time())
time_str = tmsg(util.human_duration((tonumber(it.expire) or 0) - os.time()))
end
end
%>
@@ -149,7 +153,7 @@
<% if traffic_str then %> | <%:Remaining traffic:%> <%=traffic_str%><% end %>
<% if time_str then %> | <%:Remaining time:%> <%=time_str%><% end %>
| <%:Last updated:%> <%=os.date("%Y-%m-%d %H:%M", it.last_update)%>
<% if it.error and it.error ~= "" then %> | <span style="color:#cc0000"><%=luci.util.pcdata(it.error)%></span><% end %>
<% if it.error and it.error ~= "" then %> | <span style="color:#cc0000"><%=luci.util.pcdata(tmsg(it.error))%></span><% end %>
</span>
</div>
<% end %>
@@ -2,6 +2,10 @@
<%
local http = require("luci.http")
local core = require("substore.core")
-- meta.error 是语言中立的 msgid(可能是组合消息),翻译在视图侧做 ——
-- 后端模块不能 require("luci.i18n"),见 msg.lua 的文件头。
local msg = require("substore.msg")
local function tmsg(s) return msg.translate(s, luci.i18n.translate) end
local id = http.formvalue("id") or ""
local it = id ~= "" and core.get(id) or nil
local is_edit = it ~= nil
@@ -113,7 +117,7 @@
<span style="color:#808080">
<%:Nodes:%> <%=it.node_count or 0%>
| <%:Last updated:%> <%=os.date("%Y-%m-%d %H:%M", it.last_update)%>
<% if it.error and it.error ~= "" then %> | <span style="color:#cc0000"><%=luci.util.pcdata(it.error)%></span><% end %>
<% if it.error and it.error ~= "" then %> | <span style="color:#cc0000"><%=luci.util.pcdata(tmsg(it.error))%></span><% end %>
</span>
</div>
<% end %>
@@ -4,6 +4,10 @@
local core = require("substore.core")
local output = require("substore.output")
local util = require("substore.util")
-- output.generate 的 err 是语言中立的 msgid(可能是组合消息),翻译在视图侧做 ——
-- 后端模块不能 require("luci.i18n"),见 msg.lua 的文件头。
local msg = require("substore.msg")
local function tmsg(s) return msg.translate(s, luci.i18n.translate) end
local ctx = luci.dispatcher.context or {}
local q = ctx.query or {}
local id = http.formvalue("id") or q.id or ""
@@ -41,7 +45,7 @@
</form>
<% if err then %>
<div style="color:#cc0000"><%=luci.util.pcdata(err)%></div>
<div style="color:#cc0000"><%=luci.util.pcdata(tmsg(err))%></div>
<% else %>
<textarea id="out_text" readonly style="width:100%;height:300px;font-family:monospace"><%=luci.util.pcdata(out)%></textarea>
<div style="margin-top:0.5em">
@@ -4,6 +4,7 @@
<%
-- §18:控制器把失败原因放在 ?err= 上带回来,这里渲染成可见的提示。
-- pcdata 转义:err 可能包含用户提交的内容,不能直接当 HTML 输出。
-- 控制器已经翻译过 flash_err(它是 ?err= 这条链路的边界),这里不再翻。
local flash_err = require("luci.http").formvalue("err")
if flash_err and flash_err ~= "" then
%>
@@ -48,6 +49,10 @@
<%
local core = require("substore.core")
local output = require("substore.output")
-- meta.error 是**语言中立的 msgid**(可能还是 msg.compose 拼出来的组合消息),
-- 翻译在这里做 —— 后端模块不能 require("luci.i18n"),见 msg.lua 的文件头。
local msg = require("substore.msg")
local function tmsg(s) return msg.translate(s, luci.i18n.translate) end
local http_env = require("luci.http")
local items = core.list()
local base = luci.dispatcher.build_url("substore", "download")
@@ -63,7 +68,7 @@
local status_text = luci.i18n.translate("Pending")
if it.error and it.error ~= "" then
status_color = "#cc0000"
status_text = it.error
status_text = tmsg(it.error)
elseif it.node_count and it.node_count > 0 then
status_color = "#006600"
status_text = luci.i18n.translate("OK")