✨ (auth): 接上登录和书架协议

邮箱、验证码和浏览器本地令牌登录。书架只收书城书,加入和删除都走官网接口。
This commit is contained in:
Garfield committed 2026-11-27 00:51:41 +08:00
1 parent 8ff04cee9b
commit 285d4cc487
5 files changed
+1117

No files matched your search

@@ -0,0 +1,92 @@
--[[--
LinguoLand 数据映射。将 API 响应转换为月读书源标准数据结构。
@module moonsource_linguoland.mapper
--]]
local Mapper = {}
local _ = require("l10n").get("moonsource_linguoland")
--- 只要字符串。JSON null 在没洗过的回包里是函数,不能进书名和简介。
local function str(value)
if type(value) == "string" and value ~= "" then return value end
end
--- 书架条目 → Book[]
---@param entries table[]
---@return table[]
function Mapper.shelfBooks(entries)
local books = {}
for _idx, entry in ipairs(entries) do
local catalog = entry.catalog
if catalog then
local storage_ref = str(catalog.storageRef) or ""
local book = {
source_id = "linguoland",
stable_id = tostring(catalog.id),
title = str(entry.titleOverride) or str(catalog.title) or _("未知书名"),
authors = str(entry.authorOverride) or str(catalog.author) or _("未知作者"),
cover = str(catalog.coverUrl) or "",
intro = str(catalog.description) or "",
category = str(catalog.level) or "",
meta = {
language = str(catalog.language),
source = {
shelf_entry_id = entry.id,
storage_ref = storage_ref,
origin = str(entry.origin),
format = str(catalog.format),
},
},
}
if storage_ref ~= "" then book._epub_url = storage_ref end
books[#books + 1] = book
end
end
return books
end
--- 书城目录条目 → Book[]
---@param items table[]
---@return table[]
function Mapper.catalogBooks(items)
local books = {}
for _idx, item in ipairs(items) do
local storage_ref = str(item.storageRef) or ""
local book = {
source_id = "linguoland",
stable_id = tostring(item.id),
title = str(item.title) or _("未知书名"),
authors = str(item.author) or _("未知作者"),
cover = str(item.coverUrl) or "",
intro = str(item.description) or "",
category = str(item.level) or "",
meta = {
language = str(item.language),
source = {
storage_ref = storage_ref,
format = str(item.format),
},
},
}
if storage_ref ~= "" then book._epub_url = storage_ref end
books[#books + 1] = book
end
return books
end
--- 合集列表 → BrowseChipGroup[]
---@param collections table[]
---@return table[]
function Mapper.collectionsToGroups(collections)
local groups = {}
for _idx, col in ipairs(collections) do
groups[#groups + 1] = {
id = tostring(col.id),
title = col.title or col.titleI18n and col.titleI18n["zh-CN"] or "",
}
end
return groups
end
return Mapper