From 93c04134245699fe208919ec1cbc1725c41db0ac Mon Sep 17 00:00:00 2001 From: Garfield Date: Fri, 27 Nov 2026 08:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E5=80=92=E5=BA=8F=E5=AF=BC=E8=87=B4=E5=BC=80=E4=B9=A6?= =?UTF-8?q?=E8=90=BD=E5=88=B0=E6=9C=AA=E8=B4=AD=E4=B9=B0=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ep_list 最新话在前,startIndex 默认取第一项于是开书总落在锁定章弹「本章未购买」。改为按 ord 升序排、加 toc_version 强制旧缓存重拉;首话 title 为空时回落 short_title。 --- .../moonsource_bilimanga/mapper.lua | 15 +++++++++++-- .../moonsource_bilimanga/source.lua | 22 +++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/moonsource-bilimanga.koplugin/moonsource_bilimanga/mapper.lua b/moonsource-bilimanga.koplugin/moonsource_bilimanga/mapper.lua index f885ae8..ba0d09e 100644 --- a/moonsource-bilimanga.koplugin/moonsource_bilimanga/mapper.lua +++ b/moonsource-bilimanga.koplugin/moonsource_bilimanga/mapper.lua @@ -77,18 +77,29 @@ end -- Chapter 映射 -- ============================================================ +-- 目录缓存格式。ep_list 是倒序(最新话在前),版本 1 起按 ord 升序;旧缓存一律重拉。 +Mapper.TOC_VERSION = 1 + function Mapper.chapters(comic) if not comic then return {} end - local eps = comic.ep_list or {} + local eps = {} + for i, ep in ipairs(comic.ep_list or {}) do eps[i] = ep end + table.sort(eps, function(a, b) + if a.ord ~= b.ord then return (a.ord or 0) < (b.ord or 0) end + return (a.id or 0) < (b.id or 0) + end) local chapters = {} for i, ep in ipairs(eps) do + local title = clean(ep.title):match("^%s*(.-)%s*$") + if title == "" then title = clean(ep.short_title):match("^%s*(.-)%s*$") end chapters[#chapters + 1] = { idx = i, uid = tostring(ep.id), - title = clean(ep.title or ep.short_title or ("第" .. i .. "话")), + title = title ~= "" and title or ("第" .. i .. "话"), vip = ep.is_locked == true, } end + if chapters[1] then chapters[1].toc_version = Mapper.TOC_VERSION end return chapters end diff --git a/moonsource-bilimanga.koplugin/moonsource_bilimanga/source.lua b/moonsource-bilimanga.koplugin/moonsource_bilimanga/source.lua index f49a30a..98bccd5 100644 --- a/moonsource-bilimanga.koplugin/moonsource_bilimanga/source.lua +++ b/moonsource-bilimanga.koplugin/moonsource_bilimanga/source.lua @@ -51,11 +51,19 @@ function BiliManga:getDetailAsync(identity, cb) end) end +--- 当前格式的缓存目录;旧格式(倒序)当作没有。 +---@param identity BookIdentity +---@return table[]|nil +local function cachedToc(identity) + local toc = Toc.read(identity.source_id or SOURCE_ID, identity.stable_id) + if toc and toc[1] and toc[1].toc_version == Mapper.TOC_VERSION then return toc end + return nil +end + function BiliManga:loadTocAsync(identity, cb, force) - local tid = identity.source_id or SOURCE_ID if not force then - local cached = Toc.read(tid, identity.stable_id) - if cached and #cached > 0 then + local cached = cachedToc(identity) + if cached then return SourceBase.defer(cb, cached) end end @@ -101,8 +109,8 @@ function BiliManga:openBookAsync(identity, opts, cb) }) cb(ok and path or nil, err) end - local toc = Toc.read(identity.source_id, identity.stable_id) - if toc and #toc > 0 then + local toc = cachedToc(identity) + if toc then local idx = startIndex(identity, opts, toc) local path = Chapter.existing(identity, toc[idx]) if path then return SourceBase.defer(finish, path, idx) end @@ -211,8 +219,8 @@ function BiliManga:getProgressAsync(identity, cb) cb(nil, nil, { empty = true }) end - local existing = Toc.read(identity.source_id or SOURCE_ID, identity.stable_id) - if existing and #existing > 0 then + local existing = cachedToc(identity) + if existing then afterToc(existing) else self:refreshTocAsync(identity, afterToc)