♻️ 书源 id 去掉 ext. 前缀,沿用旧内置源数据

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
GarfieldandCopilot committed 2026-11-16 14:07:45 +08:00
1 parent b41273ef9b
commit 43d4fcfabc
11 files changed
+32 -32

No files matched your search

@@ -7,7 +7,7 @@
local _ = require("l10n").get("moonsource_kuaikan") local _ = require("l10n").get("moonsource_kuaikan")
return { return {
id = "ext.kuaikan", id = "kuaikan",
name = _("快看漫画"), name = _("快看漫画"),
type = "chapter", type = "chapter",
description = _("快看漫画在线阅读"), description = _("快看漫画在线阅读"),
@@ -71,7 +71,7 @@ end
---@param headers table|nil ---@param headers table|nil
---@return table|nil ---@return table|nil
local function withCookie(headers, cookie) local function withCookie(headers, cookie)
if cookie == nil then cookie = require("utils.settings").getSource("ext.kuaikan").cookie end if cookie == nil then cookie = require("utils.settings").getSource("kuaikan").cookie end
local saved = type(cookie) == "string" and cookie or "" local saved = type(cookie) == "string" and cookie or ""
if saved == "" then return headers end if saved == "" then return headers end
headers = headers or {} headers = headers or {}
@@ -185,7 +185,7 @@ end
---@param cookie string|nil 本轮已校验的 Cookie;缺省取当前配置 ---@param cookie string|nil 本轮已校验的 Cookie;缺省取当前配置
---@return { cancel: fun() } ---@return { cancel: fun() }
function Client.favAsync(cb, cookie) function Client.favAsync(cb, cookie)
if cookie == nil then cookie = require("utils.settings").getSource("ext.kuaikan").cookie or "" end if cookie == nil then cookie = require("utils.settings").getSource("kuaikan").cookie or "" end
local cancelled, active = false, nil local cancelled, active = false, nil
local offset, collected, seen = 0, {}, {} local offset, collected, seen = 0, {}, {}
local function nextPage() local function nextPage()
@@ -226,7 +226,7 @@ end
--- 有稳定账号身份的登录态默认同步,真实有效性由请求前的账号校验确认。 --- 有稳定账号身份的登录态默认同步,真实有效性由请求前的账号校验确认。
---@return boolean ---@return boolean
function Client.hasAccount() function Client.hasAccount()
local cfg = require("utils.settings").getSource("ext.kuaikan") local cfg = require("utils.settings").getSource("kuaikan")
return type(cfg.cookie) == "string" and cfg.cookie ~= "" return type(cfg.cookie) == "string" and cfg.cookie ~= ""
and type(cfg.user_id) == "string" and cfg.user_id ~= "" and type(cfg.user_id) == "string" and cfg.user_id ~= ""
end end
@@ -246,7 +246,7 @@ Sync.__index = Sync
---@param writing boolean|nil ---@param writing boolean|nil
---@return KuaikanSync ---@return KuaikanSync
function Client.newSync(writing) function Client.newSync(writing)
local cfg = require("utils.settings").getSource("ext.kuaikan") local cfg = require("utils.settings").getSource("kuaikan")
return setmetatable({ return setmetatable({
cookie = cfg.cookie or "", previous_cookie = cfg.cookie, user_id = cfg.user_id, cookie = cfg.cookie or "", previous_cookie = cfg.cookie, user_id = cfg.user_id,
revision = Client.login_revision, writing = writing == true, revision = Client.login_revision, writing = writing == true,
@@ -255,7 +255,7 @@ end
---@return boolean ---@return boolean
function Sync:current() function Sync:current()
local cfg = require("utils.settings").getSource("ext.kuaikan") local cfg = require("utils.settings").getSource("kuaikan")
return not self.cancelled and self.revision == Client.login_revision return not self.cancelled and self.revision == Client.login_revision
and cfg.cookie == self.previous_cookie and cfg.user_id == self.user_id and cfg.cookie == self.previous_cookie and cfg.user_id == self.user_id
and (not self.writing or self.user_id ~= nil) and (not self.writing or self.user_id ~= nil)
@@ -291,12 +291,12 @@ function Sync:checkAsync(cb)
self:request("/v2/pweb/user_info/get", function(raw, err, res) self:request("/v2/pweb/user_info/get", function(raw, err, res)
local account, reason, expired = Client.accountResponse(raw, err, res) local account, reason, expired = Client.accountResponse(raw, err, res)
if not account then if not account then
if expired then require("source.auth").expire("ext.kuaikan", reason) end if expired then require("source.auth").expire("kuaikan", reason) end
cb(nil, reason) cb(nil, reason)
elseif self.user_id and tostring(self.user_id) ~= account.user_id then elseif self.user_id and tostring(self.user_id) ~= account.user_id then
cb(nil, _("登录状态已变化,请重试")) cb(nil, _("登录状态已变化,请重试"))
else else
require("source.auth").ok("ext.kuaikan") require("source.auth").ok("kuaikan")
cb(account) cb(account)
end end
end) end)
@@ -473,7 +473,7 @@ end
---@return HttpJob ---@return HttpJob
function Client.imagesAsync(comic_id, cb) function Client.imagesAsync(comic_id, cb)
local state = { cancelled = false, job = nil } local state = { cancelled = false, job = nil }
local cfg = require("utils.settings").getSource("ext.kuaikan") local cfg = require("utils.settings").getSource("kuaikan")
local saved_cookie, saved_id, logged_in = cfg.cookie or "", cfg.user_id, cfg.logged_in == true local saved_cookie, saved_id, logged_in = cfg.cookie or "", cfg.user_id, cfg.logged_in == true
local challenged = false local challenged = false
local challenge = get(HOST .. "/v1/aegis/api/web/challenge?callback=callback_1", nil, function(_body, err, res) local challenge = get(HOST .. "/v1/aegis/api/web/challenge?callback=callback_1", nil, function(_body, err, res)
@@ -506,9 +506,9 @@ function Client.imagesAsync(comic_id, cb)
state.job = nil state.job = nil
local account, reason, expired = Client.accountResponse(account_raw, account_err, account_res) local account, reason, expired = Client.accountResponse(account_raw, account_err, account_res)
if expired then if expired then
local current = require("utils.settings").getSource("ext.kuaikan") local current = require("utils.settings").getSource("kuaikan")
if current.cookie == saved_cookie and current.user_id == saved_id then if current.cookie == saved_cookie and current.user_id == saved_id then
require("source.auth").expire("ext.kuaikan", reason) require("source.auth").expire("kuaikan", reason)
else else
reason = _("登录状态已变化,请重试") reason = _("登录状态已变化,请重试")
end end
@@ -28,7 +28,7 @@ local Login = {}
Login.__index = Login Login.__index = Login
function Login.new() function Login.new()
local cfg = require("utils.settings").getSource("ext.kuaikan") local cfg = require("utils.settings").getSource("kuaikan")
return setmetatable({ return setmetatable({
cookies = {}, serial = 0, revision = Client.login_revision, cookies = {}, serial = 0, revision = Client.login_revision,
previous_cookie = cfg.cookie, previous_id = cfg.user_id, previous_cookie = cfg.cookie, previous_id = cfg.user_id,
@@ -155,7 +155,7 @@ end
---@param cb fun(account: table|nil, err: string|nil) ---@param cb fun(account: table|nil, err: string|nil)
function Login:accept(account, cb) function Login:accept(account, cb)
local settings = require("utils.settings") local settings = require("utils.settings")
local cfg = settings.getSource("ext.kuaikan") local cfg = settings.getSource("kuaikan")
if self.revision ~= Client.login_revision or cfg.cookie ~= self.previous_cookie or cfg.user_id ~= self.previous_id then if self.revision ~= Client.login_revision or cfg.cookie ~= self.previous_cookie or cfg.user_id ~= self.previous_id then
cb(nil, _("登录状态已变化,请重试")) cb(nil, _("登录状态已变化,请重试"))
return return
@@ -164,18 +164,18 @@ function Login:accept(account, cb)
if cookie == "" then cb(nil, _("没有读到 Cookie")); return end if cookie == "" then cb(nil, _("没有读到 Cookie")); return end
if (self.previous_id and tostring(self.previous_id) ~= account.user_id) if (self.previous_id and tostring(self.previous_id) ~= account.user_id)
or (not self.previous_id and self.previous_cookie and cookie ~= CookieLogin.parse(self.previous_cookie)) then or (not self.previous_id and self.previous_cookie and cookie ~= CookieLogin.parse(self.previous_cookie)) then
local cleared = require("source.logout").clear("ext.kuaikan", function() local cleared = require("source.logout").clear("kuaikan", function()
cfg.cookie, cfg.user_id, cfg.logged_in = nil, nil, nil cfg.cookie, cfg.user_id, cfg.logged_in = nil, nil, nil
Client.login_revision = Client.login_revision + 1 Client.login_revision = Client.login_revision + 1
settings.saveSource("ext.kuaikan") settings.saveSource("kuaikan")
end) end)
if not cleared then cb(nil, _("准备本地同步失败")); return end if not cleared then cb(nil, _("准备本地同步失败")); return end
end end
cfg.cookie, cfg.user_id, cfg.logged_in = cookie, account.user_id, true cfg.cookie, cfg.user_id, cfg.logged_in = cookie, account.user_id, true
settings.saveSource("ext.kuaikan") settings.saveSource("kuaikan")
Client.login_revision = Client.login_revision + 1 Client.login_revision = Client.login_revision + 1
self.revision = Client.login_revision self.revision = Client.login_revision
require("source.auth").ok("ext.kuaikan") require("source.auth").ok("kuaikan")
cb(account) cb(account)
end end
@@ -12,7 +12,7 @@ local Text = require("utils.text")
local Mapper = {} local Mapper = {}
Mapper.TOC_VERSION = 1 Mapper.TOC_VERSION = 1
local SOURCE_ID = "ext.kuaikan" local SOURCE_ID = "kuaikan"
---@param topic_id string ---@param topic_id string
---@param comic_id string ---@param comic_id string
@@ -12,9 +12,9 @@ local Setting = {}
local COOKIE_PATHS = { ["/"] = true, ["/v2"] = true, ["/v2/"] = true, ["/v2/pweb"] = true, ["/v2/pweb/"] = true } local COOKIE_PATHS = { ["/"] = true, ["/v2"] = true, ["/v2/"] = true, ["/v2/pweb"] = true, ["/v2/pweb/"] = true }
function Setting.rowStatus() function Setting.rowStatus()
local cfg = require("utils.settings").getSource("ext.kuaikan") local cfg = require("utils.settings").getSource("kuaikan")
local on = cfg.logged_in == true and type(cfg.cookie) == "string" and cfg.cookie ~= "" local on = cfg.logged_in == true and type(cfg.cookie) == "string" and cfg.cookie ~= ""
and type(cfg.user_id) == "string" and cfg.user_id ~= "" and not require("source.auth").expired("ext.kuaikan") and type(cfg.user_id) == "string" and cfg.user_id ~= "" and not require("source.auth").expired("kuaikan")
return on and _("已登录") or _("未登录 · 点此登录"), on return on and _("已登录") or _("未登录 · 点此登录"), on
end end
@@ -109,23 +109,23 @@ function Setting.rows(plugin)
end, end,
function(iw) function(iw)
local reviews = require("source.review_setting") local reviews = require("source.review_setting")
local on = reviews.enabled("ext.kuaikan") local on = reviews.enabled("kuaikan")
return Row.widget({ width = iw, chevron = false, kind = "toggle", icon = "forum", return Row.widget({ width = iw, chevron = false, kind = "toggle", icon = "forum",
title = _("章节评论"), subtitle = _("在章末显示本章讨论,不是段落评论"), title = _("章节评论"), subtitle = _("在章末显示本章讨论,不是段落评论"),
status = on and _("开") or _("关"), status_on = on, status = on and _("开") or _("关"), status_on = on,
callback = function() callback = function()
reviews.set("ext.kuaikan", not on) reviews.set("kuaikan", not on)
if plugin and plugin.desktop then plugin.desktop:updateView() end if plugin and plugin.desktop then plugin.desktop:updateView() end
end }) end })
end, end,
} }
local cfg = require("utils.settings").getSource("ext.kuaikan") local cfg = require("utils.settings").getSource("kuaikan")
if type(cfg.cookie) == "string" and cfg.cookie ~= "" then if type(cfg.cookie) == "string" and cfg.cookie ~= "" then
rows[#rows + 1] = require("source.logout").row("ext.kuaikan", _("确定退出快看账号?"), function() rows[#rows + 1] = require("source.logout").row("kuaikan", _("确定退出快看账号?"), function()
cfg = require("utils.settings").getSource("ext.kuaikan") cfg = require("utils.settings").getSource("kuaikan")
cfg.cookie, cfg.user_id, cfg.logged_in = nil, nil, nil cfg.cookie, cfg.user_id, cfg.logged_in = nil, nil, nil
Client.login_revision = Client.login_revision + 1 Client.login_revision = Client.login_revision + 1
require("utils.settings").saveSource("ext.kuaikan") require("utils.settings").saveSource("kuaikan")
end) end)
end end
return rows return rows
+1 -1
View File
@@ -38,7 +38,7 @@ package.loaded["http.request"] = {
} }
local Chapter = require("moonsource_kuaikan.chapter") local Chapter = require("moonsource_kuaikan.chapter")
local called = false local called = false
local identity = { source_id = "ext.kuaikan", stable_id = "book" } local identity = { source_id = "kuaikan", stable_id = "book" }
local handle = Chapter.materializeAsync(identity, { uid = "1", vip = true }, nil, function() called = true end) local handle = Chapter.materializeAsync(identity, { uid = "1", vip = true }, nil, function() called = true end)
Assert.is_true(fetched) Assert.is_true(fetched)
handle.cancel() handle.cancel()
+1 -1
View File
@@ -35,7 +35,7 @@ local detail = Mapper.detail(page.info, page.nickname)
Assert.eq(detail.stable_id, "9") Assert.eq(detail.stable_id, "9")
Assert.eq(detail.authors, "翘摇") Assert.eq(detail.authors, "翘摇")
Assert.eq(detail.cover, "https://c/a.jpg") Assert.eq(detail.cover, "https://c/a.jpg")
Assert.eq(detail.source_id, "ext.kuaikan") Assert.eq(detail.source_id, "kuaikan")
Assert.eq(detail.intro, "简介") Assert.eq(detail.intro, "简介")
local toc = Mapper.chapters(page.chapters) local toc = Mapper.chapters(page.chapters)
Assert.eq(#toc, 2) Assert.eq(#toc, 2)
+1 -1
View File
@@ -36,7 +36,7 @@ source.loadTocAsync = function(_self, _identity, cb)
cb(toc) cb(toc)
return { cancel = function() cancelled.toc = true end } return { cancel = function() cancelled.toc = true end }
end end
local identity = { source_id = "ext.kuaikan", stable_id = "book" } local identity = { source_id = "kuaikan", stable_id = "book" }
local called = false local called = false
local handle = source:openBookAsync(identity, nil, function() called = true end) local handle = source:openBookAsync(identity, nil, function() called = true end)
Stubs.flush() Stubs.flush()
+1 -1
View File
@@ -29,7 +29,7 @@ function source:loadTocAsync(_identity, cb)
cb({ { uid = "11", idx = 1, title = "One" }, { uid = "22", idx = 2, title = "Two" } }) cb({ { uid = "11", idx = 1, title = "One" }, { uid = "22", idx = 2, title = "Two" } })
return { cancel = function() end } return { cancel = function() end }
end end
local identity = { source_id = "ext.kuaikan", stable_id = "review-test", chapter_idx = 1 } local identity = { source_id = "kuaikan", stable_id = "review-test", chapter_idx = 1 }
local page, err local page, err
source:paragraphReviewPageAsync(identity, "chapter", 0, function(value, reason) page, err = value, reason end) source:paragraphReviewPageAsync(identity, "chapter", 0, function(value, reason) page, err = value, reason end)
Assert.is_nil(err) Assert.is_nil(err)
+1 -1
View File
@@ -25,7 +25,7 @@ package.loaded["source.auth"] = {
expire = function() expired = true end, expire = function() expired = true end,
} }
package.loaded["source.shelf"] = { syncAsync = function(id, remote, _mapper, opts, cb) package.loaded["source.shelf"] = { syncAsync = function(id, remote, _mapper, opts, cb)
Assert.eq(id, "ext.kuaikan") Assert.eq(id, "kuaikan")
Assert.is_true(opts.force) Assert.is_true(opts.force)
Assert.is_true(remote.writing) Assert.is_true(remote.writing)
return remote:shelfSyncAsync(function(books, err) return remote:shelfSyncAsync(function(books, err)
+1 -1
View File
@@ -103,7 +103,7 @@ source.loadTocAsync = function(_self, _identity, cb)
cb(toc) cb(toc)
return { cancel = function() error("已完成目录不得覆盖当前请求") end } return { cancel = function() error("已完成目录不得覆盖当前请求") end }
end end
local identity = { source_id = "ext.kuaikan", stable_id = "9" } local identity = { source_id = "kuaikan", stable_id = "9" }
local handle = source:putProgressAsync(identity, local handle = source:putProgressAsync(identity,
{ fraction = 0.6875, chapter_idx = 2, chapter_fraction = 0.375, page = 3, total_pages = 8 }, done) { fraction = 0.6875, chapter_idx = 2, chapter_fraction = 0.375, page = 3, total_pages = 8 }, done)
reply(account) reply(account)