🐛 (shelf): 详情页被拦不再误判登录失效,404 的书 7 天内不再重试

This commit is contained in:
Garfield committed 2026-12-05 11:01:38 +08:00
1 parent d736b69cdd
commit b6b137a4b4
3 files changed
+56 -6

No files matched your search

@@ -103,9 +103,13 @@ end
---@param path string
---@param cookie string|nil
---@param cb fun(html: string|nil, err: string|nil)
---@param soft boolean|nil 公开页面:带 Cookie 被 302/403 拦时不判登录失效,改用匿名再取一次
---@return HttpJob
local function webGet(path, cookie, cb, cache_ttl)
return Request.get(WEB .. path, {
local webGet
function webGet(path, cookie, cb, cache_ttl, soft)
local job
local handle = { cancel = function() if job then job.cancel() end end }
job = Request.get(WEB .. path, {
headers = headers(cookie),
timeout = require("http.timeout").net(1),
cache_ttl = cache_ttl,
@@ -113,7 +117,11 @@ local function webGet(path, cookie, cb, cache_ttl)
if not raw then
local code = res and tonumber(res.code)
if cookie and cookie ~= "" and (code == 302 or code == 403) then
cb(nil, loginGone(cookie or ""))
if soft then
job = webGet(path, nil, cb, cache_ttl, true)
else
cb(nil, loginGone(cookie or ""))
end
else
cb(nil, err and tostring(err) or _("请求失败"))
end
@@ -121,6 +129,7 @@ local function webGet(path, cookie, cb, cache_ttl)
end
cb(raw)
end)
return handle
end
---@param wire table|nil
@@ -429,7 +438,7 @@ function Client.detailAsync(book_id, cb)
end
cb(info)
end)
end, nil, true)
end
---@param book_id string
@@ -45,27 +45,46 @@ function Source:configured()
end
--- 书架行没有简介。本地没有简介或封面的书逐本补拉详情,拉不到就退回书架行。
local MISSING_TTL = 7 * 24 * 3600
--- 起点页面返回 404(下架/删除)的书:一段时间内不再逐本重试,否则每次同步书架都白打一轮请求。
local function missingSet()
local cfg = require("utils.settings").getSource("qidian")
cfg.detail_missing = type(cfg.detail_missing) == "table" and cfg.detail_missing or {}
return cfg.detail_missing
end
---@param rows table[]
---@param cb fun(rows: table[])
---@return { cancel: fun() }
local function fillDetails(rows, cb)
local BookDB = require("book.books_db")
local cancelled, job, index = false, nil, 0
local cancelled, job, index, missingDirty = false, nil, 0, false
local function nextRow()
if cancelled then return end
index = index + 1
local row = rows[index]
if not row then cb(rows); return end
if not row then
if missingDirty then require("utils.settings").saveSource("qidian") end
cb(rows)
return
end
row.local_book = BookDB.get(Qidian.meta().id, tostring(row.bid))
local book = row.local_book
local intro = book and book.intro
local cover = book and book.cover
if intro and intro ~= "" and cover and cover ~= "" then nextRow(); return end
local since = tonumber(missingSet()[tostring(row.bid)])
if since and os.time() - since < MISSING_TTL then nextRow(); return end
job = Client.detailAsync(row.bid, function(info, err)
if cancelled then return end
if info then
row.info = info
else
if tostring(err):find("404", 1, true) then
missingSet()[tostring(row.bid)] = os.time()
missingDirty = true
end
require("utils.log").warn("book qidian detail failed", row.bid, err)
end
nextRow()