2 Commits
Author SHA1 Message Date
garfield 52cb59f33f ✨ (manage): 网页书源批量操作支持「选中全部 N 个」跨页全选
Release / release (push) Successful in 15s
2026-12-04 16:42:06 +08:00
garfield 7224137ed2 ✨ (import): 设备上可浏览选择 json/jsonl 文件导入书源
Release / release (push) Successful in 14s
2026-12-04 08:28:18 +08:00
12 changed files with 95 additions and 13 deletions

No files matched your search

+8
View File
@@ -1,5 +1,13 @@
# 更新日志 # 更新日志
## 0.0.3
- 网页书源管理批量操作新增「选中全部 N 个」:按当前搜索与状态筛选跨页全选,再批量检查、启停、删除。
## 0.0.2
- 设备上新增「从文件导入」:浏览选择 .json / .jsonl / .txt 书源文件直接导入;导入提示里显示因需要 JS/WebView 被禁用的个数。
## 0.0.1 ## 0.0.1
- 新书源:在本机直接运行 Legado 书源 JSON 规则(搜索、发现、详情、目录、正文),不依赖 Legado App;需要 JS / WebView 的书源暂不支持。 - 新书源:在本机直接运行 Legado 书源 JSON 规则(搜索、发现、详情、目录、正文),不依赖 Legado App;需要 JS / WebView 的书源暂不支持。
@@ -6,7 +6,7 @@
| 导入即禁用 | 已实现,未实测 | 规则里含 JS / WebView 的书源导入时自动禁用,并在库里记录原因 | | 导入即禁用 | 已实现,未实测 | 规则里含 JS / WebView 的书源导入时自动禁用,并在库里记录原因 |
| 书源有效性检查 | 已实现,未实测 | 逐个走完整读书流程(搜索、详情、目录、第一章正文),任一环节失败即禁用;响应时间、禁用原因存库并在网页显示 | | 书源有效性检查 | 已实现,未实测 | 逐个走完整读书流程(搜索、详情、目录、第一章正文),任一环节失败即禁用;响应时间、禁用原因存库并在网页显示 |
| 书架换源 | 已实现,未实测 | 设置里和远程管理网页都有「书架换源」(网页里后台搜索并显示进度,关掉页面后回来可接上):书源失效的书排在前面,在其他书源搜同名书后改读新来源;书架身份、阅读进度和时间不变,目录重新拉取,章节序号可能与旧目录不一致 | | 书架换源 | 已实现,未实测 | 设置里和远程管理网页都有「书架换源」(网页里后台搜索并显示进度,关掉页面后回来可接上):书源失效的书排在前面,在其他书源搜同名书后改读新来源;书架身份、阅读进度和时间不变,目录重新拉取,章节序号可能与旧目录不一致 |
| 书源导入 | 已实现,未实测 | 设置页粘贴 Legado 书源 JSON、填地址或本地文件路径;支持单个、数组或每行一个 | | 书源导入 | 已实现,未实测 | 设置页可粘贴 Legado 书源 JSON、填地址,或在「从文件导入」里浏览设备选 .json / .jsonl / .txt 文件;支持单个、数组或每行一个(jsonl) |
| 登录 | 不支持 | 不处理登录;书源 header / Cookie 规则中的静态值可用,登录 JS 不支持 | | 登录 | 不支持 | 不处理登录;书源 header / Cookie 规则中的静态值可用,登录 JS 不支持 |
| 搜索 | 已实现,未实测 | 同时搜所有已启用书源(4 路并发),单个书源失败不影响其他;只取第一页 | | 搜索 | 已实现,未实测 | 同时搜所有已启用书源(4 路并发),单个书源失败不影响其他;只取第一页 |
| 发现 / 分类 | 已实现,未实测 | 来自书源 exploreUrl(`标题::地址` 或 JSON);含 JS 的条目跳过 | | 发现 / 分类 | 已实现,未实测 | 来自书源 exploreUrl(`标题::地址` 或 JSON);含 JS 的条目跳过 |
@@ -36,4 +36,6 @@ return {
["书源不可用"] = "Source unavailable", ["书源不可用"] = "Source unavailable",
["搜索失败"] = "Search failed", ["搜索失败"] = "Search failed",
["书架里还没有这个书源的书"] = "No books from this source on the shelf", ["书架里还没有这个书源的书"] = "No books from this source on the shelf",
["从文件导入"] = "Import from file",
[",%1 个需要 JS/WebView 已禁用"] = ", %1 need JS/WebView and were disabled",
} }
@@ -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 個書源。",
["已删除"] = "已刪除", ["已删除"] = "已刪除",
@@ -36,4 +36,6 @@ return {
["书源不可用"] = "書源不可用", ["书源不可用"] = "書源不可用",
["搜索失败"] = "搜索失敗", ["搜索失败"] = "搜索失敗",
["书架里还没有这个书源的书"] = "書架裡還沒有這個書源的書", ["书架里还没有这个书源的书"] = "書架裡還沒有這個書源的書",
["从文件导入"] = "從檔案匯入",
[",%1 个需要 JS/WebView 已禁用"] = ",%1 個需要 JS/WebView 已停用",
} }
@@ -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
@@ -1,5 +1,5 @@
--[[-- --[[--
开源阅读书源设置:导入 Legado 书源(地址 / 本地文件 / 粘贴 JSON)、启停与删除、书架换源。 开源阅读书源设置:导入 Legado 书源(地址 / 选择 .json、.jsonl 文件 / 粘贴 JSON)、启停与删除、书架换源。
@module moonsource_legadorule.setting @module moonsource_legadorule.setting
--]] --]]
@@ -32,9 +32,11 @@ local function finishImport(text)
toast(_("没有找到有效的书源")) toast(_("没有找到有效的书源"))
return return
end end
Sources.add(rules) local _added, disabled = Sources.add(rules)
require("source.registry").reload() require("source.registry").reload()
toast(T(_("已导入 %1 个书源,跳过 %2 个无效项"), #rules, skipped)) local msg = T(_("已导入 %1 个书源,跳过 %2 个无效项"), #rules, skipped)
if disabled and disabled > 0 then msg = msg .. T(_(",%1 个需要 JS/WebView 已禁用"), disabled) end
toast(msg)
end end
local function import(value) local function import(value)
@@ -72,6 +74,21 @@ local function importDialog()
}:show() }:show()
end end
local function importFile()
local lfs = require("libs/libkoreader-lfs")
local start = lfs.attributes("/mnt/us", "mode") == "directory" and "/mnt/us"
or require("datastorage"):getDataDir()
require("ui.themes.widgets.path_picker"):new{
path = start,
select_file = true,
filter = function(name)
local lower = name:lower()
return lower:match("%.jsonl?$") ~= nil or lower:match("%.txt$") ~= nil
end,
on_select = import,
}:show()
end
local function manageOne(entry) local function manageOne(entry)
local Sources = require("moonsource_legadorule.sources") local Sources = require("moonsource_legadorule.sources")
require("ui.themes.widgets.list"):new{ require("ui.themes.widgets.list"):new{
@@ -193,6 +210,12 @@ function Setting.rows()
callback = importDialog, callback = importDialog,
}) })
end, end,
function(iw)
return Row().widget({
width = iw, chevron = true, kind = "nav", icon = "download", title = _("从文件导入"),
callback = importFile,
})
end,
function(iw) function(iw)
return Row().widget({ return Row().widget({
width = iw, chevron = true, kind = "nav", icon = "sync", title = _("书架换源"), width = iw, chevron = true, kind = "nav", icon = "sync", title = _("书架换源"),
@@ -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);
+8
View File
@@ -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