✨ 迁移到现行 Web 协议:签名请求、浏览器登录与分类书城
GetImageIndex / ImageToken 等接口走 ultra_sign 签名并解 bytesData; 登录改为浏览器授权或完整 Cookie,校验通过才保存。
This commit is contained in:
1 parent
430962a5d0
commit
455891353c
8 files changed
+1012
-143
No files matched your search
@@ -1,82 +1,78 @@
|
||||
--[[--
|
||||
哔哩漫画账号:浏览器授权与完整 Cookie。校验通过才保存。
|
||||
|
||||
漫画站复用哔哩哔哩主站会话。已购和大会员话由详情里的 is_locked 表示,
|
||||
不在这里另做会员开关。
|
||||
|
||||
@module moonsource_bilimanga.setting
|
||||
--]]
|
||||
|
||||
local CookieLogin = require("source.cookie_login")
|
||||
local _ = require("moonsource_bilimanga.l10n")
|
||||
|
||||
local ID = "bilimanga"
|
||||
local SOURCE_ID = "bilimanga"
|
||||
local Setting = {}
|
||||
|
||||
local function entries(desktop)
|
||||
return { {
|
||||
group = "network",
|
||||
order = 100,
|
||||
id = "login",
|
||||
icon = "d_overwrite_feature",
|
||||
title = _("哔哩哔哩漫画"),
|
||||
page = {
|
||||
title = _("哔哩哔哩漫画"),
|
||||
sections = function()
|
||||
local cfg = require("utils.settings").getSource(ID)
|
||||
local has_cookie = cfg.cookie and cfg.cookie ~= ""
|
||||
|
||||
local function doLogin()
|
||||
require("ui/modal").input({
|
||||
title = _("请输入 SESSDATA Cookie"),
|
||||
button = _("登录"),
|
||||
text = cfg.cookie or "",
|
||||
hint = "SESSDATA",
|
||||
hint_is_field = true,
|
||||
}, function(entry)
|
||||
if not entry or entry == "" then return end
|
||||
require("utils.settings").saveSource(ID, {
|
||||
cookie = entry,
|
||||
})
|
||||
require("ui/uimanager"):popMenu()
|
||||
local Toast = require("ui/themed").Toast
|
||||
Toast:new({
|
||||
text = _("已登录"),
|
||||
timeout = 2,
|
||||
}):show()
|
||||
desktop:onEvent("book_source_refresh")
|
||||
end)
|
||||
end
|
||||
|
||||
local function doClear()
|
||||
require("utils.settings").saveSource(ID, {
|
||||
cookie = "",
|
||||
})
|
||||
require("ui/uimanager"):popMenu()
|
||||
local Toast = require("ui/themed").Toast
|
||||
Toast:new({
|
||||
text = _("已清除 Cookie"),
|
||||
timeout = 2,
|
||||
}):show()
|
||||
desktop:onEvent("book_source_refresh")
|
||||
end
|
||||
|
||||
local rows = { {
|
||||
fn = function()
|
||||
return require("desktop.pages.setting.tree").Row.action({
|
||||
text = has_cookie and _("已登录") or _("未登录"),
|
||||
callback = doLogin,
|
||||
})
|
||||
end,
|
||||
} }
|
||||
|
||||
if has_cookie then
|
||||
rows[#rows + 1] = {
|
||||
fn = function()
|
||||
return require("desktop.pages.setting.tree").Row.action({
|
||||
text = _("清除"),
|
||||
callback = doClear,
|
||||
})
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
return { {
|
||||
title = "",
|
||||
rows = rows,
|
||||
} }
|
||||
end,
|
||||
},
|
||||
} }
|
||||
local function loggedIn()
|
||||
local cfg = require("utils.settings").getSource(SOURCE_ID)
|
||||
return type(cfg.cookie) == "string" and cfg.cookie ~= ""
|
||||
end
|
||||
|
||||
return { entries = entries }
|
||||
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
|
||||
Reference in new issue
Block a user