GetImageIndex / ImageToken 等接口走 ultra_sign 签名并解 bytesData; 登录改为浏览器授权或完整 Cookie,校验通过才保存。
79 lines
2.4 KiB
Lua
79 lines
2.4 KiB
Lua
--[[--
|
|
哔哩漫画账号:浏览器授权与完整 Cookie。校验通过才保存。
|
|
|
|
漫画站复用哔哩哔哩主站会话。已购和大会员话由详情里的 is_locked 表示,
|
|
不在这里另做会员开关。
|
|
|
|
@module moonsource_bilimanga.setting
|
|
--]]
|
|
|
|
local CookieLogin = require("source.cookie_login")
|
|
local _ = require("moonsource_bilimanga.l10n")
|
|
|
|
local SOURCE_ID = "bilimanga"
|
|
local Setting = {}
|
|
|
|
local function loggedIn()
|
|
local cfg = require("utils.settings").getSource(SOURCE_ID)
|
|
return type(cfg.cookie) == "string" and cfg.cookie ~= ""
|
|
end
|
|
|
|
local function commit(cookie, account, cb, current)
|
|
if type(account) ~= "table" or type(account.id) ~= "string" or not account.id:match("^%d+$") then
|
|
cb(false, _("哔哩账号标识缺失"))
|
|
return
|
|
end
|
|
return CookieLogin.commitAccount(SOURCE_ID, cookie, account.id, cb, current)
|
|
end
|
|
|
|
---@type CookieLoginSpec
|
|
local SPEC = {
|
|
id = SOURCE_ID,
|
|
title = _("哔哩漫画账号"),
|
|
cookie_title = _("哔哩漫画登录 Cookie"),
|
|
cookie_hint = _("在漫画官网登录后,复制请求标头里的完整 Cookie"),
|
|
logout_text = _("确定退出哔哩漫画账号?"),
|
|
loggedIn = loggedIn,
|
|
checkAsync = function(cookie, cb)
|
|
return require("moonsource_bilimanga.client").loginCheckAsync(cookie, cb)
|
|
end,
|
|
commit = commit,
|
|
clear = function(cfg) cfg.cookie, cfg.account_id = nil, nil end,
|
|
}
|
|
|
|
function Setting.rowStatus()
|
|
local on = CookieLogin.authorized(SPEC)
|
|
return on and _("已登录") or _("未登录 · 点此登录"), on
|
|
end
|
|
|
|
function Setting.rowIcon()
|
|
return "menu_book"
|
|
end
|
|
|
|
Setting.browser = {
|
|
domain = "manga.bilibili.com",
|
|
scope = "cookie",
|
|
login = "https://manga.bilibili.com/account-center",
|
|
check = "https://manga.bilibili.com/account-center",
|
|
icon = "https://i0.hdslb.com/bfs/activity-plat/static/20250320/1e16455b3e0f77ddb2522c3ae2aba5d9/SgyyYc4rbJ.ico",
|
|
isAuthorized = function() return CookieLogin.authorized(SPEC) end,
|
|
apply = function(payload, cb)
|
|
return CookieLogin.save(SPEC, CookieLogin.fromPayload(payload, "bilibili.com"), cb)
|
|
end,
|
|
}
|
|
|
|
function Setting.rows()
|
|
local rows = {
|
|
CookieLogin.browserRow(),
|
|
CookieLogin.pasteRow(SPEC),
|
|
}
|
|
if loggedIn() then rows[#rows + 1] = CookieLogin.logoutRow(SPEC) end
|
|
return rows
|
|
end
|
|
|
|
function Setting.login()
|
|
CookieLogin.prompt(SPEC)
|
|
end
|
|
|
|
return Setting
|