<%+header%>

<%:Subscriptions%>

<% -- §18:控制器把失败原因放在 ?err= 上带回来,这里渲染成可见的提示。 -- pcdata 转义:err 可能包含用户提交的内容,不能直接当 HTML 输出。 -- 控制器已经翻译过 flash_err(它是 ?err= 这条链路的边界),这里不再翻。 local flash_err = require("luci.http").formvalue("err") if flash_err and flash_err ~= "" then %>
<%:Operation failed%>: <%=luci.util.pcdata(flash_err)%>
<% end %>
<%:Add subscription link%> <%:Add local subscription%> <%:Add combination%>
<% 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") local scheme = (http_env.getenv("HTTPS") and http_env.getenv("HTTPS") ~= "off") and "https" or "http" local host = http_env.getenv("HTTP_HOST") or (http_env.getenv("SERVER_NAME") and http_env.getenv("SERVER_NAME") .. ":" .. (http_env.getenv("SERVER_PORT") or "80")) or "127.0.0.1" local prefix = scheme .. "://" .. host .. base local name_by_id = {} for _, it2 in ipairs(items) do name_by_id[it2.id] = it2.name end for _, it in ipairs(items) do local status_color = "#808080" local status_text = luci.i18n.translate("Pending") if it.error and it.error ~= "" then status_color = "#cc0000" status_text = tmsg(it.error) elseif it.node_count and it.node_count > 0 then status_color = "#006600" status_text = luci.i18n.translate("OK") end local sub_token = core.ensure_token(it.id) -- ensure_token 在「token 写不进列表文件」时返回 nil:此时链接必然无效, -- 用空 token 拼出来,让下载端报「无效的订阅 token」, -- 而不是在模板里对 nil 做字符串拼接直接 500。 local sub_link_base = prefix .. "?token=" .. (sub_token or "") .. "&target=" -- 还没解析出节点时禁用格式下拉:刚添加还没点「更新」、更新失败、 -- 或解析结果为空的订阅,转出来的内容必然是空的。让用户能选, -- 等于引导他生成一个无效的订阅链接(选了也只是得到一个空结果)。 local fmt_disabled = (tonumber(it.node_count) or 0) <= 0 %> <% end if #items == 0 then %> <% end %>
<%:Name%> <%:URL%> <%:Nodes%> <%:Updated%> <%:Status%> <%:Subscription link%> <%:Actions%>
<%=luci.util.pcdata(it.name or "")%> <% if it.cron_enable == true or it.cron_enable == "1" then %>
<%:Schedule:%> <%=luci.util.pcdata(it.cron_time or "")%>
<% end %>
<% if it.combo then local names = {} if type(it.sources) == "table" then for _, sid in ipairs(it.sources) do names[#names + 1] = name_by_id[sid] or sid end end %>[<%:Combination%>] <%=luci.util.pcdata(table.concat(names, " + "))%><% elseif it["local"] then %>[<%:Local%>]<% else %><%=luci.util.pcdata(it.url or "")%><% end %> <%=it.node_count or 0%> <%=it.last_update and os.date("%Y-%m-%d %H:%M", it.last_update) or "-"%> <%=luci.util.pcdata(status_text or "")%>
<% if fmt_disabled then %><%:Update and parse nodes before choosing a format%><% else %><%:Pick a format to generate the subscription link; you can switch formats at any time%><% end %>
<% if it["local"] then %> <%:Update%> <% else %>
<% end %> <% if it.combo then %> <%:Edit%> <% elseif it["local"] then %> <%:Edit%> <% else %> <%:Edit%> <% end %> <%:Nodes%> <%:Output%>
<%:No subscriptions yet.%>
<%+footer%>