✨ (manage): 网页书源批量操作支持「选中全部 N 个」跨页全选
Release / release (push) Successful in 15s

This commit is contained in:
garfield committed 2026-12-04 16:42:06 +08:00
1 parent 7224137ed2
commit 52cb59f33f
8 files changed
+60 -9

No files matched your search

@@ -109,14 +109,11 @@ function Sources.all()
return entries(" ORDER BY seq ASC")
end
--- 分页查询:q 匹配名称或地址(不分大小写),status 为 "on" / "off" / nil。返回当页书源与符合条件的总数。
---@param q string|nil
---@param status string|nil
---@param page integer 从 1 起
---@param size integer
---@return table[] list
---@return integer total
function Sources.page(q, status, page, size)
---@return string cond
---@return table args
local function filter(q, status)
local where, args = {}, {}
if q and q ~= "" then
local like = "%" .. q:gsub("[\\%%_]", "\\%0") .. "%"
@@ -126,13 +123,36 @@ function Sources.page(q, status, page, size)
end
if status == "on" then where[#where + 1] = "enabled=1"
elseif status == "off" then where[#where + 1] = "enabled=0" end
local cond = #where > 0 and (" WHERE " .. table.concat(where, " AND ")) or ""
return #where > 0 and (" WHERE " .. table.concat(where, " AND ")) or "", args
end
--- 分页查询:q 匹配名称或地址(不分大小写),status 为 "on" / "off" / nil。返回当页书源与符合条件的总数。
---@param q string|nil
---@param status string|nil
---@param page integer 从 1 起
---@param size integer
---@return table[] list
---@return integer total
function Sources.page(q, status, page, size)
local cond, args = filter(q, status)
local total = tonumber(DB.rowexec("SELECT COUNT(*) FROM legadorule_sources" .. cond .. ";", unpack(args))) or 0
args[#args + 1] = size
args[#args + 1] = (page - 1) * size
return entries(cond .. " ORDER BY seq ASC LIMIT ? OFFSET ?", unpack(args)), total
end
--- 符合条件的全部书源 key(跨页全选)。
---@param q string|nil
---@param status string|nil
---@return string[]
function Sources.keys(q, status)
local cond, args = filter(q, status)
local result, n = DB.query("SELECT key FROM legadorule_sources" .. cond .. " ORDER BY seq ASC;", unpack(args))
local out = {}
for i = 1, n or 0 do out[i] = result[1][i] end
return out
end
---@return { all: integer, on: integer, off: integer }
function Sources.counts()
local all = tonumber(DB.rowexec("SELECT COUNT(*) FROM legadorule_sources;")) or 0