Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52cb59f33f |
No files matched your search
@@ -1,5 +1,9 @@
|
|||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
## 0.0.3
|
||||||
|
|
||||||
|
- 网页书源管理批量操作新增「选中全部 N 个」:按当前搜索与状态筛选跨页全选,再批量检查、启停、删除。
|
||||||
|
|
||||||
## 0.0.2
|
## 0.0.2
|
||||||
|
|
||||||
- 设备上新增「从文件导入」:浏览选择 .json / .jsonl / .txt 书源文件直接导入;导入提示里显示因需要 JS/WebView 被禁用的个数。
|
- 设备上新增「从文件导入」:浏览选择 .json / .jsonl / .txt 书源文件直接导入;导入提示里显示因需要 JS/WebView 被禁用的个数。
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ return {
|
|||||||
["还没有书源,点右上角「添加书源」"] = "No sources yet. Click “Add sources”.",
|
["还没有书源,点右上角「添加书源」"] = "No sources yet. Click “Add sources”.",
|
||||||
["显示更多(还有 %1 个)"] = "Show more (%1 left)",
|
["显示更多(还有 %1 个)"] = "Show more (%1 left)",
|
||||||
["已选 %1 项"] = "%1 selected",
|
["已选 %1 项"] = "%1 selected",
|
||||||
|
["选中全部 %1 个"] = "Select all %1",
|
||||||
["删除书源?"] = "Delete sources?",
|
["删除书源?"] = "Delete sources?",
|
||||||
["将删除 %1 个书源。"] = "%1 sources will be deleted.",
|
["将删除 %1 个书源。"] = "%1 sources will be deleted.",
|
||||||
["已删除"] = "Deleted",
|
["已删除"] = "Deleted",
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ return {
|
|||||||
["还没有书源,点右上角「添加书源」"] = "還沒有書源,点右上角「添加書源」",
|
["还没有书源,点右上角「添加书源」"] = "還沒有書源,点右上角「添加書源」",
|
||||||
["显示更多(还有 %1 个)"] = "顯示更多(還有 %1 個)",
|
["显示更多(还有 %1 个)"] = "顯示更多(還有 %1 個)",
|
||||||
["已选 %1 项"] = "已選 %1 項",
|
["已选 %1 项"] = "已選 %1 項",
|
||||||
|
["选中全部 %1 个"] = "選中全部 %1 個",
|
||||||
["删除书源?"] = "刪除書源?",
|
["删除书源?"] = "刪除書源?",
|
||||||
["将删除 %1 个书源。"] = "將刪除 %1 個書源。",
|
["将删除 %1 个书源。"] = "將刪除 %1 個書源。",
|
||||||
["已删除"] = "已刪除",
|
["已删除"] = "已刪除",
|
||||||
|
|||||||
@@ -29,11 +29,14 @@ local function summary(s)
|
|||||||
reason = s.reason, ms = s.ms, checked = s.checked }
|
reason = s.reason, ms = s.ms, checked = s.checked }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function statusOf(params)
|
||||||
|
return params.status == "on" and "on" or params.status == "off" and "off" or nil
|
||||||
|
end
|
||||||
|
|
||||||
local function listing(params)
|
local function listing(params)
|
||||||
local page = math.max(1, math.floor(tonumber(params.page) or 1))
|
local page = math.max(1, math.floor(tonumber(params.page) or 1))
|
||||||
local size = math.min(200, math.max(1, math.floor(tonumber(params.size) or 50)))
|
local size = math.min(200, math.max(1, math.floor(tonumber(params.size) or 50)))
|
||||||
local status = params.status == "on" and "on" or params.status == "off" and "off" or nil
|
local list, total = Sources.page(params.q and tostring(params.q) or nil, statusOf(params), page, size)
|
||||||
local list, total = Sources.page(params.q and tostring(params.q) or nil, status, page, size)
|
|
||||||
local sources = {}
|
local sources = {}
|
||||||
for _idx, s in ipairs(list) do sources[#sources + 1] = summary(s) end
|
for _idx, s in ipairs(list) do sources[#sources + 1] = summary(s) end
|
||||||
return { sources = sources, total = total, counts = Sources.counts() }
|
return { sources = sources, total = total, counts = Sources.counts() }
|
||||||
@@ -161,6 +164,8 @@ function Remote.handle(method, action, params, cb)
|
|||||||
require("utils.awake").poke()
|
require("utils.awake").poke()
|
||||||
if method == "GET" and action == "list" then
|
if method == "GET" and action == "list" then
|
||||||
cb(200, listing(params))
|
cb(200, listing(params))
|
||||||
|
elseif method == "GET" and action == "keys" then
|
||||||
|
cb(200, { keys = Sources.keys(params.q and tostring(params.q) or nil, statusOf(params)) })
|
||||||
elseif method == "POST" and action == "import" then
|
elseif method == "POST" and action == "import" then
|
||||||
-- 原始文件体落在临时文件里(路径在 params.temp);粘贴的文本由网页同样当文件体发来
|
-- 原始文件体落在临时文件里(路径在 params.temp);粘贴的文本由网页同样当文件体发来
|
||||||
local path = params.temp
|
local path = params.temp
|
||||||
|
|||||||
@@ -109,14 +109,11 @@ function Sources.all()
|
|||||||
return entries(" ORDER BY seq ASC")
|
return entries(" ORDER BY seq ASC")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- 分页查询:q 匹配名称或地址(不分大小写),status 为 "on" / "off" / nil。返回当页书源与符合条件的总数。
|
|
||||||
---@param q string|nil
|
---@param q string|nil
|
||||||
---@param status string|nil
|
---@param status string|nil
|
||||||
---@param page integer 从 1 起
|
---@return string cond
|
||||||
---@param size integer
|
---@return table args
|
||||||
---@return table[] list
|
local function filter(q, status)
|
||||||
---@return integer total
|
|
||||||
function Sources.page(q, status, page, size)
|
|
||||||
local where, args = {}, {}
|
local where, args = {}, {}
|
||||||
if q and q ~= "" then
|
if q and q ~= "" then
|
||||||
local like = "%" .. q:gsub("[\\%%_]", "\\%0") .. "%"
|
local like = "%" .. q:gsub("[\\%%_]", "\\%0") .. "%"
|
||||||
@@ -126,13 +123,36 @@ function Sources.page(q, status, page, size)
|
|||||||
end
|
end
|
||||||
if status == "on" then where[#where + 1] = "enabled=1"
|
if status == "on" then where[#where + 1] = "enabled=1"
|
||||||
elseif status == "off" then where[#where + 1] = "enabled=0" end
|
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
|
local total = tonumber(DB.rowexec("SELECT COUNT(*) FROM legadorule_sources" .. cond .. ";", unpack(args))) or 0
|
||||||
args[#args + 1] = size
|
args[#args + 1] = size
|
||||||
args[#args + 1] = (page - 1) * size
|
args[#args + 1] = (page - 1) * size
|
||||||
return entries(cond .. " ORDER BY seq ASC LIMIT ? OFFSET ?", unpack(args)), total
|
return entries(cond .. " ORDER BY seq ASC LIMIT ? OFFSET ?", unpack(args)), total
|
||||||
end
|
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 }
|
---@return { all: integer, on: integer, off: integer }
|
||||||
function Sources.counts()
|
function Sources.counts()
|
||||||
local all = tonumber(DB.rowexec("SELECT COUNT(*) FROM legadorule_sources;")) or 0
|
local all = tonumber(DB.rowexec("SELECT COUNT(*) FROM legadorule_sources;")) or 0
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="batch" class="sub-batch" role="toolbar" aria-label="批量操作" hidden>
|
<div id="batch" class="sub-batch" role="toolbar" aria-label="批量操作" hidden>
|
||||||
<span id="batch-count" class="count-badge"></span>
|
<span id="batch-count" class="count-badge"></span>
|
||||||
|
<button type="button" id="b-all" class="file-action" hidden></button>
|
||||||
<button type="button" id="b-check" class="file-action">检查所选</button>
|
<button type="button" id="b-check" class="file-action">检查所选</button>
|
||||||
<button type="button" id="b-on" class="file-action">启用</button>
|
<button type="button" id="b-on" class="file-action">启用</button>
|
||||||
<button type="button" id="b-off" class="file-action">禁用</button>
|
<button type="button" id="b-off" class="file-action">禁用</button>
|
||||||
|
|||||||
@@ -188,6 +188,9 @@
|
|||||||
var n = selectedKeys().length;
|
var n = selectedKeys().length;
|
||||||
el('batch').hidden = !n;
|
el('batch').hidden = !n;
|
||||||
el('batch-count').textContent = t('已选 %1 项', n);
|
el('batch-count').textContent = t('已选 %1 项', n);
|
||||||
|
var all = el('b-all');
|
||||||
|
all.hidden = !n || !data || n >= data.total;
|
||||||
|
all.textContent = t('选中全部 %1 个', data ? data.total : 0);
|
||||||
}
|
}
|
||||||
function render() {
|
function render() {
|
||||||
renderGroups();
|
renderGroups();
|
||||||
@@ -420,6 +423,14 @@
|
|||||||
run(function () { return post('enable', { keys: selectedKeys(), enabled: false }); }, t('完成'));
|
run(function () { return post('enable', { keys: selectedKeys(), enabled: false }); }, t('完成'));
|
||||||
};
|
};
|
||||||
el('b-delete').onclick = function () { removeKeys(selectedKeys()); };
|
el('b-delete').onclick = function () { removeKeys(selectedKeys()); };
|
||||||
|
el('b-all').onclick = function () {
|
||||||
|
var qs = 'status=' + (cur === ALL ? '' : cur) + '&q=' + encodeURIComponent(el('q').value.trim());
|
||||||
|
jfetch(API + 'keys?' + qs, { cache: 'no-store' }).then(function (d) {
|
||||||
|
sel = {};
|
||||||
|
(Array.isArray(d.keys) ? d.keys : []).forEach(function (k) { sel[k] = true; });
|
||||||
|
renderList();
|
||||||
|
}).catch(fail);
|
||||||
|
};
|
||||||
el('b-clear').onclick = function () { sel = {}; renderList(); };
|
el('b-clear').onclick = function () { sel = {}; renderList(); };
|
||||||
el('q').oninput = function () {
|
el('q').oninput = function () {
|
||||||
clearTimeout(searchTimer);
|
clearTimeout(searchTimer);
|
||||||
|
|||||||
@@ -159,6 +159,14 @@ do
|
|||||||
Assert.eq(r.total, 1)
|
Assert.eq(r.total, 1)
|
||||||
_, r = call("GET", "list", { status = "on" })
|
_, r = call("GET", "list", { status = "on" })
|
||||||
Assert.eq(r.total, r.counts.on)
|
Assert.eq(r.total, r.counts.on)
|
||||||
|
-- 跨页全选:key 数量等于筛选后的总数,不受分页限制
|
||||||
|
local k
|
||||||
|
_, k = call("GET", "keys", {})
|
||||||
|
Assert.len(k.keys, r.counts.all)
|
||||||
|
_, k = call("GET", "keys", { q = "V.COM" })
|
||||||
|
Assert.len(k.keys, 1)
|
||||||
|
_, k = call("GET", "keys", { status = "on" })
|
||||||
|
Assert.len(k.keys, r.counts.on)
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in new issue
Block a user