🌈 Sync 2026-08-11 02:29:57

This commit is contained in:
github-actions[bot] committed 2026-08-11 02:29:57 +08:00
1 parent f8bdc4459f
commit 412c262edf
73 files changed
+9791 -5915

No files matched your search

+59 -23
View File
@@ -335,16 +335,24 @@ function get_resourse_mtime(path)
local found = find_case_insensitive_path(path)
if found then
real_path = found
elseif uci_get_config("config", "small_flash_memory") == "1" then
local fallback_path = path:gsub("^/etc/openclash/", "/tmp/etc/openclash/")
local fallback_found = find_case_insensitive_path(fallback_path)
if fallback_found then
real_path = fallback_found
else
return "File Not Exist"
end
else
return "File Not Exist"
end
end
local file = fs.readlink(real_path) or real_path
local resourse_etag_version = SYS.exec(string.format("source /usr/share/openclash/openclash_etag.sh && GET_ETAG_TIMESTAMP_BY_PATH '%s'", real_path))
local resourse_etag_version = SYS.exec(string.format("source /usr/share/openclash/openclash_etag.sh && GET_ETAG_TIMESTAMP_BY_PATH '%s'", file))
if resourse_etag_version and resourse_etag_version ~= "" then
return resourse_etag_version
end
local resourse_version = os.date("%Y-%m-%d %H:%M:%S", mtime(real_path))
local resourse_version = os.date("%Y-%m-%d %H:%M:%S", mtime(file))
if resourse_version and resourse_version ~= "" then
return resourse_version
end
@@ -600,32 +608,60 @@ function pkg_type()
end
end
--- Returns the installed version of luci-app-openclash.
-- Supports both opkg and apk package managers.
-- @return String containing the version number, or "0" if not found
-- NOTE: The module-level cache (_oc_version_cache) provides per-request
-- deduplication. In OpenWrt LuCI CGI mode each HTTP request spawns a new Lua
-- process, so cross-request caching is impossible.
-- Since require() returns the same module instance (package.loaded), the
-- first call caches the result and subsequent calls avoid redundant shell
-- commands. No time-based expiration is needed — the version is immutable
-- for the lifetime of a request.
local _oc_version_cache = nil
--- Reads the CDN proxy address list from /usr/share/openclash/res/cdn.list.
-- Lines starting with "#" are treated as comments and skipped.
-- @return Table of CDN address strings (deduplicated, in file order)
function cdn_list()
local list = {}
local seen = {}
local raw = fs.readfile("/usr/share/openclash/res/cdn.list")
if raw then
for line in raw:gmatch("[^\r\n]+") do
line = line:gsub("^%s+", ""):gsub("%s+$", "")
if line ~= "" and line:sub(1, 1) ~= "#" and not seen[line] then
seen[line] = true
list[#list + 1] = line
end
end
end
return list
end
--- Read a field of an installed package directly from the package database
-- (/usr/lib/opkg/status or /lib/apk/db/installed), avoiding the opkg/apk
-- binaries and their lock files (/var/lock/opkg.lock, /lib/apk/db/lock).
-- Safe to call repeatedly/concurrently and never blocks on a lock.
-- @param pkg Package name, e.g. "luci-app-openclash" or "libc"
-- @param field Field name; opkg: "Version"/"Architecture", apk: "V"/"A"
-- @return String field value, or "" when not found
function read_pkg_field(pkg, field)
local text
if pkg_type() == "opkg" then
text = fs.readfile("/usr/lib/opkg/status")
else
text = fs.readfile("/lib/apk/db/installed")
end
if not text then return "" end
text = text:gsub("\r\n", "\n")
local prefix = (pkg_type() == "opkg") and ("Package: " .. pkg .. "\n") or ("P:" .. pkg .. "\n")
local start = text:find(prefix, 1, true)
if not start then return "" end
local block_end = text:find("\n\n", start + #prefix, true) or #text
local block = text:sub(start + #prefix, block_end - 1)
local colon = (pkg_type() == "opkg") and ": " or ":"
local val = block:match("\n" .. field .. colon .. "([^\r\n]+)")
if not val then
val = block:match("^" .. field .. colon .. "([^\r\n]+)")
end
return val or ""
end
function oc_version()
if _oc_version_cache ~= nil then
return _oc_version_cache
end
local v
if pkg_type() == "opkg" then
v = SYS.exec("rm -f /var/lock/opkg.lock && opkg status luci-app-openclash 2>/dev/null |grep '^Version:' |awk '{print $2}' |tr -d '\n'")
else
v = SYS.exec("rm -f /lib/apk/db/lock && apk info luci-app-openclash 2>/dev/null |grep '^luci-app-openclash-[0-9]' |sed 's/luci-app-openclash-//' |tr -d '\n'")
end
local v = read_pkg_field("luci-app-openclash", pkg_type() == "opkg" and "Version" or "V")
if v == "" then
v = "0"
end
_oc_version_cache = v
return v
end