2 Commits
Author SHA1 Message Date
Garfield ce0210a4e8 🔖 (release): 发布 0.3.1
Release / release (push) Successful in 16s
2026-12-05 11:01:38 +08:00
Garfield b6b137a4b4 🐛 (shelf): 详情页被拦不再误判登录失效,404 的书 7 天内不再重试 2026-12-05 11:01:38 +08:00
4 changed files with 59 additions and 5 deletions

No files matched your search

+4
View File
@@ -1,5 +1,9 @@
# 更新日志 # 更新日志
## 0.3.1
- :bug: (shelf): 详情页被拦不再误判登录失效,404 的书 7 天内不再重试
## 0.3.0 ## 0.3.0
- :lipstick: (setting): 账号页使用书源自己的图标 - :lipstick: (setting): 账号页使用书源自己的图标
@@ -103,9 +103,13 @@ end
---@param path string ---@param path string
---@param cookie string|nil ---@param cookie string|nil
---@param cb fun(html: string|nil, err: string|nil) ---@param cb fun(html: string|nil, err: string|nil)
---@param soft boolean|nil 公开页面:带 Cookie 被 302/403 拦时不判登录失效,改用匿名再取一次
---@return HttpJob ---@return HttpJob
local function webGet(path, cookie, cb, cache_ttl) local webGet
return Request.get(WEB .. path, { 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), headers = headers(cookie),
timeout = require("http.timeout").net(1), timeout = require("http.timeout").net(1),
cache_ttl = cache_ttl, cache_ttl = cache_ttl,
@@ -113,7 +117,11 @@ local function webGet(path, cookie, cb, cache_ttl)
if not raw then if not raw then
local code = res and tonumber(res.code) local code = res and tonumber(res.code)
if cookie and cookie ~= "" and (code == 302 or code == 403) then if cookie and cookie ~= "" and (code == 302 or code == 403) then
if soft then
job = webGet(path, nil, cb, cache_ttl, true)
else
cb(nil, loginGone(cookie or "")) cb(nil, loginGone(cookie or ""))
end
else else
cb(nil, err and tostring(err) or _("请求失败")) cb(nil, err and tostring(err) or _("请求失败"))
end end
@@ -121,6 +129,7 @@ local function webGet(path, cookie, cb, cache_ttl)
end end
cb(raw) cb(raw)
end) end)
return handle
end end
---@param wire table|nil ---@param wire table|nil
@@ -429,7 +438,7 @@ function Client.detailAsync(book_id, cb)
end end
cb(info) cb(info)
end) end, nil, true)
end end
---@param book_id string ---@param book_id string
@@ -45,27 +45,46 @@ function Source:configured()
end 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 rows table[]
---@param cb fun(rows: table[]) ---@param cb fun(rows: table[])
---@return { cancel: fun() } ---@return { cancel: fun() }
local function fillDetails(rows, cb) local function fillDetails(rows, cb)
local BookDB = require("book.books_db") 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() local function nextRow()
if cancelled then return end if cancelled then return end
index = index + 1 index = index + 1
local row = rows[index] 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)) row.local_book = BookDB.get(Qidian.meta().id, tostring(row.bid))
local book = row.local_book local book = row.local_book
local intro = book and book.intro local intro = book and book.intro
local cover = book and book.cover local cover = book and book.cover
if intro and intro ~= "" and cover and cover ~= "" then nextRow(); return end 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) job = Client.detailAsync(row.bid, function(info, err)
if cancelled then return end if cancelled then return end
if info then if info then
row.info = info row.info = info
else 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) require("utils.log").warn("book qidian detail failed", row.bid, err)
end end
nextRow() nextRow()
+22
View File
@@ -349,3 +349,25 @@ do
Assert.is_nil(got) Assert.is_nil(got)
Assert.eq(err, "起点书友圈响应无效") Assert.eq(err, "起点书友圈响应无效")
end end
-- 详情页是公开页面:带 Cookie 被 302/403 拦时不能判登录失效,改匿名再取一次。
do
expired = nil
cfg.cookie = "ywkey=abc; _csrfToken=tok"
requests, replies = {}, {
{ body = nil, err = "HTTP 403", res = { code = 403 } },
{ body = page({ bookInfo = { bookId = 9, bookName = "书" } }) },
}
local info
Client.detailAsync("9", function(v) info = v end)
Assert.eq(#requests, 2)
Assert.is_true(requests[2].opts.headers.Cookie == nil, "重试不带账号 Cookie")
Assert.eq(info.bookName, "书")
Assert.is_nil(expired, "详情被拦不标登录失效")
-- 404(下架)原样报错,不当登录问题
requests, replies = {}, { { body = nil, err = "HTTP 404", res = { code = 404 } } }
local err
Client.detailAsync("9", function(_, e) err = e end)
Assert.eq(err, "HTTP 404")
Assert.is_nil(expired)
end