✨ 迁移到现行 Web 协议:签名请求、浏览器登录与分类书城

GetImageIndex / ImageToken 等接口走 ultra_sign 签名并解 bytesData;
登录改为浏览器授权或完整 Cookie,校验通过才保存。
This commit is contained in:
Garfield committed 2026-11-27 07:43:45 +08:00
1 parent 430962a5d0
commit 455891353c
8 files changed
+1012 -143

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
--[[--
哔哩漫画账号校验,以及已解锁话不被本机标成未购买。
@module tests.moonsource_bilimanga.account_spec
--]]
local Assert = require("support.assert")
local Stubs = require("support.stubs")
local Json = require("support.json_stub")
local Mapper = require("moonsource_bilimanga.mapper")
local chapters = Mapper.chapters({ ep_list = {
{ id = 1, title = "已解锁", is_locked = false, pay_type = 1, is_pay = true },
{ id = 2, title = "未解锁", is_locked = true, pay_type = 0 },
} })
Assert.eq(chapters[1].vip, false)
Assert.eq(chapters[2].vip, true)
local fetched = false
package.loaded["moonsource_bilimanga.client"] = {
imageIndexAsync = function() fetched = true end,
}
local Chapter = require("moonsource_bilimanga.chapter")
local reason
Chapter.materializeAsync(
{ source_id = "bilimanga", stable_id = "1" },
{ uid = "9", vip = true },
nil,
function(_path, err) reason = err end)
Stubs.flush()
Assert.eq(reason, "本章未购买")
Assert.is_false(fetched)
package.loaded["moonsource_bilimanga.client"] = nil
package.loaded["moonsource_bilimanga.chapter"] = nil
package.loaded["json"] = { encode = Json.encode, decode = Json.decode }
local sent
local reply
package.loaded["http.request"] = {
ok = function(code) return code and code >= 200 and code < 300 end,
request = function(opts, cb)
sent = opts
local job = { cancel = function() reply = nil end }
if reply then cb(reply.body, reply.err) end
return job
end,
}
local Client = require("moonsource_bilimanga.client")
local function check(body)
reply = { body = { code = 200, body = body } }
local ok, err, account
Client.loginCheckAsync("SESSDATA=fixture", function(a, b, c)
ok, err, account = a, b, c
end)
return ok, err, account
end
local ok, err = check(Json.encode({ code = -101, data = { isLogin = false } }))
Assert.eq(ok, false)
Assert.eq(err, "登录校验失败,请确认已经登录哔哩哔哩")
Assert.eq(sent.headers.Cookie, "SESSDATA=fixture")
Assert.eq(sent.url, "https://api.bilibili.com/x/web-interface/nav")
ok, err, account = check(Json.encode({ code = 0, data = { isLogin = true, mid = 42 } }))
Assert.eq(ok, true)
Assert.is_nil(err)
Assert.eq(account.id, "42")
local empty_ok, empty_err
Client.loginCheckAsync("", function(a, b) empty_ok, empty_err = a, b end)
Assert.eq(empty_ok, false)
Assert.eq(empty_err, "没有读到 Cookie")
+44
View File
@@ -0,0 +1,44 @@
--[[--
书架列表和书城分类的字段形状。
@module tests.moonsource_bilimanga.store_spec
--]]
local Assert = require("support.assert")
local Mapper = require("moonsource_bilimanga.mapper")
local book = Mapper.book({ season_id = 25717, title = "示例", vertical_cover = "http://cover" })
Assert.eq(book.stable_id, "25717")
Assert.eq(book.cover, "http://cover")
local shelf = Mapper.rows({ code = 0, data = {
{ comic_id = 1, title = "一" },
{ comic_id = 2, title = "二" },
} })
Assert.eq(#shelf, 2)
Assert.is_nil(Mapper.rows({ code = 0, msg = "坏了" }))
local labels = Mapper.labels({ data = {
styles = { { id = 999, name = "热血" } },
orders = { { id = 0, name = "人气推荐" }, { id = 1, name = "更新时间" } },
} })
local order, style = Mapper.storeChoice(nil, labels)
Assert.eq(order, 0)
Assert.eq(style, -1)
order, style = Mapper.storeChoice("1:999", labels)
Assert.eq(order, 1)
Assert.eq(style, 999)
order, style = Mapper.storeChoice("9:8", labels)
Assert.eq(order, 0)
Assert.eq(style, -1)
local groups = Mapper.storeGroups(labels, 0, 999)
Assert.eq(#groups, 2)
Assert.eq(groups[1].chips[2].id, "1:999")
Assert.eq(groups[2].chips[1].id, "0:-1")
Assert.eq(groups[2].chips[2].id, "0:999")
local books = Mapper.books({ { season_id = 29040, title = "分类" } })
Assert.eq(#books, 1)
Assert.eq(books[1].stable_id, "29040")
Assert.is_nil(Mapper.books({ { title = "没有身份" } }))