🐛 修复目录倒序导致开书落到未购买章

ep_list 最新话在前,startIndex 默认取第一项于是开书总落在锁定章弹「本章未购买」。改为按 ord 升序排、加 toc_version 强制旧缓存重拉;首话 title 为空时回落 short_title。
This commit is contained in:
Garfield committed 2026-11-27 08:49:17 +08:00
1 parent 5efe13834e
commit 93c0413424
2 files changed
+28 -9

No files matched your search

@@ -77,18 +77,29 @@ end
-- Chapter 映射 -- Chapter 映射
-- ============================================================ -- ============================================================
-- 目录缓存格式。ep_list 是倒序(最新话在前),版本 1 起按 ord 升序;旧缓存一律重拉。
Mapper.TOC_VERSION = 1
function Mapper.chapters(comic) function Mapper.chapters(comic)
if not comic then return {} end 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 = {} local chapters = {}
for i, ep in ipairs(eps) do 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] = { chapters[#chapters + 1] = {
idx = i, idx = i,
uid = tostring(ep.id), 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, vip = ep.is_locked == true,
} }
end end
if chapters[1] then chapters[1].toc_version = Mapper.TOC_VERSION end
return chapters return chapters
end end
@@ -51,11 +51,19 @@ function BiliManga:getDetailAsync(identity, cb)
end) end)
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) function BiliManga:loadTocAsync(identity, cb, force)
local tid = identity.source_id or SOURCE_ID
if not force then if not force then
local cached = Toc.read(tid, identity.stable_id) local cached = cachedToc(identity)
if cached and #cached > 0 then if cached then
return SourceBase.defer(cb, cached) return SourceBase.defer(cb, cached)
end end
end end
@@ -101,8 +109,8 @@ function BiliManga:openBookAsync(identity, opts, cb)
}) })
cb(ok and path or nil, err) cb(ok and path or nil, err)
end end
local toc = Toc.read(identity.source_id, identity.stable_id) local toc = cachedToc(identity)
if toc and #toc > 0 then if toc then
local idx = startIndex(identity, opts, toc) local idx = startIndex(identity, opts, toc)
local path = Chapter.existing(identity, toc[idx]) local path = Chapter.existing(identity, toc[idx])
if path then return SourceBase.defer(finish, path, idx) end if path then return SourceBase.defer(finish, path, idx) end
@@ -211,8 +219,8 @@ function BiliManga:getProgressAsync(identity, cb)
cb(nil, nil, { empty = true }) cb(nil, nil, { empty = true })
end end
local existing = Toc.read(identity.source_id or SOURCE_ID, identity.stable_id) local existing = cachedToc(identity)
if existing and #existing > 0 then if existing then
afterToc(existing) afterToc(existing)
else else
self:refreshTocAsync(identity, afterToc) self:refreshTocAsync(identity, afterToc)