This commit is contained in:
commit
994167fbe5
50 files changed
+18324
No files matched your search
@@ -0,0 +1,86 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
# 推送 vX.Y.Z(或 vX.Y.Z-rc.1 等预发布)标签:打包本仓库的插件为 zip → 建 Release 并上传。
|
||||||
|
# 更新日志取自 CHANGELOG.md 里 "## <版本号>" 这一节,作为 Release 说明(月读的更新弹窗也会显示)。
|
||||||
|
# 令牌默认用内置 GITHUB_TOKEN;需要时可在仓库密钥里配 RELEASE_TOKEN 覆盖。
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: gitea
|
||||||
|
container:
|
||||||
|
image: node:22-bookworm
|
||||||
|
steps:
|
||||||
|
# 实例内网地址在任务容器里解析不了,签出和 API 都走公网地址
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
github-server-url: https://git.garfieldho.me
|
||||||
|
|
||||||
|
- name: Resolve version
|
||||||
|
id: ver
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
TAG="${GITHUB_REF_NAME}"
|
||||||
|
VERSION="${TAG#v}"
|
||||||
|
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.+-].*)?$ ]]; then
|
||||||
|
echo "标签不合法:${TAG}(应为 vMAJOR.MINOR.PATCH)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
PRERELEASE=false
|
||||||
|
[[ "$VERSION" == *-* ]] && PRERELEASE=true
|
||||||
|
{
|
||||||
|
echo "tag=${TAG}"
|
||||||
|
echo "version=${VERSION}"
|
||||||
|
echo "prerelease=${PRERELEASE}"
|
||||||
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Install packaging tools
|
||||||
|
run: apt-get update && apt-get install -y -o Acquire::Retries=3 rsync zip
|
||||||
|
|
||||||
|
- name: Package plugin
|
||||||
|
run: tools/package.sh "${{ steps.ver.outputs.version }}" dist
|
||||||
|
|
||||||
|
- name: Create release and upload assets
|
||||||
|
env:
|
||||||
|
TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
|
||||||
|
TAG: ${{ steps.ver.outputs.tag }}
|
||||||
|
PRERELEASE: ${{ steps.ver.outputs.prerelease }}
|
||||||
|
VERSION: ${{ steps.ver.outputs.version }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
: "${TOKEN:?没有可用令牌:没有内置令牌,也没有配置 RELEASE_TOKEN}"
|
||||||
|
API="https://git.garfieldho.me/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||||
|
AUTH="Authorization: token ${TOKEN}"
|
||||||
|
|
||||||
|
# 同一标签重跑:删掉旧 Release 再建,附件不会重复
|
||||||
|
OLD=$(curl -fsS -H "$AUTH" "${API}/releases/tags/${TAG}" 2>/dev/null | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{console.log(JSON.parse(s).id||"")}catch(e){}})' || true)
|
||||||
|
[ -n "$OLD" ] && curl -fsS -X DELETE -H "$AUTH" "${API}/releases/${OLD}"
|
||||||
|
|
||||||
|
BODY=$(node -e '
|
||||||
|
const fs = require("fs");
|
||||||
|
let notes = "";
|
||||||
|
try {
|
||||||
|
const lines = fs.readFileSync("CHANGELOG.md", "utf8").split(/\r?\n/);
|
||||||
|
const start = lines.findIndex(l => l.trim() === "## " + process.env.VERSION);
|
||||||
|
if (start >= 0) {
|
||||||
|
let end = lines.findIndex((l, i) => i > start && /^## /.test(l));
|
||||||
|
if (end < 0) end = lines.length;
|
||||||
|
notes = lines.slice(start + 1, end).join("\n").trim();
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
const tail = "给月读增加在线平台书源的 KOReader 插件。把 zip 解压到 KOReader 的 plugins/ 目录即可,附件 SHA256SUMS 用于校验。与各平台官方无关,使用风险自行承担。";
|
||||||
|
console.log(JSON.stringify({tag_name:process.env.TAG,name:process.env.TAG,prerelease:process.env.PRERELEASE==="true",body:notes?notes+"\n\n---\n"+tail:tail}));
|
||||||
|
')
|
||||||
|
ID=$(curl -fsS -X POST -H "$AUTH" -H "Content-Type: application/json" -d "$BODY" "${API}/releases" \
|
||||||
|
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>console.log(JSON.parse(s).id))')
|
||||||
|
|
||||||
|
for f in dist/*; do
|
||||||
|
echo "upload $(basename "$f")"
|
||||||
|
curl -fsS -X POST -H "$AUTH" -F "attachment=@${f}" "${API}/releases/${ID}/assets?name=$(basename "$f")" >/dev/null
|
||||||
|
done
|
||||||
|
shell: bash
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
.DS_Store
|
||||||
|
*.swp
|
||||||
|
dist/
|
||||||
|
.idea/
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# 更新日志
|
||||||
|
|
||||||
|
## 0.0.1
|
||||||
|
|
||||||
|
- 「Kavita」书源拆成独立仓库,独立发版、独立更新;原来所有书源同版本一起更新的做法取消。
|
||||||
|
- 检查更新与自动更新只管本书源:月读「书库 → 更新」里每个书源各有一项,只提示、不静默安装,装完重启 KOReader。
|
||||||
|
- 书源 id、书架、进度、登录配置和缓存沿用原有数据,从旧版覆盖安装即可,无需迁移。
|
||||||
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
# 月读书源:Kavita
|
||||||
|
|
||||||
|
给月读增加「Kavita」在线书源的 KOReader 插件。本仓库只含这一个插件,独立维护、独立发版,全部书源见 [moon-source 组织](https://git.garfieldho.me/moon-source)。
|
||||||
|
|
||||||
|
## 免责声明
|
||||||
|
|
||||||
|
- 本仓库与「Kavita」官方**没有任何关联**,所有商标、书名、内容归原权利人所有。
|
||||||
|
- 插件只是在用户自己的账号、自己的设备上,按用户本人已有的权限读取内容;不提供、不分发任何书籍内容,也不绕过付费。
|
||||||
|
- 使用可能违反对应平台的用户协议,账号可能被限制或封禁。是否使用、风险如何,由使用者自行判断并承担。
|
||||||
|
- 权利人认为本仓库内容有问题,请通过仓库 issue 联系,核实后会及时处理。
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
1. 先装好月读。
|
||||||
|
2. 从 [Release](../../releases) 下载 `moonsource-kavita.koplugin-<版本>.zip`,解压出 `moonsource-kavita.koplugin` 目录,整个复制到 KOReader 的 `plugins/` 下。
|
||||||
|
3. 重启 KOReader,在月读的书源列表里启用。
|
||||||
|
|
||||||
|
书源 id 是 `kavita`,与旧版(合并仓库、内置书源)相同,书架、进度、登录配置、缓存沿用原有数据,无需迁移。
|
||||||
|
|
||||||
|
## 更新
|
||||||
|
|
||||||
|
在月读的「书库 → Kavita 更新」里有「检查书源插件更新」和「自动检查书源插件更新」(默认开,每 24 小时一次,只提示、不静默安装)。
|
||||||
|
本插件只检查并更新自己(本仓库的 Release),校验值取自 Release 的 `SHA256SUMS`,装完重启 KOReader。
|
||||||
|
|
||||||
|
> 从旧的合并仓库 `GarfieldTony/moon-source` 迁移:旧仓库的更新入口已停用,请直接从本仓库下载最新包覆盖安装。
|
||||||
|
|
||||||
|
## 发布
|
||||||
|
|
||||||
|
推送 `vX.Y.Z` 标签(带 `-` 的如 `v1.2.0-rc.1` 为预发布),Forgejo Actions 会打包 `moonsource-kavita.koplugin-<版本>.zip`,连同 `SHA256SUMS` 上传到 Release。
|
||||||
|
更新日志写在 `CHANGELOG.md`,格式是 `## <版本号>` 一节,发布时取对应小节作为 Release 说明(月读的更新弹窗也会显示)。无需配置密钥,默认用内置令牌。本地打包:`tools/package.sh <版本> [输出目录]`。
|
||||||
|
|
||||||
|
## 测试
|
||||||
|
|
||||||
|
离线单元测试复用月读仓库的测试运行器(需要 luajit):
|
||||||
|
|
||||||
|
```sh
|
||||||
|
MOON_DIR=/path/to/moon tools/run-tests.sh # 全部
|
||||||
|
MOON_DIR=/path/to/moon tools/run-tests.sh tests/kavita/xxx_spec.lua
|
||||||
|
```
|
||||||
|
|
||||||
|
## 公共文件
|
||||||
|
|
||||||
|
`<包名>/update.lua`、`tools/package.sh`、`tools/run-tests.sh`、`.github/workflows/release.yml`、`tests/update/update_spec.lua` 由 [moonsource-template](https://git.garfieldho.me/moon-source/moonsource-template) 同步,请改模板仓库,不要在这里手改。
|
||||||
|
|
||||||
|
## 许可
|
||||||
|
|
||||||
|
见 [LICENSE](LICENSE)。
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
local _ = require("gettext")
|
||||||
|
return {
|
||||||
|
fullname = _("月读书源:Kavita"),
|
||||||
|
description = _("给月读增加「Kavita」书源。需要同时安装月读,与平台官方无关。"),
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
--[[--
|
||||||
|
KOReader 只认带 main.lua 的插件目录;书源本身不需要任何插件钩子,月读读取旁边的 moon_source.lua。
|
||||||
|
--]]
|
||||||
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||||
|
|
||||||
|
return WidgetContainer:extend{
|
||||||
|
name = "moonsource_kavita",
|
||||||
|
is_doc_only = false,
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
--[[--
|
||||||
|
月读第三方书源描述:Kavita。契约见月读 examples/moonsource-demo.koplugin/moon_source.lua。
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local function lazy(module)
|
||||||
|
return setmetatable({}, { __index = function(_, key) return require(module)[key] end })
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
api = 1,
|
||||||
|
provides = {
|
||||||
|
source = true,
|
||||||
|
home_widgets = { require("moonsource_kavita.on_deck") },
|
||||||
|
},
|
||||||
|
meta = function() return require("moonsource_kavita.source").meta() end,
|
||||||
|
new = function() return require("moonsource_kavita.source").new() end,
|
||||||
|
setting = lazy("moonsource_kavita.setting"),
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Kavita
|
||||||
|
|
||||||
|
| 能力 | 是否支持 | 备注 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 服务连接 | 支持 | Kavita 0.9 或更新版本;填写地址、API Key 并选择书库 |
|
||||||
|
| 书架拉取 | 支持 | 分页读取系列;多卷系列打开时选择卷 |
|
||||||
|
| 加入与移出远端书架 | 不支持 | 书架只读;本地删除不操作服务器藏书 |
|
||||||
|
| 详情与封面 | 支持 | 读取书库、系列及作者等元数据 |
|
||||||
|
| 整本下载与阅读 | 支持 | EPUB、PDF、CBZ 等 KOReader 支持的格式 |
|
||||||
|
| 漫画在线阅读与缓存 | 部分支持 | 依赖兼容的 kamare 增强版;无增强接口时 CBZ 可下载阅读,图片目录不能同样回退 |
|
||||||
|
| 阅读进度同步 | 支持 | 按卷保存;EPUB 使用 spine/锚点,固定版式使用页码 |
|
||||||
|
| 划线与备注同步 | 部分支持 | 仅 EPUB;依赖本地内容和坐标定位 |
|
||||||
|
| 阅读统计同步 | 部分支持 | 拉取历史快照;进度心跳可记入会话时长,不上传本地统计集合 |
|
||||||
|
| 整书书评 | 已实现,未实测 | 系列级书评,卷共享所属系列缓存;受服务器版本、Kavita+ 及外部评价权限影响 |
|
||||||
|
| 章评与段评 | 不支持 | 未接入可验证的读取接口;服务器存在章节评价模型,不等于插件已接入 |
|
||||||
|
| 评论回复与写操作 | 不支持 | 不发评、不改评分 |
|
||||||
|
| 离线阅读 | 支持 | 已下载文件及目录可用;漫画缓存取决于 kamare |
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
--[[--
|
||||||
|
书源元信息:id / 名称 / 类型,加上启用页展示用的说明与能力清单。`init.lua` 的 `meta()` 直接返回本表。
|
||||||
|
|
||||||
|
@module moonsource_kavita._meta
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
|
||||||
|
return {
|
||||||
|
id = "kavita",
|
||||||
|
name = _("Kavita"),
|
||||||
|
type = "book",
|
||||||
|
description = _("同步 Kavita 书架、电子书与漫画"),
|
||||||
|
abilities = { _("书架与卷目录同步(只读)"), _("进度同步"), _("EPUB 划线同步"), _("阅读历史拉取"),
|
||||||
|
_("漫画在线阅读与缓存(需 kamare 增强版)"), _("书评") },
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita 注解的线上形态与同一性:纯函数、无 IO,pull / push / delete 共用同一条口径。
|
||||||
|
|
||||||
|
Kavita 网页端把备注存成 Quill Delta JSON(`comment`)+ Quill HTML(`commentHtml`),
|
||||||
|
纯文本 `commentPlainText` 是**后端从 HTML 去标签**算出来的(块级标签不插分隔,有损)。
|
||||||
|
读回、写入、冲突判定三处必须共用这里的归一,否则同一段备注每轮都会被判「改过」→ 无限 update。
|
||||||
|
|
||||||
|
@module moonsource_kavita.annotation
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local JSON = require("json")
|
||||||
|
local Text = require("utils.text")
|
||||||
|
|
||||||
|
local Annotation = {}
|
||||||
|
|
||||||
|
--- 键分隔符用 US(0x1F):Kavita 的路径与选中文本里不会出现,天然不可撞。
|
||||||
|
--- 导出是为了让源侧拼「同坐标」判定键时用同一个字符,不各写一份字面量。
|
||||||
|
Annotation.KEY_SEP = string.char(31)
|
||||||
|
|
||||||
|
--- 排版上不可见、但字节上会破坏比较的字符:ZWSP / ZWNJ / ZWJ / BOM / WORD JOINER。
|
||||||
|
local ZERO_WIDTH = { "\226\128\139", "\226\128\140", "\226\128\141", "\239\187\191", "\226\129\160" }
|
||||||
|
|
||||||
|
--- 写入前的归一:`\r\n` → `\n`、去掉尾部换行;纯空白在调用方判空。
|
||||||
|
---@param note string|nil
|
||||||
|
---@return string
|
||||||
|
local function normalizeNote(note)
|
||||||
|
return (Text.normalizeNewlines(note):gsub("\n+$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 比较用归一:trim + 内部连续空白压成单空格 + 剔除零宽字符。
|
||||||
|
--- 只用于「是不是同一段备注」,不能拿它落库(会把用户的换行/缩进抹平)。
|
||||||
|
---@param s string|nil
|
||||||
|
---@return string
|
||||||
|
local function comparisonText(s)
|
||||||
|
local text = tostring(s or ""):gsub("\r\n", "\n"):gsub("\r", "\n")
|
||||||
|
for _idx, zw in ipairs(ZERO_WIDTH) do text = text:gsub(zw, "") end
|
||||||
|
return (text:gsub("%s+", " "):gsub("^%s+", ""):gsub("%s+$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Delta → 纯文本:`ops[*].insert` 里的字符串拼接,embed(图片等)与 `attributes` 一律忽略。
|
||||||
|
--- 末尾换行是 Delta 文档的收尾,不是内容;拼完剥掉。
|
||||||
|
---@param data table
|
||||||
|
---@return string
|
||||||
|
local function deltaText(data)
|
||||||
|
local ops = data.ops
|
||||||
|
if type(ops) ~= "table" then return "" end
|
||||||
|
local parts = {}
|
||||||
|
for _idx, op in ipairs(ops) do
|
||||||
|
if type(op) == "table" and type(op.insert) == "string" then
|
||||||
|
parts[#parts + 1] = op.insert
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return (table.concat(parts):gsub("\n+$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- HTML → 纯文本:块级边界(`</p>` / `</div>` / `<br>`)换行,其余标签丢弃,实体解码。
|
||||||
|
--- 不能直接用 Text.stripHtml:它会丢弃空行,而备注里的空行是内容。
|
||||||
|
---@param html string
|
||||||
|
---@return string
|
||||||
|
local function htmlText(html)
|
||||||
|
local text = tostring(html or ""):gsub("\r\n", "\n"):gsub("\r", "\n")
|
||||||
|
-- Quill 的空行是 `<p><br></p>`:先整个折成一个换行,否则 <br> 与 </p> 会各补一行。
|
||||||
|
text = text:gsub("<p[^>]*>%s*<br%s*/?>%s*</p>", "\n")
|
||||||
|
text = text:gsub("<br%s*/?>", "\n"):gsub("</p%s*>", "\n"):gsub("</div%s*>", "\n")
|
||||||
|
text = text:gsub("<[^>]*>", "")
|
||||||
|
-- Quill 把连续空格写成 ,解出来是 NBSP,还原成普通空格才能与本地文本对上。
|
||||||
|
text = Text.xmlDecode(text):gsub("\194\160", " ")
|
||||||
|
return (text:gsub("\n+$", ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 读回归一。优先级:commentHtml → commentPlainText → comment 的 Delta → comment 原文(legacy 纯文本)。
|
||||||
|
--- 空值集合("" / "{}" / {"ops":[]} / {"ops":[{"insert":"\n"}]} / null)一律 ""。
|
||||||
|
---@param comment string|nil
|
||||||
|
---@param comment_html string|nil
|
||||||
|
---@param comment_plain_text string|nil
|
||||||
|
---@return string
|
||||||
|
function Annotation.noteText(comment, comment_html, comment_plain_text)
|
||||||
|
if type(comment_html) == "string" and Text.trim(comment_html) ~= "" then
|
||||||
|
return htmlText(comment_html)
|
||||||
|
end
|
||||||
|
if type(comment_plain_text) == "string" and Text.trim(comment_plain_text) ~= "" then
|
||||||
|
-- 后端 StripHtml 的产物,块间无分隔;这里只需去首尾空白。
|
||||||
|
return Text.trim(comment_plain_text)
|
||||||
|
end
|
||||||
|
local raw = tostring(comment or "")
|
||||||
|
if Text.trim(raw) == "" or Text.trim(raw) == "null" then return "" end
|
||||||
|
local ok, data = pcall(JSON.decode, raw)
|
||||||
|
-- json.decode 失败 = 存量纯文本备注(网页端 JSON.parse 会崩,但设备侧要能读)。
|
||||||
|
if not ok then return raw end
|
||||||
|
if data == nil then return "" end
|
||||||
|
if type(data) ~= "table" then return tostring(data) end
|
||||||
|
local text = deltaText(data)
|
||||||
|
if text:match("^%s*$") then return "" end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 写回归一(create / update 共用):与 Web 同构,`comment` 为 Quill Delta JSON、`commentHtml` 为对应 HTML。
|
||||||
|
--- 空备注写 `"{}"` + `""`(Web「新建未输入」的原样),否则网页端 `JSON.parse(comment)` 会崩。
|
||||||
|
---@param note string|nil
|
||||||
|
---@return { comment: string, commentHtml: string }
|
||||||
|
function Annotation.toRemote(note)
|
||||||
|
local text = normalizeNote(note)
|
||||||
|
if text:match("^%s*$") then
|
||||||
|
return { comment = "{}", commentHtml = "" }
|
||||||
|
end
|
||||||
|
local lines = {}
|
||||||
|
for line in (text .. "\n"):gmatch("([^\n]*)\n") do
|
||||||
|
lines[#lines + 1] = line == "" and "<p><br></p>" or ("<p>" .. Text.xmlEscape(line) .. "</p>")
|
||||||
|
end
|
||||||
|
return {
|
||||||
|
comment = JSON.encode({ ops = { { insert = text .. "\n" } } }),
|
||||||
|
commentHtml = table.concat(lines),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 幂等键(spec §8.2):`<chapterId>\31<xPath>\31<endingXPath>\31<selectedText>`。
|
||||||
|
--- `comment` 不进键(备注可改,进键会把「改备注」变成「新建」);`selectedText` 用比较归一,
|
||||||
|
--- 否则网页端/设备端的换行差异会让同一条划线认不出来(落库仍存原文)。
|
||||||
|
--- 字段名两套都要认:线上 DTO 用 `xPath` / `endingXPath` / `selectedText`,落库后的 payload
|
||||||
|
--- (阅读器快照、远端去重的输入)用 `kavita_xpath` / `kavita_ending_xpath` / `text`。
|
||||||
|
---@param ann { chapterId: integer|nil, xPath: string|nil, endingXPath: string|nil, selectedText: string|nil, kavita_xpath: string|nil, kavita_ending_xpath: string|nil, text: string|nil }
|
||||||
|
---@return string
|
||||||
|
function Annotation.key(ann)
|
||||||
|
local selected = ann.selectedText
|
||||||
|
if selected == nil then selected = ann.text end
|
||||||
|
return table.concat({
|
||||||
|
tostring(ann.chapterId or ""),
|
||||||
|
tostring(ann.xPath or ann.kavita_xpath or ""),
|
||||||
|
tostring(ann.endingXPath or ann.kavita_ending_xpath or ""),
|
||||||
|
comparisonText(selected),
|
||||||
|
}, Annotation.KEY_SEP)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 在对账列表里找本地这条注解的远端对应:同键多条取 id 最小(网页端重扫可能留下重复),
|
||||||
|
--- 没有 id 的条目没法采纳,直接跳过。
|
||||||
|
---@param remote table[]|nil
|
||||||
|
---@param ann table
|
||||||
|
---@return table|nil
|
||||||
|
function Annotation.match(remote, ann)
|
||||||
|
if type(remote) ~= "table" then return nil end
|
||||||
|
local wanted = Annotation.key(ann)
|
||||||
|
local best, best_id
|
||||||
|
for _idx, item in ipairs(remote) do
|
||||||
|
local id = type(item) == "table" and tonumber(item.id)
|
||||||
|
if id and (not best_id or id < best_id) and Annotation.key(item) == wanted then
|
||||||
|
best, best_id = item, id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return best
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 比较两段备注是不是同一段:trim、内部连续空白压成单空格、剔除零宽字符,两边都空判等。
|
||||||
|
--- push / pull / 冲突裁决共用;不能拿它落库(换行与缩进会被抹平)。
|
||||||
|
---@param a string|nil
|
||||||
|
---@param b string|nil
|
||||||
|
---@return boolean
|
||||||
|
function Annotation.sameNote(a, b)
|
||||||
|
return comparisonText(a) == comparisonText(b)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- owner 比较:远端 id 是数字,调用方可能拿到字符串(配置/`/api/Users/me` 解析),两边能对上。
|
||||||
|
---@param a any
|
||||||
|
---@param b any
|
||||||
|
---@return boolean
|
||||||
|
local function sameOwner(a, b)
|
||||||
|
local na, nb = tonumber(a), tonumber(b)
|
||||||
|
if na and nb then return na == nb end
|
||||||
|
return tostring(a) == tostring(b)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 该章全部注解(`GET /api/Annotation/all`,无分页)。`owner_id` 非空时只留自己的:
|
||||||
|
--- 账号开了「查看他人注解」后接口会混入别人的条目,删改别人的会整批 400。
|
||||||
|
---@param client KavitaClient
|
||||||
|
---@param chapter_id integer
|
||||||
|
---@param owner_id integer|string|nil nil / "" = 拿不到当前用户时的降级:不过滤
|
||||||
|
---@param cb fun(list: table[]|nil, err: string|nil)
|
||||||
|
---@return HttpJob|nil
|
||||||
|
function Annotation.listByChapter(client, chapter_id, owner_id, cb)
|
||||||
|
return client:json("GET", "/api/Annotation/all", { chapterId = chapter_id }, nil, function(data, err)
|
||||||
|
if not data then return cb(nil, err) end
|
||||||
|
local filter = owner_id ~= nil and owner_id ~= ""
|
||||||
|
local out = {}
|
||||||
|
for _idx, item in ipairs(type(data) == "table" and data or {}) do
|
||||||
|
if type(item) == "table" and (not filter or sameOwner(item.ownerUserId, owner_id)) then
|
||||||
|
out[#out + 1] = item
|
||||||
|
end
|
||||||
|
end
|
||||||
|
cb(out)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Annotation
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
--[[--
|
||||||
|
同步阻塞操作期间的忙碌窗:kamare 的缓存操作直接写盘,主线程会停住。
|
||||||
|
先把窗画出来、强制重绘一次,再动手;返回后关窗。
|
||||||
|
|
||||||
|
调用方只给标题与要跑的函数;`fn` 的返回值原样透传(最多四个)。
|
||||||
|
关闭失败不会发生:窗在建好后才交给 UIManager。
|
||||||
|
|
||||||
|
@module moonsource_kavita.busy
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
|
||||||
|
local Busy = {}
|
||||||
|
|
||||||
|
---@param title string 窗标题(一般是动作名,如「清理已读」)
|
||||||
|
---@param fn fun(): any
|
||||||
|
---@return any, any, any, any
|
||||||
|
function Busy.run(title, fn)
|
||||||
|
local UIManager = require("ui/uimanager")
|
||||||
|
local dialog = require("ui.themes.widgets.progress_dialog"):new{
|
||||||
|
title = title,
|
||||||
|
text = _("正在清理…"),
|
||||||
|
dismissable = false,
|
||||||
|
}
|
||||||
|
local ok, code, message, detail = dialog:showWhile(function()
|
||||||
|
if UIManager.forceRePaint then UIManager:forceRePaint() end
|
||||||
|
return fn()
|
||||||
|
end)
|
||||||
|
dialog:close()
|
||||||
|
return ok, code, message, detail
|
||||||
|
end
|
||||||
|
|
||||||
|
return Busy
|
||||||
@@ -0,0 +1,912 @@
|
|||||||
|
--[[--
|
||||||
|
kamare 漫画缓存适配层:探测、能力门面、配置镜像、错误文案、书架投影、删除保护。
|
||||||
|
|
||||||
|
kamare 是缓存的唯一执行者与写入者;moon 只读状态、发下载 / 删除 / 队列请求。
|
||||||
|
kamare 的模块一律在函数内 `pcall(require, …)`,绝不顶层 require、也不持有它的 table:
|
||||||
|
插件升级 / 重载后旧 table 会失效。探测成功结果进程内记忆,失败不记忆(require 自带缓存)。
|
||||||
|
|
||||||
|
@module moonsource_kavita.cache
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
local T = require("ffi/util").template
|
||||||
|
local logger = require("utils.log")
|
||||||
|
local Text = require("utils.text")
|
||||||
|
|
||||||
|
local Cache = {}
|
||||||
|
|
||||||
|
---@class KamareProbe
|
||||||
|
---@field ok boolean
|
||||||
|
---@field state "missing"|"official"|"incompatible"|"enhanced"
|
||||||
|
---@field reason string|nil
|
||||||
|
---@field api_version integer|nil
|
||||||
|
---@field capabilities table|nil
|
||||||
|
---@field version string|nil
|
||||||
|
---@field path string|nil
|
||||||
|
|
||||||
|
--- 成功探测的记忆(只存元信息,不存模块 table)。
|
||||||
|
---@type KamareProbe|nil
|
||||||
|
local memo
|
||||||
|
|
||||||
|
--- 当前进程内已镜像过的配置(base_url\0api_key),失败不写。
|
||||||
|
---@type string|nil
|
||||||
|
local mirrored
|
||||||
|
|
||||||
|
--- 本次会话的镜像是否失败过(设置页第五态)。
|
||||||
|
local mirror_failed = false
|
||||||
|
|
||||||
|
--- 一次性日志的去重键(同一原因只记一行,状态变化才再记)。
|
||||||
|
local logged = {}
|
||||||
|
|
||||||
|
--- 当前打开的章(kamare 保证同一时刻只有一个 viewer)。
|
||||||
|
---@type { base_url: string|nil, chapter_id: any }|nil
|
||||||
|
local active
|
||||||
|
|
||||||
|
--- 书架投影记忆,按服务器分开;只由成功写操作 / 手动刷新 / Registry.reload 失效。
|
||||||
|
---@type table<string, ShelfCacheProjection>
|
||||||
|
local shelves = {}
|
||||||
|
|
||||||
|
--- 上次记录过的暂停原因(按服务器),轮询时只在变化时写日志。
|
||||||
|
---@type table<string, string>
|
||||||
|
local pause_reason_logged = {}
|
||||||
|
|
||||||
|
--- 记一行日志;同一 key 在本进程内只记一次。
|
||||||
|
---@param key string
|
||||||
|
---@param text string
|
||||||
|
local function logOnce(key, text)
|
||||||
|
if logged[key] then return end
|
||||||
|
logged[key] = true
|
||||||
|
logger.info(text)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 能力名清单(排序后按分隔符拼接),日志与设置页共用一份口径。
|
||||||
|
---@param capabilities table|nil
|
||||||
|
---@param separator string|nil 缺省逗号(日志);设置页传「、」
|
||||||
|
---@return string
|
||||||
|
function Cache.capabilityNames(capabilities, separator)
|
||||||
|
local names = {}
|
||||||
|
for name, on in pairs(type(capabilities) == "table" and capabilities or {}) do
|
||||||
|
if on == true then names[#names + 1] = tostring(name) end
|
||||||
|
end
|
||||||
|
table.sort(names)
|
||||||
|
if #names == 0 then return "none" end
|
||||||
|
return table.concat(names, separator or ",")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 探测结果每进程(每种结果)一行:四态 + 版本 + 能力;不记 API Key。
|
||||||
|
---@param probe KamareProbe
|
||||||
|
local function logProbe(probe)
|
||||||
|
local capabilities = Cache.capabilityNames(probe.capabilities)
|
||||||
|
local signature = string.format("probe|%s|%s|%s", probe.state, tostring(probe.version), capabilities)
|
||||||
|
logOnce(signature, string.format("kamare probe ok=%s state=%s version=%s caps=%s",
|
||||||
|
tostring(probe.ok), probe.state, tostring(probe.version), capabilities))
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param ids any
|
||||||
|
---@return string
|
||||||
|
local function joinIds(ids)
|
||||||
|
if type(ids) ~= "table" then return "-" end
|
||||||
|
local parts = {}
|
||||||
|
for _idx, id in ipairs(ids) do parts[#parts + 1] = tostring(id) end
|
||||||
|
return #parts > 0 and table.concat(parts, ",") or "-"
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 每次缓存写操作一行:<op> + 章 id + code(成功记 ok)。
|
||||||
|
---@param op string
|
||||||
|
---@param ids any
|
||||||
|
---@param code string|nil
|
||||||
|
local function logWrite(op, ids, code)
|
||||||
|
logger.info("cache " .. op .. " cid=" .. joinIds(ids) .. " code=" .. tostring(code or "ok"))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 目录条目 → chapterId 列表(只用于日志)。
|
||||||
|
---@param entries table|nil
|
||||||
|
---@return table
|
||||||
|
local function entryIds(entries)
|
||||||
|
local ids = {}
|
||||||
|
for _idx, entry in ipairs(type(entries) == "table" and entries or {}) do
|
||||||
|
if type(entry) == "table" then
|
||||||
|
ids[#ids + 1] = entry.chapterId or entry.chapter_id or entry.id or "?"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ids
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 函数内 require:拿不到就 nil,不抛错。
|
||||||
|
---@param name string
|
||||||
|
---@return table|nil
|
||||||
|
local function loadModule(name)
|
||||||
|
local ok, mod = pcall(require, name)
|
||||||
|
if ok and type(mod) == "table" then return mod end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 本地封面文件存在才算数(缓存可能已被 kamare 清理)。
|
||||||
|
---@param path any
|
||||||
|
---@return boolean
|
||||||
|
local function fileExists(path)
|
||||||
|
if type(path) ~= "string" or path == "" then return false end
|
||||||
|
local file = io.open(path, "rb")
|
||||||
|
if not file then return false end
|
||||||
|
file:close()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 官方 / 旧版 kamare 的查看器是否可用(legacy 通道的触发条件)。
|
||||||
|
---@return boolean
|
||||||
|
local function legacyAvailable()
|
||||||
|
local viewer = loadModule("kamareimageviewer")
|
||||||
|
return type(viewer) == "table" and type(viewer.new) == "function"
|
||||||
|
end
|
||||||
|
|
||||||
|
--- `kamareversion` 返回字符串(发布时写入);老写法可能是表。
|
||||||
|
---@return string|nil
|
||||||
|
local function kamareVersion()
|
||||||
|
local ok, value = pcall(require, "kamareversion")
|
||||||
|
if not ok then return nil end
|
||||||
|
if type(value) == "string" and value ~= "" then return value end
|
||||||
|
if type(value) == "table" then
|
||||||
|
local version = value.version or value.VERSION
|
||||||
|
if type(version) == "string" and version ~= "" then return version end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 模块文件路径:借任一公开函数反查,不扫 package.path。
|
||||||
|
--- 归一重复斜杠:KOReader 的 `extra_plugin_paths` 带尾斜杠,data 目录里的插件会被拼成
|
||||||
|
--- `plugins//kamare.koplugin`,原样显示会让人以为路径写错了(文件系统本身不介意)。
|
||||||
|
---@param mod table
|
||||||
|
---@return string|nil
|
||||||
|
local function modulePath(mod)
|
||||||
|
for _idx, name in ipairs({ "status", "summary", "enqueue", "delete", "open" }) do
|
||||||
|
if type(mod[name]) == "function" then
|
||||||
|
local ok, info = pcall(debug.getinfo, mod[name], "S")
|
||||||
|
local source = ok and info and info.source
|
||||||
|
if type(source) == "string" and source:sub(1, 1) == "@" then
|
||||||
|
return (source:sub(2):gsub("/+", "/"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param mod table
|
||||||
|
---@return KamareProbe
|
||||||
|
local function enhancedProbe(mod)
|
||||||
|
local api_version = tonumber(mod.api_version)
|
||||||
|
local capabilities = type(mod.capabilities) == "table" and mod.capabilities or {}
|
||||||
|
local ok = api_version == 1
|
||||||
|
return {
|
||||||
|
ok = ok,
|
||||||
|
state = ok and "enhanced" or "incompatible",
|
||||||
|
reason = ok and nil or "major_mismatch",
|
||||||
|
api_version = api_version,
|
||||||
|
capabilities = capabilities,
|
||||||
|
version = kamareVersion(),
|
||||||
|
path = modulePath(mod),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param official boolean
|
||||||
|
---@return KamareProbe
|
||||||
|
local function missingProbe(official)
|
||||||
|
return {
|
||||||
|
ok = false,
|
||||||
|
state = official and "official" or "missing",
|
||||||
|
reason = "missing",
|
||||||
|
api_version = nil,
|
||||||
|
capabilities = nil,
|
||||||
|
version = kamareVersion(),
|
||||||
|
path = nil,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 清空进程内记忆(测试缝;Registry.reload 不经过这里,探测态本就与源实例无关)。
|
||||||
|
function Cache.reset()
|
||||||
|
memo = nil
|
||||||
|
mirrored = nil
|
||||||
|
mirror_failed = false
|
||||||
|
logged = {}
|
||||||
|
shelves = {}
|
||||||
|
active = nil
|
||||||
|
pause_reason_logged = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return KamareProbe
|
||||||
|
function Cache.probe()
|
||||||
|
if memo then return memo end
|
||||||
|
local mod = loadModule("kamarecache")
|
||||||
|
if mod then
|
||||||
|
local result = enhancedProbe(mod)
|
||||||
|
-- 只有增强版值得记:官方 / 不兼容 / 未安装都要能随安装或升级立刻变化。
|
||||||
|
if result.ok then memo = result end
|
||||||
|
logProbe(result)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
local result = missingProbe(legacyAvailable())
|
||||||
|
logProbe(result)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 重新探测(设置页的「重新检测」):清掉成功记忆再探;结果没变则不重复记日志。
|
||||||
|
---@return KamareProbe
|
||||||
|
function Cache.reprobe()
|
||||||
|
memo = nil
|
||||||
|
return Cache.probe()
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 插件根目录:kamare 已装用它当前所在目录(就地替换),否则用月读自己的。
|
||||||
|
---@param own_path string|nil book.koplugin 目录
|
||||||
|
---@return string
|
||||||
|
function Cache.pluginsDir(own_path)
|
||||||
|
local path = Cache.probe().path
|
||||||
|
local installed = type(path) == "string" and path:gsub("/+", "/"):match("^(.*)/[^/]+%.koplugin/")
|
||||||
|
if installed then return installed end
|
||||||
|
if type(own_path) == "string" and own_path ~= "" then
|
||||||
|
local own = own_path:gsub("/+", "/"):gsub("/+$", "")
|
||||||
|
return own:match("^(.*)/[^/]+$") or own
|
||||||
|
end
|
||||||
|
local source = debug.getinfo(1, "S").source
|
||||||
|
if type(source) == "string" and source:sub(1, 1) == "@" then source = source:sub(2) end
|
||||||
|
-- 本文件在 <plugins>/moonsource-kavita.koplugin/moonsource_kavita/,往上三级
|
||||||
|
return source:match("^(.*)/[^/]+%.koplugin/moonsource_kavita/[^/]+$") or "plugins"
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 功能清单:kamare 随包提供的用户可见功能文案(kamarefeatures.lua)。
|
||||||
|
--- 只用于展示;缺失 / api_version 不符 / 结构不合法都当没有清单,不做能力推断回退。
|
||||||
|
---@param probe KamareProbe|nil
|
||||||
|
---@return string|nil
|
||||||
|
function Cache.featureText(probe)
|
||||||
|
probe = probe or Cache.probe()
|
||||||
|
if not probe.ok then return nil end
|
||||||
|
local ok, manifest = pcall(require, "kamarefeatures")
|
||||||
|
if not ok or type(manifest) ~= "table" or manifest.api_version ~= 1 then return nil end
|
||||||
|
local list = manifest.features
|
||||||
|
if type(list) ~= "table" then return nil end
|
||||||
|
local parts, seen = {}, {}
|
||||||
|
for _idx, item in ipairs(list) do
|
||||||
|
if type(item) == "string" and item ~= "" and not seen[item] then
|
||||||
|
seen[item] = true
|
||||||
|
parts[#parts + 1] = item
|
||||||
|
if #parts == 8 then break end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #parts == 0 then return nil end
|
||||||
|
return table.concat(parts, " · ")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 能力是否可用。`open` 是唯一允许退回 legacy 通道的能力(02 A4)。
|
||||||
|
---@param cap string|nil
|
||||||
|
---@return boolean
|
||||||
|
function Cache.available(cap)
|
||||||
|
local probe = Cache.probe()
|
||||||
|
if not probe.ok then
|
||||||
|
return cap == "open" and legacyAvailable() or false
|
||||||
|
end
|
||||||
|
if cap == nil then return true end
|
||||||
|
local capabilities = probe.capabilities or {}
|
||||||
|
if cap == "open" then
|
||||||
|
return capabilities.open == true or legacyAvailable()
|
||||||
|
end
|
||||||
|
return capabilities[cap] == true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 源配置:只读 base_url / api_key,其它键与缓存无关。
|
||||||
|
---@return table
|
||||||
|
local function config()
|
||||||
|
local value = require("utils.settings").getSource("kavita")
|
||||||
|
return type(value) == "table" and value or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 与 Client.new 同口径:去尾斜杠、去首尾空白;空串当未给。
|
||||||
|
---@param url any
|
||||||
|
---@return string|nil
|
||||||
|
local function normBase(url)
|
||||||
|
local text = Text.rtrimSlashes(Text.trim(url))
|
||||||
|
return text ~= "" and text or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- API Key 里的空白一律去掉(粘贴时常带换行 / 空格)。
|
||||||
|
---@param key any
|
||||||
|
---@return string|nil
|
||||||
|
local function normKey(key)
|
||||||
|
local text = Text.stripWhitespace(key)
|
||||||
|
return text ~= "" and text or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 当前服务器;未配置返回 nil(调用方按 unknown_server 静默降级)。
|
||||||
|
---@return string|nil
|
||||||
|
local function targetBase()
|
||||||
|
return normBase(config().base_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 能力对应的 kamare 函数名。
|
||||||
|
local KAMARE = {
|
||||||
|
status = "status",
|
||||||
|
summary = "summary",
|
||||||
|
resume = "resume_page",
|
||||||
|
queue = "queue_state",
|
||||||
|
index = "index",
|
||||||
|
enqueue = "enqueue",
|
||||||
|
delete = "delete",
|
||||||
|
estimate = "estimate",
|
||||||
|
open = "open",
|
||||||
|
server = "register_server",
|
||||||
|
chapters = "chapters",
|
||||||
|
delete_all = "delete_all",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- 取能力对应的函数:缺能力 / 缺函数一律 unsupported(调用点不各写一套)。
|
||||||
|
--- 队列控制是同一个能力(queue_control)下的三个动作,由 fn_name 指定函数。
|
||||||
|
---@param name string
|
||||||
|
---@param fn_name string|nil 缺省为 KAMARE[name]
|
||||||
|
---@return table|nil mod, string|nil code, function|nil fn
|
||||||
|
local function capability(name, fn_name)
|
||||||
|
local probe = Cache.probe()
|
||||||
|
if not probe.ok then return nil, "unsupported" end
|
||||||
|
if (probe.capabilities or {})[name] ~= true then return nil, "unsupported" end
|
||||||
|
local mod = loadModule("kamarecache")
|
||||||
|
if not mod then return nil, "unsupported" end
|
||||||
|
local fn = mod[fn_name or KAMARE[name]]
|
||||||
|
if type(fn) ~= "function" then return nil, "unsupported" end
|
||||||
|
return mod, nil, fn
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 写:把 moon 的服务器地址 + API Key 镜像给 kamare(幂等、不联网、不传 name)。
|
||||||
|
---@param base_url string|nil
|
||||||
|
---@param api_key string|nil
|
||||||
|
---@return string|nil server_key, string|nil code, string|nil message
|
||||||
|
function Cache.registerServer(base_url, api_key)
|
||||||
|
local mod, code, fn = capability("server")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
local url = normBase(base_url) or targetBase()
|
||||||
|
local key = normKey(api_key) or normKey(config().api_key)
|
||||||
|
if not url then return nil, "base_url_required" end
|
||||||
|
if not key then return nil, "api_key_required" end
|
||||||
|
local server_key, err, message = fn({ base_url = url, api_key = key })
|
||||||
|
if server_key then
|
||||||
|
mirrored = url .. "\0" .. key
|
||||||
|
mirror_failed = false
|
||||||
|
else
|
||||||
|
mirror_failed = true
|
||||||
|
logOnce("mirror|" .. tostring(err), "cache mirror failed code=" .. tostring(err))
|
||||||
|
end
|
||||||
|
return server_key, err, message
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 本次会话内镜像是否失败过(设置页的第五态)。
|
||||||
|
---@return boolean
|
||||||
|
function Cache.mirrorFailed()
|
||||||
|
return mirror_failed
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 镜像兜底:读路径首次操作前一次;写路径每次幂等重放。
|
||||||
|
---@param write boolean
|
||||||
|
---@param base_url string|nil
|
||||||
|
---@param api_key string|nil
|
||||||
|
---@return boolean
|
||||||
|
local function ensureMirror(write, base_url, api_key)
|
||||||
|
local probe = Cache.probe()
|
||||||
|
if not probe.ok or (probe.capabilities or {}).server ~= true then return false end
|
||||||
|
local url = normBase(base_url) or targetBase()
|
||||||
|
local key = normKey(api_key) or normKey(config().api_key)
|
||||||
|
if not url or not key then return false end
|
||||||
|
if not write and mirrored == url .. "\0" .. key then return true end
|
||||||
|
return Cache.registerServer(url, key) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param list any
|
||||||
|
---@param value any
|
||||||
|
---@return boolean
|
||||||
|
local function includes(list, value)
|
||||||
|
if type(list) ~= "table" then return false end
|
||||||
|
for _idx, item in ipairs(list) do
|
||||||
|
if tostring(item) == tostring(value) then return true end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 这一章是不是正在 kamare 查看器里(删除按钮据此置灰)。
|
||||||
|
---@param chapter_id any
|
||||||
|
---@return boolean
|
||||||
|
function Cache.isChapterOpen(chapter_id)
|
||||||
|
if not active then return false end
|
||||||
|
if tostring(active.chapter_id) ~= tostring(chapter_id) then return false end
|
||||||
|
local base_url = targetBase()
|
||||||
|
return base_url == nil or active.base_url == base_url
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 关闭回调包一层:先清 active,再交给调用方(source 写双行进度)。
|
||||||
|
---@param opts table
|
||||||
|
---@param base_url string|nil
|
||||||
|
---@param chapter_id any
|
||||||
|
---@return table
|
||||||
|
local function wrapClose(opts, base_url, chapter_id)
|
||||||
|
local user_close = opts.on_close
|
||||||
|
local wrapped = {}
|
||||||
|
for key, value in pairs(opts) do wrapped[key] = value end
|
||||||
|
wrapped.on_close = function(page, total)
|
||||||
|
if active and tostring(active.chapter_id) == tostring(chapter_id)
|
||||||
|
and (base_url == nil or active.base_url == base_url) then
|
||||||
|
active = nil
|
||||||
|
end
|
||||||
|
if user_close then return user_close(page, total) end
|
||||||
|
end
|
||||||
|
return wrapped
|
||||||
|
end
|
||||||
|
|
||||||
|
--- kamare 的页尺寸接口页号有时从 0 起,查看器只认从 1 起;拿不到就不预热。
|
||||||
|
---@param client table
|
||||||
|
---@param chapter_id any
|
||||||
|
---@return table|nil
|
||||||
|
local function dimensions(client, chapter_id)
|
||||||
|
if type(client.getFileDimensions) ~= "function" then return nil end
|
||||||
|
local dims, code = client:getFileDimensions(chapter_id)
|
||||||
|
if type(dims) ~= "table" or type(code) ~= "number" or code < 200 or code >= 300 then return nil end
|
||||||
|
local zero_based = false
|
||||||
|
for _idx, item in ipairs(dims) do
|
||||||
|
if item.pageNumber == 0 then zero_based = true end
|
||||||
|
end
|
||||||
|
if zero_based then
|
||||||
|
for _idx, item in ipairs(dims) do
|
||||||
|
if type(item.pageNumber) == "number" then item.pageNumber = item.pageNumber + 1 end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return dims
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 官方 / 旧版 kamare 的查看器通道:02 A4 要求官方版(无 kamarecache)与增强版缺 `open` 时
|
||||||
|
--- 仍保住今天的在线看图,所以这条通道留在适配层;source.lua 里那份重复实现已删(12 号票)。
|
||||||
|
---@param opts table
|
||||||
|
---@return table|nil viewer, string|nil code, string|nil message
|
||||||
|
local function legacyOpen(opts)
|
||||||
|
local Viewer = loadModule("kamareimageviewer")
|
||||||
|
if not Viewer or type(Viewer.new) ~= "function" then return nil, "unsupported" end
|
||||||
|
local entry = opts.entry or {}
|
||||||
|
if (tonumber(entry.pages) or 0) <= 0 then return nil, "no_pages" end
|
||||||
|
local client = loadModule("kavitaclient")
|
||||||
|
if not client then return nil, "open_failed", _("打开漫画阅读器失败") end
|
||||||
|
local ok, viewer, code, message = pcall(function()
|
||||||
|
client.base_url, client.api_key, client.auth_method, client.bearer =
|
||||||
|
opts.base_url, opts.api_key, "apiKey", nil
|
||||||
|
if not client.device_id or client.device_id == "" then client.device_id = "moon-kavita" end
|
||||||
|
local images = client:streamChapter(entry.chapterId)
|
||||||
|
if type(images) ~= "table" then return nil, "open_failed", _("打开漫画阅读器失败") end
|
||||||
|
local LuaSettings = require("luasettings")
|
||||||
|
local spec = Viewer:new{
|
||||||
|
images_list_data = images,
|
||||||
|
images_list_nb = entry.pages,
|
||||||
|
title = opts.title,
|
||||||
|
fullscreen = true,
|
||||||
|
metadata = {
|
||||||
|
seriesName = opts.title,
|
||||||
|
seriesId = entry.seriesId,
|
||||||
|
libraryId = entry.libraryId,
|
||||||
|
volumeId = entry.volumeId,
|
||||||
|
chapterId = entry.chapterId,
|
||||||
|
chapter = { id = entry.chapterId, volumeId = entry.volumeId, pages = entry.pages },
|
||||||
|
startPage = opts.start_page,
|
||||||
|
content_type = "chapter",
|
||||||
|
},
|
||||||
|
preloaded_dimensions = dimensions(client, entry.chapterId),
|
||||||
|
kamare_settings = LuaSettings:open(require("datastorage"):getSettingsDir() .. "/kamare.lua"),
|
||||||
|
on_close_callback = opts.on_close,
|
||||||
|
on_next_chapter_callback = opts.on_next and function(next_id)
|
||||||
|
require("ui/uimanager"):nextTick(function() opts.on_next(next_id) end)
|
||||||
|
end or nil,
|
||||||
|
}
|
||||||
|
if spec._aborted then return nil, "viewer_running", _("漫画阅读器已在运行") end
|
||||||
|
require("ui/uimanager"):show(spec)
|
||||||
|
return spec
|
||||||
|
end)
|
||||||
|
if not ok then
|
||||||
|
logger.warn("kavita.cache legacy open failed", viewer)
|
||||||
|
return nil, "open_failed", _("打开漫画阅读器失败")
|
||||||
|
end
|
||||||
|
return viewer, code, message
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 增强版是否接管打开:起始页 / 离线全归 kamare(journal + 缓存)。
|
||||||
|
--- 官方版或增强版缺 `open` 时退回 legacy 查看器,起始页要 moon 自己给。
|
||||||
|
---@return boolean
|
||||||
|
function Cache.enhancedOpen()
|
||||||
|
local probe = Cache.probe()
|
||||||
|
if not probe.ok or (probe.capabilities or {}).open ~= true then return false end
|
||||||
|
local mod = loadModule("kamarecache")
|
||||||
|
return mod ~= nil and type(mod.open) == "function"
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 打开一卷:enhanced 有 open 交 kamare 判缓存 / 离线 / 起始页;否则退回 legacy 查看器。
|
||||||
|
---@param opts { base_url: string|nil, api_key: string|nil, entry: table, title: string,
|
||||||
|
--- start_page: integer|nil, on_close: function|nil, on_next: function|nil }
|
||||||
|
---@return table|nil viewer, string|nil code, string|nil message
|
||||||
|
function Cache.open(opts)
|
||||||
|
opts = type(opts) == "table" and opts or {}
|
||||||
|
local entry = opts.entry or {}
|
||||||
|
local base_url = normBase(opts.base_url) or targetBase()
|
||||||
|
local api_key = normKey(opts.api_key) or normKey(config().api_key)
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local probe = Cache.probe()
|
||||||
|
local mod = probe.ok and loadModule("kamarecache") or nil
|
||||||
|
local use_enhanced = Cache.enhancedOpen()
|
||||||
|
local viewer, code, message
|
||||||
|
if use_enhanced then
|
||||||
|
ensureMirror(false, base_url, api_key)
|
||||||
|
viewer, code, message = mod.open(wrapClose(opts, base_url, entry.chapterId))
|
||||||
|
else
|
||||||
|
local next_opts = {}
|
||||||
|
for key, value in pairs(opts) do next_opts[key] = value end
|
||||||
|
next_opts.base_url, next_opts.api_key = base_url, api_key
|
||||||
|
viewer, code, message = legacyOpen(wrapClose(next_opts, base_url, entry.chapterId))
|
||||||
|
end
|
||||||
|
if viewer then
|
||||||
|
active = { base_url = base_url, chapter_id = entry.chapterId }
|
||||||
|
elseif code then
|
||||||
|
logOnce("open|" .. tostring(entry.chapterId) .. "|" .. code,
|
||||||
|
"cache open cid=" .. tostring(entry.chapterId) .. " code=" .. tostring(code))
|
||||||
|
end
|
||||||
|
return viewer, code, message
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 让书架投影失效(手动刷新书架 / Registry.reload 都走这里)。
|
||||||
|
function Cache.resetShelf()
|
||||||
|
shelves = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 「已缓存」的唯一口径:complete 或 stale(stale 与 complete 等价,03 A3)。
|
||||||
|
--- 同时接受两种形状:Cache.status 的章状态(state)与书架 index 的系列摘要(complete/stale)。
|
||||||
|
---@param status table|nil
|
||||||
|
---@return boolean
|
||||||
|
function Cache.isCached(status)
|
||||||
|
if type(status) ~= "table" then return false end
|
||||||
|
if status.state == "complete" or status.state == "stale" then return true end
|
||||||
|
if status.state ~= nil then return false end
|
||||||
|
return status.complete == true or status.stale == true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:书架投影(series_ids / mark / cover),按服务器记忆;无 TTL。
|
||||||
|
---@return ShelfCacheProjection|nil
|
||||||
|
function Cache.shelf()
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil end
|
||||||
|
if shelves[base_url] then return shelves[base_url] end
|
||||||
|
local index = Cache.index()
|
||||||
|
if not index then return nil end
|
||||||
|
local projection = { series_ids = {}, mark = {}, cover = {} }
|
||||||
|
local series = type(index.series) == "table" and index.series or {}
|
||||||
|
for key, info in pairs(series) do
|
||||||
|
if type(info) == "table" then
|
||||||
|
local stable_id = tostring(info.seriesId or key)
|
||||||
|
-- 只有 complete / stale 算「已缓存」;queued / downloading 只有 .part,离线打不开。
|
||||||
|
if (tonumber(info.chapters) or 0) > 0 and Cache.isCached(info) then
|
||||||
|
projection.series_ids[stable_id] = true
|
||||||
|
projection.mark[stable_id] = true
|
||||||
|
end
|
||||||
|
local cover = info.coverPath
|
||||||
|
if type(cover) == "string" and cover ~= "" and fileExists(cover) then
|
||||||
|
projection.cover[stable_id] = cover
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
shelves[base_url] = projection
|
||||||
|
return projection
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:缓存占用(设置页与「缓存占用」展示;确认框一律用 estimate)。
|
||||||
|
---@return table|nil, string|nil, string|nil
|
||||||
|
function Cache.summary()
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("summary")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(false)
|
||||||
|
return fn(base_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:所有服务器(含未关联)的合计占用;未配置服务器时用它算「清理全部」的预览。
|
||||||
|
---@return table|nil, string|nil, string|nil
|
||||||
|
function Cache.summaryAll()
|
||||||
|
local mod, code, fn = capability("summary")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
return fn(nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:当前服务器的清理计划(每章 facts)。series_id 可选。
|
||||||
|
---@param series_id any|nil
|
||||||
|
---@return table[]|nil, string|nil, string|nil
|
||||||
|
function Cache.chapters(series_id)
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("chapters")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(false)
|
||||||
|
return fn(base_url, series_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:已缓存章的状态(complete / stale / partial)。
|
||||||
|
---@param chapter_id any
|
||||||
|
---@return table|nil, string|nil, string|nil
|
||||||
|
function Cache.status(chapter_id)
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("status")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(false)
|
||||||
|
return fn(base_url, chapter_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:续读页(journal > snapshot > nil)。
|
||||||
|
---@param chapter_id any
|
||||||
|
---@param series_id any|nil
|
||||||
|
---@return table|nil, string|nil, string|nil
|
||||||
|
function Cache.resumePage(chapter_id, series_id)
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("resume")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(false)
|
||||||
|
return fn(base_url, chapter_id, series_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:按当前服务器过滤后的队列状态。
|
||||||
|
---@return table|nil, string|nil, string|nil
|
||||||
|
function Cache.queueState()
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("queue")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(false)
|
||||||
|
local state, err, message = fn(base_url)
|
||||||
|
if type(state) == "table" then
|
||||||
|
-- 1 秒轮询:只在暂停原因变化时记一行,恢复后清空,下次同原因再记。
|
||||||
|
if state.pause_reason ~= nil and state.pause_reason ~= "" then
|
||||||
|
if pause_reason_logged[base_url] ~= state.pause_reason then
|
||||||
|
pause_reason_logged[base_url] = state.pause_reason
|
||||||
|
logger.info("queue paused reason=" .. tostring(state.pause_reason))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
pause_reason_logged[base_url] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return state, err, message
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 批量暂停(全局队列,契约明确作用于所有服务器)。
|
||||||
|
---@return boolean|nil, string|nil, string|nil
|
||||||
|
function Cache.queuePause()
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("queue_control", "queue_pause")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(true)
|
||||||
|
local ok, err, message = fn(base_url)
|
||||||
|
logWrite("queue_pause", nil, err)
|
||||||
|
if ok then Cache.resetShelf() end
|
||||||
|
return ok, err, message
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 批量恢复。
|
||||||
|
---@return boolean|nil, string|nil, string|nil
|
||||||
|
function Cache.queueResume()
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("queue_control", "queue_resume")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(true)
|
||||||
|
local ok, err, message = fn(base_url)
|
||||||
|
logWrite("queue_resume", nil, err)
|
||||||
|
if ok then Cache.resetShelf() end
|
||||||
|
return ok, err, message
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只重试 queued / failed 的条目。
|
||||||
|
---@param chapter_ids any[]
|
||||||
|
---@return boolean|nil, string|nil, string|nil
|
||||||
|
function Cache.queueRetry(chapter_ids)
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("queue_control", "queue_retry")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(true)
|
||||||
|
local ok, err, message = fn(base_url, chapter_ids)
|
||||||
|
logWrite("queue_retry", chapter_ids, err)
|
||||||
|
if ok then Cache.resetShelf() end
|
||||||
|
return ok, err, message
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:书架索引投影(一次全量,不分页)。
|
||||||
|
---@return table|nil, string|nil, string|nil
|
||||||
|
function Cache.index()
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("index")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(false)
|
||||||
|
return fn(base_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 写:入队下载。成功时第三个返回值是 { chapters, bytes, available }。
|
||||||
|
---@param entries table[]
|
||||||
|
---@return boolean|nil, string|nil, any, table|nil
|
||||||
|
function Cache.enqueue(entries)
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("enqueue")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(true)
|
||||||
|
local ok, err, message, detail = fn(base_url, entries)
|
||||||
|
logWrite("enqueue", entryIds(entries), err)
|
||||||
|
if ok then Cache.resetShelf() end
|
||||||
|
return ok, err, message, detail
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 写:删除缓存(不碰 journal)。正在查看器里打开的章本地先拦一次(与 kamare 双层保护)。
|
||||||
|
---@param chapter_ids any[]
|
||||||
|
---@return boolean|nil, string|nil, string|nil, integer|nil
|
||||||
|
function Cache.delete(chapter_ids)
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
if active and active.base_url == base_url and includes(chapter_ids, active.chapter_id) then
|
||||||
|
return nil, "chapter_open"
|
||||||
|
end
|
||||||
|
local mod, code, fn = capability("delete")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(true)
|
||||||
|
local ok, err, message, deleted = fn(base_url, chapter_ids)
|
||||||
|
logWrite("delete", chapter_ids, err)
|
||||||
|
if ok then Cache.resetShelf() end
|
||||||
|
return ok, err, message, deleted
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 写:清空所有服务器(含未关联)。成功时第四个返回值是 { chapters, bytes } 估算。
|
||||||
|
---@return boolean|nil, string|nil, string|nil, table|nil
|
||||||
|
function Cache.deleteAll()
|
||||||
|
local mod, code, fn = capability("delete_all")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
local ok, err, third = fn()
|
||||||
|
logWrite("delete_all", nil, err)
|
||||||
|
if ok then
|
||||||
|
Cache.resetShelf()
|
||||||
|
return true, nil, nil, type(third) == "table" and third or nil
|
||||||
|
end
|
||||||
|
return nil, err, third
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读:下载前估算(数量 / 峰值 / 可用 / 裁决),不写盘、不入队、不建 serverKey。
|
||||||
|
---@param entries table[]
|
||||||
|
---@return table|nil, string|nil, string|nil, table|nil
|
||||||
|
function Cache.estimate(entries)
|
||||||
|
local base_url = targetBase()
|
||||||
|
if not base_url then return nil, "unknown_server" end
|
||||||
|
local mod, code, fn = capability("estimate")
|
||||||
|
if not mod then return nil, code end
|
||||||
|
ensureMirror(false)
|
||||||
|
return fn(base_url, entries)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 错误码 → 用户可见文案(02 A9)。调用点只问这张表,不各写一套。
|
||||||
|
local SILENT = {
|
||||||
|
unknown_server = true,
|
||||||
|
already_cached = true,
|
||||||
|
already_queued = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
local CODE_TEXT = {
|
||||||
|
offline_not_cached = _("这一卷还没缓存,联网后可下载"),
|
||||||
|
viewer_running = _("漫画阅读器已在运行"),
|
||||||
|
no_pages = _("这一卷没有可显示的页面"),
|
||||||
|
settings_write_failed = _("无法写入 kamare 配置"),
|
||||||
|
retry_no_entry = _("没有可重试的任务"),
|
||||||
|
chapter_open = _("正在阅读这一卷,关闭后可以删除"),
|
||||||
|
unsupported = _("需要安装带缓存接口的增强版 kamare"),
|
||||||
|
base_url_required = _("无法同步配置到 kamare"),
|
||||||
|
api_key_required = _("无法同步配置到 kamare"),
|
||||||
|
delete_incomplete = _("部分缓存未能删除(权限或存储错误)"),
|
||||||
|
}
|
||||||
|
|
||||||
|
local SPACE_CODES = {
|
||||||
|
not_enough_space = true,
|
||||||
|
cache_limit_reached = true,
|
||||||
|
low_space = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
--- 字节数 → 一行「x.x MB」;不做单位阶梯,容量判断只看数量级。
|
||||||
|
---@param bytes any
|
||||||
|
---@return string
|
||||||
|
function Cache.sizeText(bytes)
|
||||||
|
local value = tonumber(bytes)
|
||||||
|
if not value then return _("未知") end
|
||||||
|
return T(_("%1 MB"), string.format("%.1f", value / (1024 * 1024)))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 空间错误的 code + detail 文案。detail 由 kamare 给(不在 moon 复制阈值)。
|
||||||
|
---@param code string
|
||||||
|
---@param detail table|nil
|
||||||
|
---@return string
|
||||||
|
local function spaceText(code, detail)
|
||||||
|
detail = type(detail) == "table" and detail or {}
|
||||||
|
if code == "not_enough_space" then
|
||||||
|
return T(_("空间不足:需要 %1,可用 %2"), Cache.sizeText(detail.needed), Cache.sizeText(detail.available))
|
||||||
|
elseif code == "cache_limit_reached" then
|
||||||
|
return T(_("缓存空间已满:需要 %1,上限 %2"), Cache.sizeText(detail.needed), Cache.sizeText(detail.limit))
|
||||||
|
end
|
||||||
|
return T(_("可用空间低于 %1,清理后再下载"), Cache.sizeText(detail.low_water))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- code → 文案;静默码返回 nil。
|
||||||
|
---@param code string|nil
|
||||||
|
---@param message string|nil kamare 的原话(未知 code 时优先)
|
||||||
|
---@param detail table|nil 空间错误的 { needed, available, used, limit, low_water }
|
||||||
|
---@return string|nil
|
||||||
|
function Cache.message(code, message, detail)
|
||||||
|
if code == nil or SILENT[code] then return nil end
|
||||||
|
if SPACE_CODES[code] then return spaceText(code, detail) end
|
||||||
|
return CODE_TEXT[code] or message or _("缓存操作失败")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 清理计划 → 汇总。`filter` 为 "read" 时只算已读;`toc_read` 是可选的服务端进度
|
||||||
|
--- (chapterId → pagesRead),用于补上 kamare 离线拿不到的第三源。
|
||||||
|
---@param entries table[]|nil
|
||||||
|
---@param filter "all"|"read"
|
||||||
|
---@param toc_read table<string, number>|nil
|
||||||
|
---@return { chapters: integer, bytes: integer, ids: any[], queued: integer, open: boolean }
|
||||||
|
function Cache.plan(entries, filter, toc_read)
|
||||||
|
local out = { chapters = 0, bytes = 0, ids = {}, queued = 0, open = false }
|
||||||
|
for _idx, entry in ipairs(type(entries) == "table" and entries or {}) do
|
||||||
|
local pages = tonumber(entry.pages) or 0
|
||||||
|
local server_read = toc_read and (tonumber(toc_read[tostring(entry.chapterId)]) or 0) or 0
|
||||||
|
local read = entry.read == true or (pages > 0 and server_read >= pages)
|
||||||
|
if filter ~= "read" or read then
|
||||||
|
out.chapters = out.chapters + 1
|
||||||
|
out.bytes = out.bytes + (tonumber(entry.bytes) or 0)
|
||||||
|
out.ids[#out.ids + 1] = entry.chapterId
|
||||||
|
if entry.queued then out.queued = out.queued + 1 end
|
||||||
|
if entry.open then out.open = true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
--- estimate 的裁决 → 确认框 / toast 文案;可下载时 nil。
|
||||||
|
---@param result table|nil
|
||||||
|
---@return string|nil
|
||||||
|
function Cache.estimateMessage(result)
|
||||||
|
if type(result) ~= "table" or result.ok then return nil end
|
||||||
|
if result.reason == "nothing_to_do" then return _("全部已缓存或正在下载") end
|
||||||
|
if result.reason == "space" then
|
||||||
|
return T(_("空间不足:需要 %1,可用 %2"), Cache.sizeText(result.bytes), Cache.sizeText(result.available))
|
||||||
|
end
|
||||||
|
if result.reason == "low_water" then
|
||||||
|
return T(_("可用空间不足(剩余 %1),清理后再下载"), Cache.sizeText(result.available))
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 逐条 lastError 的特征 → 文案(07 A7)。moon 不加自动重试,只负责解释。
|
||||||
|
local FAILURE_PATTERNS = {
|
||||||
|
{ "http 403", _("服务器拒绝下载(403),检查 API Key / 权限") },
|
||||||
|
{ "not an archive", _("下载内容不完整或不是有效压缩包") },
|
||||||
|
{ "size ", _("下载内容不完整或不是有效压缩包") },
|
||||||
|
{ "extracted", _("下载内容不完整或不是有效压缩包") },
|
||||||
|
{ "sink write failed", _("存储空间不足或写入失败") },
|
||||||
|
{ "no space", _("存储空间不足或写入失败") },
|
||||||
|
{ "disk full", _("存储空间不足或写入失败") },
|
||||||
|
{ "socket", _("网络中断或服务器不可达") },
|
||||||
|
{ "connect", _("网络中断或服务器不可达") },
|
||||||
|
{ "closed", _("网络中断或服务器不可达") },
|
||||||
|
{ "truncated", _("网络中断或服务器不可达") },
|
||||||
|
{ "timeout", _("网络中断或服务器不可达") },
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param last_error string|nil
|
||||||
|
---@return string|nil
|
||||||
|
function Cache.failureText(last_error)
|
||||||
|
if type(last_error) ~= "string" or last_error == "" then return nil end
|
||||||
|
local lowered = last_error:lower()
|
||||||
|
for _idx, pattern in ipairs(FAILURE_PATTERNS) do
|
||||||
|
if lowered:find(pattern[1], 1, true) then return pattern[2] end
|
||||||
|
end
|
||||||
|
return T(_("缓存失败:%1"), last_error)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Cache
|
||||||
@@ -0,0 +1,257 @@
|
|||||||
|
--[[--
|
||||||
|
漫画缓存的后台任务登记:把「缓存这一批卷」登记成一条 passive 后台任务。
|
||||||
|
|
||||||
|
kamare 仍是唯一的执行者与写入者:这里不下载、不取消队列,只按本批 chapterId 轮询
|
||||||
|
`queue_state` / `status`,把进度报给 `workers.tasks`,让顶栏「后台任务」看得到、缓存期间不自动休眠、
|
||||||
|
关掉卷列表后仍有完成提示。队列是全局的(按服务器过滤),所以进度只数本批自己那几卷。
|
||||||
|
|
||||||
|
local handle = CacheTask.track{ series = series, entries = entries } -- 入队成功后
|
||||||
|
handle.mute(true) -- 页面自己的进度框负责提示时静音(默认不静音,由任务 toast)
|
||||||
|
handle.add(more) -- 同一部又有卷入队 / 重试失败项:并进同一条任务,终态清掉重新观察
|
||||||
|
handle.cancel() -- 只停轮询,不动 kamare 队列(队列控制仍走 Cache.queuePause/Resume/Retry)
|
||||||
|
|
||||||
|
@module moonsource_kavita.cache_task
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
local T = require("ffi/util").template
|
||||||
|
local Cache = require("moonsource_kavita.cache")
|
||||||
|
|
||||||
|
local CacheTask = {}
|
||||||
|
|
||||||
|
--- 轮询间隔:下载中 1 秒;暂停时 5 秒(用户可能几小时不处理,别每秒读一次索引)。
|
||||||
|
local POLL_SECONDS = 1
|
||||||
|
local PAUSED_SECONDS = 5
|
||||||
|
--- 连续这么多拍都看不到本批的队列项、也没落地:kamare 重启 / 队列被清,按中断收尾。
|
||||||
|
local MAX_IDLE_TICKS = 5
|
||||||
|
|
||||||
|
--- 队列任务 → 本批状态与句柄;同 key 再入队时并进去。弱键:任务出队后随之回收。
|
||||||
|
---@type table<BookTask, { st: table, handle: table }>
|
||||||
|
local tracked = setmetatable({}, { __mode = "k" })
|
||||||
|
|
||||||
|
---@param text string|nil
|
||||||
|
local function toast(text)
|
||||||
|
if not text then return end
|
||||||
|
require("ui.themes.widgets.toast"):new{ text = text, timeout = 2 }:show()
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 队列条目按 chapterId 归一成字符串键(kamare 的键可能是数字)。
|
||||||
|
---@param queue table|nil
|
||||||
|
---@return table
|
||||||
|
function CacheTask.queueEntries(queue)
|
||||||
|
local out = {}
|
||||||
|
for key, entry in pairs(type(queue) == "table" and queue.entries or {}) do
|
||||||
|
out[tostring(key)] = entry
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param queue table|nil
|
||||||
|
---@return boolean
|
||||||
|
function CacheTask.queuePaused(queue)
|
||||||
|
return type(queue) == "table" and (queue.state == "paused" or queue.pause_reason ~= nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param st table
|
||||||
|
local function stopTimer(st)
|
||||||
|
if st.timer then
|
||||||
|
require("ui/uimanager"):unschedule(st.timer)
|
||||||
|
st.timer = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param st table
|
||||||
|
local function schedule(st)
|
||||||
|
if st.settled or st.timer then return end
|
||||||
|
local delay = st.paused and PAUSED_SECONDS or POLL_SECONDS
|
||||||
|
st.timer = require("ui.guard").wrap("kavita cache task poll", function()
|
||||||
|
st.timer = nil
|
||||||
|
st:poll()
|
||||||
|
end)
|
||||||
|
require("ui/uimanager"):scheduleIn(delay, st.timer)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 本批任务的可变状态:track / 轮询 / handle 共用一份。
|
||||||
|
---@param opts table
|
||||||
|
---@return table
|
||||||
|
local function newState(opts)
|
||||||
|
local series = type(opts.series) == "table" and opts.series or {}
|
||||||
|
local st = {
|
||||||
|
title = series.title or series.stable_id,
|
||||||
|
ids = {}, -- 顺序数组,去重
|
||||||
|
seen = {}, -- tostring(id) -> true
|
||||||
|
landed = {}, -- tostring(id) -> 终态(已缓存或失败)
|
||||||
|
failed = {}, -- tostring(id) -> true
|
||||||
|
titles = {}, -- tostring(id) -> 卷名
|
||||||
|
total = 0,
|
||||||
|
ok_count = 0,
|
||||||
|
idle = 0,
|
||||||
|
muted = false,
|
||||||
|
paused = false,
|
||||||
|
settled = false,
|
||||||
|
timer = nil,
|
||||||
|
report = nil,
|
||||||
|
call_done = nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
--- 并进一批卷:新 id 追加;已有的清掉终态,重试 / 重新入队后下一拍重新观察。
|
||||||
|
---@param entries table[]
|
||||||
|
function st:add(entries)
|
||||||
|
for _idx, entry in ipairs(type(entries) == "table" and entries or {}) do
|
||||||
|
local id = entry.chapterId or entry.chapter_id or entry.id
|
||||||
|
if id ~= nil then
|
||||||
|
local key = tostring(id)
|
||||||
|
if not self.seen[key] then
|
||||||
|
self.seen[key] = true
|
||||||
|
self.ids[#self.ids + 1] = id
|
||||||
|
end
|
||||||
|
self.landed[key] = nil
|
||||||
|
self.failed[key] = nil
|
||||||
|
self.titles[key] = entry.title
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.total = #self.ids
|
||||||
|
self.idle = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 报表一次;没有 run 之前(还在排队)跳过。
|
||||||
|
---@param text string|nil
|
||||||
|
function st:emit(text)
|
||||||
|
if self.report then self.report(text, self.ok_count, self.total) end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 收尾:只结算一次;静音时不出提示(页面自己的进度框已经报过)。
|
||||||
|
---@param interrupted boolean|nil
|
||||||
|
---@return table
|
||||||
|
function st:settle(interrupted)
|
||||||
|
if self.settled then return { ok = false } end
|
||||||
|
self.settled = true
|
||||||
|
stopTimer(self)
|
||||||
|
-- 最后一卷落地的那一拍直接 settle,不会走到 poll 末尾的 emit:补报一次最终计数,
|
||||||
|
-- 否则任务卡片停在上一拍的「已完成 2/3」。
|
||||||
|
self:emit(nil)
|
||||||
|
local failed_count = 0
|
||||||
|
for key in pairs(self.failed) do
|
||||||
|
if self.seen[key] then failed_count = failed_count + 1 end
|
||||||
|
end
|
||||||
|
if not self.muted then
|
||||||
|
if interrupted and self.ok_count == 0 then
|
||||||
|
toast(_("缓存已中断"))
|
||||||
|
elseif failed_count == 0 then
|
||||||
|
toast(T(_("已缓存 %1 卷"), self.total))
|
||||||
|
else
|
||||||
|
toast(T(_("%1 卷成功,%2 卷失败"), self.ok_count, failed_count))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local result = {
|
||||||
|
ok = failed_count == 0 and not interrupted,
|
||||||
|
cached = self.ok_count,
|
||||||
|
total = self.total,
|
||||||
|
failed = failed_count,
|
||||||
|
interrupted = interrupted or nil,
|
||||||
|
}
|
||||||
|
if self.call_done then self.call_done(result) end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 每一拍:数本批的终态,报进度;全部落地就收尾。
|
||||||
|
function st:poll()
|
||||||
|
self.timer = nil
|
||||||
|
if self.settled then return end
|
||||||
|
local queue = Cache.queueState()
|
||||||
|
local entries = CacheTask.queueEntries(queue)
|
||||||
|
local remaining, queued_any = 0, false
|
||||||
|
for _idx, id in ipairs(self.ids) do
|
||||||
|
local key = tostring(id)
|
||||||
|
if not self.landed[key] then
|
||||||
|
local queued = entries[key]
|
||||||
|
if queued and queued.state == "failed" then
|
||||||
|
self.landed[key] = true
|
||||||
|
self.failed[key] = true
|
||||||
|
elseif Cache.isCached(Cache.status(id)) then
|
||||||
|
self.landed[key] = true
|
||||||
|
else
|
||||||
|
remaining = remaining + 1
|
||||||
|
if queued then queued_any = true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local ok_count = 0
|
||||||
|
for _idx, id in ipairs(self.ids) do
|
||||||
|
local key = tostring(id)
|
||||||
|
if self.landed[key] and not self.failed[key] then ok_count = ok_count + 1 end
|
||||||
|
end
|
||||||
|
self.ok_count = ok_count
|
||||||
|
self.paused = CacheTask.queuePaused(queue)
|
||||||
|
if remaining <= 0 then return self:settle() end
|
||||||
|
if self.paused then
|
||||||
|
self.idle = 0
|
||||||
|
self:emit(queue and queue.pause_reason == "low_space" and _("空间不足,已暂停") or _("已暂停"))
|
||||||
|
else
|
||||||
|
local current = queue and queue.current_chapter_id
|
||||||
|
self:emit(current ~= nil and self.titles[tostring(current)] or nil)
|
||||||
|
if queued_any then
|
||||||
|
self.idle = 0
|
||||||
|
else
|
||||||
|
-- 本批的卷既没在队列里、也没落地:kamare 重启 / 队列被清,不能永远挂着。
|
||||||
|
self.idle = self.idle + 1
|
||||||
|
if self.idle >= MAX_IDLE_TICKS then return self:settle(true) end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
schedule(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
return st
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 登记一条 passive 任务;同一部书已有未结束的任务就并进去。
|
||||||
|
---@param opts { series: table|nil, entries: table[], key: string|nil }
|
||||||
|
---@return table|nil handle mute(value): …; add(entries): …; cancel(): …
|
||||||
|
function CacheTask.track(opts)
|
||||||
|
opts = type(opts) == "table" and opts or {}
|
||||||
|
local entries = type(opts.entries) == "table" and opts.entries or {}
|
||||||
|
if #entries == 0 then return nil end
|
||||||
|
if not Cache.available("queue") then return nil end
|
||||||
|
local Tasks = require("workers.tasks")
|
||||||
|
local series = type(opts.series) == "table" and opts.series or {}
|
||||||
|
local key = "cache\0kavita\0" .. tostring(opts.key or series.stable_id or series.title or "series")
|
||||||
|
|
||||||
|
local live = tracked[Tasks.get(key) or false]
|
||||||
|
if live then
|
||||||
|
live.st:add(entries)
|
||||||
|
live.st:emit(nil)
|
||||||
|
return live.handle
|
||||||
|
end
|
||||||
|
|
||||||
|
local st = newState(opts)
|
||||||
|
st:add(entries)
|
||||||
|
local handle = {}
|
||||||
|
handle.mute = function(value) st.muted = value ~= false end
|
||||||
|
handle.add = function(more)
|
||||||
|
st:add(more)
|
||||||
|
st:emit(nil)
|
||||||
|
end
|
||||||
|
handle.cancel = function() stopTimer(st) end
|
||||||
|
|
||||||
|
local task = {
|
||||||
|
key = key,
|
||||||
|
kind = "cache",
|
||||||
|
title = st.title,
|
||||||
|
passive = true,
|
||||||
|
-- 队列暂停(空间不足 / 等网络)时不再压自动休眠:一停几小时不能把电耗光。
|
||||||
|
hold = function() return not st.paused end,
|
||||||
|
run = function(report, done)
|
||||||
|
st.report, st.call_done = report, done
|
||||||
|
st:emit(nil)
|
||||||
|
schedule(st)
|
||||||
|
return { cancel = function() stopTimer(st) end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
local queued = Tasks.enqueue(task)
|
||||||
|
if not queued then return nil end
|
||||||
|
tracked[queued] = { st = st, handle = handle }
|
||||||
|
handle.task = queued
|
||||||
|
return handle
|
||||||
|
end
|
||||||
|
|
||||||
|
return CacheTask
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita HTTP 客户端:x-api-key 认证,只回 wire,不做领域转换。
|
||||||
|
调用方先看 configured(),这里不再判。
|
||||||
|
|
||||||
|
@module moonsource_kavita.client
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local JSON = require("json")
|
||||||
|
local Request = require("http.request")
|
||||||
|
local Text = require("utils.text")
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
local T = require("ffi/util").template
|
||||||
|
|
||||||
|
--- 单次请求默认超时(秒)。全量书架(`all-v2`)在慢设备 / 慢服务器上 30s 拉不完,
|
||||||
|
--- 一个请求超时就会中断整轮同步、书架永远加载不出来,所以默认给足,并允许在设置里调大。
|
||||||
|
local DEFAULT_TIMEOUT = 60
|
||||||
|
--- 设置里的合法区间:太小等于次次超时,太大等于卡住没法恢复。
|
||||||
|
local MIN_TIMEOUT = 5
|
||||||
|
local MAX_TIMEOUT = 600
|
||||||
|
|
||||||
|
---@class KavitaClient
|
||||||
|
---@field base_url string
|
||||||
|
---@field api_key string
|
||||||
|
---@field timeout integer 单次请求超时秒(含下载)
|
||||||
|
local Client = {}
|
||||||
|
Client.__index = Client
|
||||||
|
Client.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT
|
||||||
|
Client.MIN_TIMEOUT = MIN_TIMEOUT
|
||||||
|
Client.MAX_TIMEOUT = MAX_TIMEOUT
|
||||||
|
|
||||||
|
---@param cfg { base_url: string|nil, api_key: string|nil, timeout: integer|string|nil }
|
||||||
|
---@return KavitaClient
|
||||||
|
function Client.new(cfg)
|
||||||
|
local timeout = math.floor(tonumber(cfg.timeout) or DEFAULT_TIMEOUT)
|
||||||
|
if timeout < MIN_TIMEOUT then timeout = MIN_TIMEOUT end
|
||||||
|
if timeout > MAX_TIMEOUT then timeout = MAX_TIMEOUT end
|
||||||
|
return setmetatable({
|
||||||
|
base_url = Text.rtrimSlashes(cfg.base_url),
|
||||||
|
api_key = Text.stripWhitespace(cfg.api_key),
|
||||||
|
timeout = timeout,
|
||||||
|
}, Client)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return boolean
|
||||||
|
function Client:configured()
|
||||||
|
return self.base_url ~= "" and self.api_key ~= ""
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Kavita 按 User-Agent 识别客户端;不带时设备列表里显示 Unknown Client。
|
||||||
|
---@return table
|
||||||
|
function Client:headers()
|
||||||
|
local device = package.loaded["device"]
|
||||||
|
local platform = type(device) == "table" and device.isAndroid and device:isAndroid() and "Android" or "Linux"
|
||||||
|
return { ["x-api-key"] = self.api_key, ["User-Agent"] = "KOReader/MoonBook (" .. platform .. ")" }
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 查询串:单值参数与 `Text.formEncode` 同形;值是数组时展开成重复键
|
||||||
|
--- (Kavita 的 `Libraries` 过滤器要 `&Libraries=8&Libraries=10`,逗号串会被当成一个库、恒返回 0 条)。
|
||||||
|
---@param query table
|
||||||
|
---@return string
|
||||||
|
local function queryString(query)
|
||||||
|
local keys = {}
|
||||||
|
for key in pairs(query) do keys[#keys + 1] = key end
|
||||||
|
table.sort(keys, function(a, b) return tostring(a) < tostring(b) end)
|
||||||
|
local parts = {}
|
||||||
|
for _idx, key in ipairs(keys) do
|
||||||
|
local value = query[key]
|
||||||
|
if type(value) == "table" then
|
||||||
|
for _i, item in ipairs(value) do
|
||||||
|
parts[#parts + 1] = Text.urlEncode(key) .. "=" .. Text.urlEncode(item)
|
||||||
|
end
|
||||||
|
elseif value ~= nil then
|
||||||
|
parts[#parts + 1] = Text.urlEncode(key) .. "=" .. Text.urlEncode(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(parts, "&")
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param path string
|
||||||
|
---@param query table|nil
|
||||||
|
---@return string
|
||||||
|
function Client:url(path, query)
|
||||||
|
if query then return self.base_url .. path .. "?" .. queryString(query) end
|
||||||
|
return self.base_url .. path
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 原始请求:2xx 回 cb(res)(带状态码与响应头,分页接口要读 `Pagination` 头);
|
||||||
|
--- 401/403 与非 2xx 一律 cb(nil, err, code)。
|
||||||
|
---@param method string
|
||||||
|
---@param path string
|
||||||
|
---@param query table|nil
|
||||||
|
---@param body table|nil JSON 请求体
|
||||||
|
---@param cb fun(res: table|nil, err: string|nil, code: integer|nil)
|
||||||
|
---@return HttpJob
|
||||||
|
function Client:requestRes(method, path, query, body, cb)
|
||||||
|
local headers = self:headers()
|
||||||
|
local payload
|
||||||
|
if body then
|
||||||
|
headers["Content-Type"] = "application/json"
|
||||||
|
payload = JSON.encode(body)
|
||||||
|
end
|
||||||
|
return Request.request({
|
||||||
|
url = self:url(path, query), method = method, headers = headers, body = payload, timeout = self.timeout,
|
||||||
|
}, function(res, err)
|
||||||
|
if err or not res then
|
||||||
|
cb(nil, err and tostring(err) or _("网络请求失败"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local code = tonumber(res.code)
|
||||||
|
if code == 401 or code == 403 then
|
||||||
|
cb(nil, _("Kavita API Key 无效或无权限"), code)
|
||||||
|
elseif not Request.ok(code) then
|
||||||
|
cb(nil, T(_("请求失败 (HTTP %1)"), tostring(code)), code)
|
||||||
|
else
|
||||||
|
-- 只规范化 body;响应头原样带着(`Request.header` 认 Turbo 头与普通表两种)。
|
||||||
|
cb({ code = code, headers = res.headers, body = Text.stripBom(res.body or "") }, nil, code)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 原始请求:2xx 回 cb(body),否则 cb(nil, err, code)。
|
||||||
|
---@param method string
|
||||||
|
---@param path string
|
||||||
|
---@param query table|nil
|
||||||
|
---@param body table|nil JSON 请求体
|
||||||
|
---@param cb fun(body: string|nil, err: string|nil, code: integer|nil)
|
||||||
|
---@return HttpJob
|
||||||
|
function Client:request(method, path, query, body, cb)
|
||||||
|
return self:requestRes(method, path, query, body, function(res, err, code)
|
||||||
|
cb(res and res.body, err, code)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- JSON 解码:写接口成功时回空体,按 {} 交回;服务端或反代可能回 HTML 错误页,
|
||||||
|
--- 解析失败按请求失败处理,不让异常冒到回调链外。
|
||||||
|
---@param raw string
|
||||||
|
---@return table|nil, string|nil
|
||||||
|
local function decodeJson(raw)
|
||||||
|
if Text.trim(raw) == "" then return {} end
|
||||||
|
local ok, data = pcall(JSON.decode, raw)
|
||||||
|
if ok and type(data) == "table" then return data end
|
||||||
|
return nil, _("响应不是 JSON")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- JSON 请求。
|
||||||
|
---@param method string
|
||||||
|
---@param path string
|
||||||
|
---@param query table|nil
|
||||||
|
---@param body table|nil
|
||||||
|
---@param cb fun(data: table|nil, err: string|nil, code: integer|nil)
|
||||||
|
---@return HttpJob
|
||||||
|
function Client:json(method, path, query, body, cb)
|
||||||
|
return self:request(method, path, query, body, function(raw, err, code)
|
||||||
|
if not raw then
|
||||||
|
cb(nil, err, code)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local data, derr = decodeJson(raw)
|
||||||
|
cb(data, derr, code)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 分页接口的 JSON 请求:Kavita 把分页信息放在响应头 `Pagination` 里(不在 body),
|
||||||
|
--- 回调第四参是本页声明的总页数(缺失 / 不可信时为 nil,调用方自行兜底)。
|
||||||
|
--- 头的内容只由 client 解释,源不必碰 `http.request`。
|
||||||
|
---@param method string
|
||||||
|
---@param path string
|
||||||
|
---@param query table|nil
|
||||||
|
---@param body table|nil
|
||||||
|
---@param cb fun(data: table|nil, err: string|nil, code: integer|nil, pages: integer|nil)
|
||||||
|
---@return HttpJob
|
||||||
|
function Client:jsonPaged(method, path, query, body, cb)
|
||||||
|
return self:requestRes(method, path, query, body, function(res, err, code)
|
||||||
|
if not res then
|
||||||
|
cb(nil, err, code)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local data, derr = decodeJson(res.body)
|
||||||
|
cb(data, derr, code, Client.totalPages(Request.header(res, "Pagination")))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- `Pagination` 头 → 总页数:`{"currentPage":1,"itemsPerPage":200,"totalItems":316,"totalPages":2}`。
|
||||||
|
--- 缺失 / 解析不出 / 负数一律回 nil(当分页信息不可信),调用方按「本页拉满就还有下一页」兜底。
|
||||||
|
---@param raw string|nil
|
||||||
|
---@return integer|nil
|
||||||
|
function Client.totalPages(raw)
|
||||||
|
if type(raw) ~= "string" or raw == "" then return nil end
|
||||||
|
local ok, data = pcall(JSON.decode, raw)
|
||||||
|
if not ok or type(data) ~= "table" then return nil end
|
||||||
|
local pages = tonumber(data.totalPages)
|
||||||
|
if not pages or pages < 0 then return nil end
|
||||||
|
return math.floor(pages)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 下载一卷原文件。Request.download 遇到非 2xx 也会落盘,这里删掉并报错。
|
||||||
|
---@param chapter_id integer
|
||||||
|
---@param dest string
|
||||||
|
---@param on_progress fun(bytes: number, total: number|nil)
|
||||||
|
---@param cb fun(ok: boolean, err: string|nil)
|
||||||
|
---@return HttpJob
|
||||||
|
function Client:download(chapter_id, dest, on_progress, cb)
|
||||||
|
return Request.download({
|
||||||
|
url = self:url("/api/Download/chapter", { chapterId = chapter_id }),
|
||||||
|
headers = self:headers(), timeout = self.timeout, on_progress = on_progress,
|
||||||
|
}, dest, function(ok, err, res)
|
||||||
|
if ok and not Request.ok(res and res.code) then
|
||||||
|
os.remove(dest)
|
||||||
|
ok, err = false, T(_("请求失败 (HTTP %1)"), tostring(res and res.code))
|
||||||
|
end
|
||||||
|
cb(ok, err and tostring(err))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Client
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
--[[--
|
||||||
|
卷列表与系列页共用的「继续阅读」目标。
|
||||||
|
|
||||||
|
主线 = 最远碰过的那一卷(有进度);这一卷读完就顺延到下一卷,全读完回到第一卷(重读)。
|
||||||
|
`updated_at` 只用来标记「上次翻阅」,不参与选卷——回头翻旧卷不会把入口拽回去
|
||||||
|
(Kavita 的 continue-point 是「最早未读完」,正是会被回顾劫持的那种)。
|
||||||
|
|
||||||
|
纯函数:不读网、不读盘,进度与时间由调用方注入。
|
||||||
|
|
||||||
|
@module moonsource_kavita.continue_point
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local T = require("ffi/util").template
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
--- 卷名:优先 toc 的标题;没有、或退化成系列名时兜底「第 N 卷」。
|
||||||
|
---@param entry table|nil
|
||||||
|
---@param series_title string|nil
|
||||||
|
---@return string
|
||||||
|
function M.label(entry, series_title)
|
||||||
|
local title = entry and entry.title
|
||||||
|
if type(title) ~= "string" or title == "" or title == series_title then
|
||||||
|
local n = tonumber(entry and (entry.idx or entry.number))
|
||||||
|
return n and T(_("第 %1 卷"), n) or "?"
|
||||||
|
end
|
||||||
|
return title
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param target ContinueTarget
|
||||||
|
---@param series_title string|nil
|
||||||
|
---@return string text, string|nil caption
|
||||||
|
function M.describe(target, series_title)
|
||||||
|
local label = M.label(target.entry, series_title)
|
||||||
|
local text, caption
|
||||||
|
if target.kind == "done" then
|
||||||
|
text = T(_("重读 · %1"), label)
|
||||||
|
elseif target.kind == "fresh" then
|
||||||
|
text = T(_("开始阅读 · %1"), label)
|
||||||
|
if target.total_pages > 0 then caption = T(_("共 %1 页"), target.total_pages) end
|
||||||
|
else
|
||||||
|
text = T(_("继续阅读 · %1"), label)
|
||||||
|
if target.total_pages > 0 then
|
||||||
|
caption = T(_("第 %1/%2 页 · %3%"), target.page, target.total_pages,
|
||||||
|
math.floor(target.fraction * 100 + 0.5))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return text, caption
|
||||||
|
end
|
||||||
|
|
||||||
|
---@class ContinueTarget
|
||||||
|
---@field entry table 要打开的卷
|
||||||
|
---@field kind "fresh"|"continue"|"done"
|
||||||
|
---@field fraction number 这一卷的进度 0..1
|
||||||
|
---@field page number 已读页(用于「第 x/y 页」)
|
||||||
|
---@field total_pages number
|
||||||
|
---@field browsed table|nil 上次翻阅且不是主线的卷
|
||||||
|
|
||||||
|
--- 选主线。
|
||||||
|
---@param toc table[] 卷目录(toc 顺序即阅读顺序)
|
||||||
|
---@param opts table { fraction = fun(entry):number|nil, updated_at = fun(entry):number|nil,
|
||||||
|
--- page = fun(entry):{page:number,total:number}|nil,
|
||||||
|
--- complete = fun(entry):boolean }
|
||||||
|
---@return ContinueTarget|nil
|
||||||
|
function M.pick(toc, opts)
|
||||||
|
opts = opts or {}
|
||||||
|
local entries = {}
|
||||||
|
for _i, e in ipairs(toc or {}) do
|
||||||
|
local pages = tonumber(e.pages) or 0
|
||||||
|
if pages > 0 then
|
||||||
|
local fraction = opts.fraction and tonumber(opts.fraction(e))
|
||||||
|
if fraction == nil then
|
||||||
|
fraction = (tonumber(e.pagesRead) or 0) / pages
|
||||||
|
end
|
||||||
|
fraction = math.max(0, math.min(1, fraction))
|
||||||
|
-- 服务端 / 调用方说这卷已经读完:本机重新打开留下的低进度不改变「已读完」,
|
||||||
|
-- 否则回顾旧卷会把主线拖回去,列表也会出现「已读 · 1/194 页」。
|
||||||
|
if (tonumber(e.pagesRead) or 0) >= pages
|
||||||
|
or (opts.complete and opts.complete(e)) then
|
||||||
|
fraction = 1
|
||||||
|
end
|
||||||
|
entries[#entries + 1] = { entry = e, fraction = fraction }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #entries == 0 then return nil end
|
||||||
|
|
||||||
|
local last
|
||||||
|
for i, item in ipairs(entries) do
|
||||||
|
if item.fraction > 0 then last = i end
|
||||||
|
end
|
||||||
|
|
||||||
|
local target, kind
|
||||||
|
if not last then
|
||||||
|
target, kind = entries[1], "fresh"
|
||||||
|
elseif entries[last].fraction < 1 then
|
||||||
|
target, kind = entries[last], "continue"
|
||||||
|
else
|
||||||
|
local next_item
|
||||||
|
for i = last + 1, #entries do
|
||||||
|
if entries[i].fraction < 1 then next_item = entries[i] break end
|
||||||
|
end
|
||||||
|
if next_item then
|
||||||
|
target, kind = next_item, "continue"
|
||||||
|
else
|
||||||
|
target, kind = entries[1], "done"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local total = tonumber(target.entry.pages) or 0
|
||||||
|
local page
|
||||||
|
if opts.page then
|
||||||
|
local got = opts.page(target.entry)
|
||||||
|
if got then
|
||||||
|
page = tonumber(got.page)
|
||||||
|
total = tonumber(got.total) or total
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not page then page = math.floor(target.fraction * total + 0.5) end
|
||||||
|
if kind == "fresh" then page = 0 end
|
||||||
|
|
||||||
|
-- 「上次翻阅」:本机更新时间最新的一卷;和主线同一卷就不标。
|
||||||
|
local browsed, browsed_at
|
||||||
|
if opts.updated_at then
|
||||||
|
for _i, item in ipairs(entries) do
|
||||||
|
local ts = tonumber(opts.updated_at(item.entry)) or 0
|
||||||
|
if ts > 0 and (not browsed_at or ts > browsed_at) then
|
||||||
|
browsed, browsed_at = item, ts
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
entry = target.entry,
|
||||||
|
kind = kind,
|
||||||
|
fraction = target.fraction,
|
||||||
|
page = page,
|
||||||
|
total_pages = total,
|
||||||
|
browsed = browsed and tostring(browsed.entry.chapterId) ~= tostring(target.entry.chapterId)
|
||||||
|
and browsed.entry or nil,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
--[[--
|
||||||
|
kamare 增强版在线更新:流程在 utils.plugin_update,这里只给 kamare 的目标描述。
|
||||||
|
|
||||||
|
版本和 digest 先问 api.ankio.net 的 GitHub 转发,挂了回落 api.github.com。
|
||||||
|
kamare 已装就地替换,没装装进月读同级插件目录。装好立即重启:旧模块还在内存里。
|
||||||
|
|
||||||
|
@module moonsource_kavita.kamare_update
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local Cache = require("moonsource_kavita.cache")
|
||||||
|
local Updater = require("utils.plugin_update")
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
local T = require("ffi/util").template
|
||||||
|
|
||||||
|
local NAME = "kamare.koplugin"
|
||||||
|
|
||||||
|
local Update = Updater.new({
|
||||||
|
repo = "backtracker/kamare.koplugin",
|
||||||
|
api_urls = {
|
||||||
|
"https://api.ankio.net/gh/repos/backtracker/kamare.koplugin/releases/latest",
|
||||||
|
"https://api.github.com/repos/backtracker/kamare.koplugin/releases/latest",
|
||||||
|
},
|
||||||
|
asset = function() return "kamare.koplugin.zip" end,
|
||||||
|
archive = "kamare-update.zip",
|
||||||
|
job = "kamare.update",
|
||||||
|
installed = function()
|
||||||
|
local probe = Cache.probe()
|
||||||
|
return probe.ok and probe.version or nil
|
||||||
|
end,
|
||||||
|
name = NAME,
|
||||||
|
parent = function(plugin) return Cache.pluginsDir(plugin and plugin.path) end,
|
||||||
|
text = {
|
||||||
|
checking = _("正在检查 kamare 更新…"),
|
||||||
|
downloading = _("正在下载 kamare 更新…"),
|
||||||
|
installing = _("正在安装 kamare 更新…"),
|
||||||
|
failed = _("kamare 更新失败:%1"),
|
||||||
|
title = _("更新 kamare"),
|
||||||
|
latest = function(release) return "kamare " .. release.installed end,
|
||||||
|
header = function(release)
|
||||||
|
if release.installed then
|
||||||
|
return T(_("发现 kamare %1(当前 %2)。下载并完整替换插件目录?"), release.version, release.installed)
|
||||||
|
end
|
||||||
|
return T(_("当前未安装可用的 kamare 增强版。安装最新版 %1?"), release.version)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return Update
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
return {
|
||||||
|
["EPUB 划线同步"] = "EPUB highlight sync",
|
||||||
|
["书架与卷目录同步(只读)"] = "Bookshelf and volume list sync (read-only)",
|
||||||
|
["同步 Kavita 书架、电子书与漫画"] = "Sync Kavita bookshelves, ebooks and comics",
|
||||||
|
["漫画在线阅读与缓存(需 kamare 增强版)"] = "Read and cache comics online (requires enhanced kamare)",
|
||||||
|
["阅读历史拉取"] = "Fetch reading history",
|
||||||
|
["下载文件校验失败"] = "Downloaded file failed verification",
|
||||||
|
["确定退出 Kavita 账号?"] = "Sign out of Kavita?",
|
||||||
|
["正在下载…"] = "Downloading…",
|
||||||
|
["章节目录保存失败"] = "Failed to save chapter list",
|
||||||
|
["请求失败 (HTTP %1)"] = "Request failed (HTTP %1)",
|
||||||
|
["连接失败"] = "Connection failed",
|
||||||
|
["打开漫画阅读器失败"] = "Could not open the comic viewer",
|
||||||
|
["漫画阅读器已在运行"] = "A comic viewer is already running",
|
||||||
|
["这一卷还没缓存,联网后可下载"] = "This volume is not cached yet; connect to download it",
|
||||||
|
["这一卷没有可显示的页面"] = "This volume has no pages to show",
|
||||||
|
["下一卷不在目录里"] = "The next volume is not in the table of contents",
|
||||||
|
["无法写入 kamare 配置"] = "Could not write the kamare settings",
|
||||||
|
["没有可重试的任务"] = "Nothing to retry",
|
||||||
|
["正在阅读这一卷,关闭后可以删除"] = "This volume is open; close it before deleting",
|
||||||
|
["需要安装带缓存接口的增强版 kamare"] = "Install the enhanced kamare build with the cache API",
|
||||||
|
["无法同步配置到 kamare"] = "Could not sync settings to kamare",
|
||||||
|
["%1 MB"] = "%1 MB",
|
||||||
|
["空间不足:需要 %1,可用 %2"] = "Not enough space: %1 needed, %2 available",
|
||||||
|
["缓存空间已满:需要 %1,上限 %2"] = "Cache limit reached: %1 needed, %2 limit",
|
||||||
|
["可用空间低于 %1,清理后再下载"] = "Available space is below %1; free some space and try again",
|
||||||
|
["缓存操作失败"] = "Cache operation failed",
|
||||||
|
["全部已缓存或正在下载"] = "Everything is already cached or downloading",
|
||||||
|
["可用空间不足(剩余 %1),清理后再下载"] = "Not enough free space (%1 left); free some space and try again",
|
||||||
|
["服务器拒绝下载(403),检查 API Key / 权限"] = "Server refused the download (403); check the API key / permissions",
|
||||||
|
["下载内容不完整或不是有效压缩包"] = "The download is incomplete or not a valid archive",
|
||||||
|
["存储空间不足或写入失败"] = "Out of storage space or write failed",
|
||||||
|
["网络中断或服务器不可达"] = "Network interrupted or server unreachable",
|
||||||
|
["缓存失败:%1"] = "Cache failed: %1",
|
||||||
|
["配置同步失败"] = "Settings sync failed",
|
||||||
|
["增强版 v%1"] = "Enhanced v%1",
|
||||||
|
["增强版"] = "Enhanced",
|
||||||
|
["版本不兼容"] = "Incompatible version",
|
||||||
|
["官方版(无缓存接口)"] = "Official build (no cache API)",
|
||||||
|
["未安装 / 未启用"] = "Not installed / not enabled",
|
||||||
|
["连接正常"] = "Connected",
|
||||||
|
["Kavita %1"] = "Kavita %1",
|
||||||
|
["未加载"] = "Not loaded",
|
||||||
|
["获取增强版"] = "Get the enhanced build",
|
||||||
|
["秒"] = "s",
|
||||||
|
["检查 Kavita 服务器连接与版本"] = "Check the Kavita server connection and version",
|
||||||
|
["kamare 增强版"] = "kamare enhanced build",
|
||||||
|
["点按检查 kamare 增强版更新"] = "Tap to check for kamare enhanced-build updates",
|
||||||
|
["点按安装 kamare 增强版"] = "Tap to install the kamare enhanced build",
|
||||||
|
["点按安装兼容的 kamare 增强版"] = "Tap to install a compatible kamare enhanced build",
|
||||||
|
["点按检查并安装 kamare 增强版"] = "Tap to check for and install the kamare enhanced build",
|
||||||
|
["官方版"] = "Official build",
|
||||||
|
[" 也可点上方「kamare 增强版」检查并安装最新版。"] = " Or tap “kamare enhanced build” above to check for and install the latest version.",
|
||||||
|
["正在检查 kamare 更新…"] = "Checking for kamare updates…",
|
||||||
|
["更新 kamare"] = "Update kamare",
|
||||||
|
["发现 kamare %1(当前 %2)。下载并完整替换插件目录?"] = "kamare %1 is available (current %2). Download and replace the plugin directory?",
|
||||||
|
["当前未安装可用的 kamare 增强版。安装最新版 %1?"] = "No usable kamare enhanced build is installed. Install the latest version %1?",
|
||||||
|
["正在下载 kamare 更新…"] = "Downloading the kamare update…",
|
||||||
|
["正在安装 kamare 更新…"] = "Installing the kamare update…",
|
||||||
|
["kamare 更新失败:%1"] = "kamare update failed: %1",
|
||||||
|
[" 发布页:github.com/backtracker/kamare.koplugin/releases/latest"] = " Releases: github.com/backtracker/kamare.koplugin/releases/latest",
|
||||||
|
[" 下载 kamare.koplugin.zip,解压后把 kamare.koplugin/ 放进:%1"] = " Download kamare.koplugin.zip, unzip it, and put kamare.koplugin/ into: %1",
|
||||||
|
[" 重启 KOReader。包里要有 kamarecache.lua(没有就是官方版);"] = " Restart KOReader. The archive must contain kamarecache.lua (otherwise it is the official build);",
|
||||||
|
[" 增强版与官方版目录同名,不能共存;替换前先删掉旧的 kamare.koplugin/。"] = " Enhanced and official share the same directory name and cannot coexist; delete the old kamare.koplugin/ before replacing it.",
|
||||||
|
[" 如该目录不可写,可改用:%1"] = " If that directory is not writable, use: %1",
|
||||||
|
["%1 · 已缓存"] = "%1 · Cached",
|
||||||
|
["%1 · 待同步"] = "%1 · Pending sync",
|
||||||
|
["%1 · 离线"] = "%1 · Offline",
|
||||||
|
["%1 卷成功,%2 卷失败"] = "%1 volumes succeeded, %2 failed",
|
||||||
|
["%1 等 %2 卷"] = "%1 and %2 volumes",
|
||||||
|
["下载中 %1%"] = "Downloading %1%",
|
||||||
|
["全部已缓存"] = "Everything is cached",
|
||||||
|
["删除「%1」的缓存?将释放 %2。"] = "Delete the cache for %1? This frees %2.",
|
||||||
|
["删除会取消这一卷的下载。"] = "Deleting also cancels this volume's download.",
|
||||||
|
["删除后离线不可读。"] = "It will not be readable offline after deletion.",
|
||||||
|
["删除缓存"] = "Delete cache",
|
||||||
|
["去清理空间"] = "Free up space",
|
||||||
|
["另有 %1 卷失败将重试"] = "%1 failed volumes will be retried",
|
||||||
|
["完成后剩余 %1"] = "%1 left afterwards",
|
||||||
|
["将缓存:%1"] = "To cache: %1",
|
||||||
|
["将重试:%1"] = "To retry: %1",
|
||||||
|
["已排队"] = "Queued",
|
||||||
|
["已暂停"] = "Paused",
|
||||||
|
["已暂停整个下载队列"] = "Paused the whole download queue",
|
||||||
|
["已暂停 %1%"] = "Paused %1%",
|
||||||
|
["已暂停(仅 Wi-Fi 下载)"] = "Paused (Wi-Fi only)",
|
||||||
|
["已暂停(启动恢复)"] = "Paused (restored at startup)",
|
||||||
|
["已暂停(断网)"] = "Paused (offline)",
|
||||||
|
["已暂停(连续下载失败)"] = "Paused (repeated download failures)",
|
||||||
|
["已缓存 %1 卷"] = "Cached %1 volumes",
|
||||||
|
["缓存已中断"] = "Caching was interrupted",
|
||||||
|
["开始缓存"] = "Start caching",
|
||||||
|
["当前下载已暂停,开始缓存会恢复整个队列"] = "Downloads are paused; starting will resume the whole queue",
|
||||||
|
["未缓存"] = "Not cached",
|
||||||
|
["查看失败原因"] = "View failure reasons",
|
||||||
|
["正在缓存 %1/%2 卷"] = "Caching volume %1/%2",
|
||||||
|
["清理后再下载"] = "Free up space before downloading",
|
||||||
|
["空间不足"] = "Not enough space",
|
||||||
|
["空间不足,已暂停"] = "Not enough space, paused",
|
||||||
|
["空间不足,已暂停。清理后再下载"] = "Not enough space, paused. Free up space before downloading.",
|
||||||
|
["缓存 %1 卷"] = "Cache %1 volumes",
|
||||||
|
["缓存这一卷"] = "Cache this volume",
|
||||||
|
["设备可用 %1"] = "%1 available",
|
||||||
|
["部分失败"] = "Partly failed",
|
||||||
|
["重试"] = "Retry",
|
||||||
|
["重试失败项并继续"] = "Retry failures and continue",
|
||||||
|
["重试缓存"] = "Retry cache",
|
||||||
|
["预计占用 %1(峰值)"] = "Estimated use %1 (peak)",
|
||||||
|
["缓存整部"] = "Cache whole series",
|
||||||
|
["缓存未读"] = "Cache unread",
|
||||||
|
["没有未读的卷"] = "No unread volumes",
|
||||||
|
["缓存后 N 卷…"] = "Cache next N volumes…",
|
||||||
|
["缓存后 N 卷"] = "Cache next N volumes",
|
||||||
|
["卷数"] = "Volumes",
|
||||||
|
["增强版 v%1(旧接口)"] = "Enhanced v%1 (legacy API)",
|
||||||
|
["增强版(旧接口)"] = "Enhanced (legacy API)",
|
||||||
|
["kamare API v%1 与当前支持的 v1 不兼容;装回支持 v1 的增强版后可管理缓存"] = "kamare API v%1 is not compatible with the supported v1; install an enhanced build that supports v1 to manage the cache",
|
||||||
|
["版本与获取"] = "Version and getting the enhanced build",
|
||||||
|
["正在统计…"] = "Measuring…",
|
||||||
|
["正在清理…"] = "Cleaning up…",
|
||||||
|
["增强版功能"] = "Enhanced features",
|
||||||
|
["加载路径"] = "Loaded from",
|
||||||
|
["缓存占用"] = "Cache usage",
|
||||||
|
["已用 %1%2,可用 %3"] = "%1 used%2, %3 available",
|
||||||
|
["(含未关联服务器)"] = " (unlinked servers included)",
|
||||||
|
["重试同步"] = "Retry sync",
|
||||||
|
["已重新同步配置"] = "Settings synced again",
|
||||||
|
["服务器配置没能写入 kamare,缓存操作可能找不到服务器"] = "The server settings could not be written to kamare; cache actions may not find the server",
|
||||||
|
["未配置服务器"] = "No server configured",
|
||||||
|
["填写服务器地址与 API Key 后,可按服务器清理已读或全部缓存"] = "Fill in the server address and API key to clean up read or all cache per server",
|
||||||
|
["清理已读"] = "Clean up read",
|
||||||
|
["清理本服务器"] = "Clean up this server",
|
||||||
|
["清理全部"] = "Clean up all",
|
||||||
|
["清理全部缓存"] = "Clean up all cache",
|
||||||
|
["清理本系列"] = "Clean up this series",
|
||||||
|
["清理本系列已读"] = "Clean up read in this series",
|
||||||
|
["没有可清理的缓存"] = "No cache to clean up",
|
||||||
|
["没有已读完的缓存"] = "No finished cache to clean up",
|
||||||
|
["%1 章"] = "%1 chapters",
|
||||||
|
["%1 卷"] = "%1 volumes",
|
||||||
|
["%1 章 · 约 %2"] = "%1 chapters · about %2",
|
||||||
|
["含未关联服务器"] = "Includes unlinked servers",
|
||||||
|
["含未关联服务器 · %1 章 · 约 %2"] = "Includes unlinked servers · %1 chapters · about %2",
|
||||||
|
["将删除 %1 章已读完的缓存(约 %2)。"] = "This deletes %1 finished chapters from the cache (about %2).",
|
||||||
|
["将删除本服务器的 %1 章(约 %2)。"] = "This deletes %1 chapters from this server (about %2).",
|
||||||
|
["将删除所有服务器(含未关联服务器)共 %1 章(约 %2)。"] = "This deletes %1 chapters from all servers (unlinked servers included; about %2).",
|
||||||
|
["将删除本系列 %1 卷缓存(约 %2)。"] = "This deletes the cache for %1 volumes in this series (about %2).",
|
||||||
|
["将删除本系列 %1 卷已读完的缓存(约 %2)。"] = "This deletes the cache for %1 finished volumes in this series (about %2).",
|
||||||
|
["会中止正在下载的 %1 章,已下载的部分会被删除。"] = "This aborts %1 downloading chapters; what was downloaded will be removed.",
|
||||||
|
["会中止正在下载的 %1 卷,已下载的部分会被删除。"] = "This aborts %1 downloading volumes; what was downloaded will be removed.",
|
||||||
|
["此操作不可撤销,之后阅读需要重新下载。"] = "This cannot be undone; reading again requires downloading again.",
|
||||||
|
["阅读进度与 kamare journal 保留。"] = "Reading progress and the kamare journal are kept.",
|
||||||
|
["已清理 %1 章,释放约 %2"] = "Cleaned %1 chapters, freeing about %2",
|
||||||
|
["已清理 %1 章,%2 章未能删除"] = "Cleaned %1 chapters; %2 could not be deleted",
|
||||||
|
["已清理 %1 卷,释放约 %2"] = "Cleaned %1 volumes, freeing about %2",
|
||||||
|
["已清理 %1 卷,%2 卷未能删除"] = "Cleaned %1 volumes; %2 could not be deleted",
|
||||||
|
["已清理全部缓存,释放约 %1"] = "Cleaned all cache, freeing about %1",
|
||||||
|
["当前 kamare 没有清理接口"] = "This kamare build has no cleanup API",
|
||||||
|
["升级到带 chapters / delete_all 的版本后才能清理"] = "Upgrade to a build with chapters / delete_all to clean up",
|
||||||
|
["增强版功能随版本不同,以实际安装的版本为准。"] = "Enhanced-build features vary by version; the installed build is authoritative.",
|
||||||
|
["漫画缓存"] = "Comic cache",
|
||||||
|
["清理已读、按系列或全部清理"] = "Clean up read, per series, or all",
|
||||||
|
["状态与获取增强版"] = "Status and getting the enhanced build",
|
||||||
|
["批量操作"] = "Batch actions",
|
||||||
|
["请先打开月读桌面"] = "Open the Moon Reader desktop first",
|
||||||
|
["无法识别 Kavita 版本"] = "Could not identify the Kavita version",
|
||||||
|
["Kavita %1 过旧,需要 0.9 及以上"] = "Kavita %1 is too old; 0.9 or later is required",
|
||||||
|
["部分缓存未能删除(权限或存储错误)"] = "Some cache files could not be deleted (permission or storage error)",
|
||||||
|
["缓存与同步"] = "Cache & sync",
|
||||||
|
["诊断"] = "Diagnostics",
|
||||||
|
["进度心跳间隔"] = "Progress heartbeat interval",
|
||||||
|
["阅读时补推进度,0 关闭"] = "Push progress while reading; 0 = off",
|
||||||
|
["请求超时"] = "Request timeout",
|
||||||
|
["%1 · 已下载"] = "%1 · Downloaded",
|
||||||
|
["API Key"] = "API Key",
|
||||||
|
["Kavita"] = "Kavita",
|
||||||
|
["Kavita API Key 无效或无权限"] = "Kavita API key is invalid or lacks permission",
|
||||||
|
["Kavita 上没有在读的书"] = "No books in progress on Kavita",
|
||||||
|
["Kavita 未确认注解已创建"] = "Kavita did not confirm the annotation was created",
|
||||||
|
["Kavita 注解删除后复核失败"] = "Kavita could not verify the annotation deletion",
|
||||||
|
["Kavita 注解删除失败"] = "Kavita annotation deletion failed",
|
||||||
|
["Kavita 用户设置 → API Key"] = "Kavita user settings → API Key",
|
||||||
|
["Kavita 继续阅读"] = "Continue reading on Kavita",
|
||||||
|
["划线无法定位,本轮暂不推送:%1"] = "Highlight could not be anchored; not pushed this round: %1",
|
||||||
|
["响应不是 JSON"] = "Response is not JSON",
|
||||||
|
["图片目录格式需要安装 kamare 插件在线阅读"] = "Image-directory format requires the kamare plugin to read online",
|
||||||
|
["正在拉取书架(%1 本)"] = "Fetching shelf (%1 books)",
|
||||||
|
["正在连接 Kavita…"] = "Connecting to Kavita…",
|
||||||
|
["联网后显示 Kavita 上在读的书"] = "Books in progress on Kavita appear when online",
|
||||||
|
["请先在设置里填写 Kavita 服务器并选择书库"] = "Set the Kavita server and select a library in settings first",
|
||||||
|
["请先填写服务器地址和 API Key"] = "Fill in the server address and API key first",
|
||||||
|
["这一卷已不在 Kavita 上"] = "This volume is no longer on Kavita",
|
||||||
|
["这本书在 Kavita 上没有可读的卷"] = "No readable volumes for this book on Kavita",
|
||||||
|
["选择书库"] = "Select libraries",
|
||||||
|
["进度同步"] = "Progress sync",
|
||||||
|
["漫画缓存(需 kamare 增强版)"] = "Comic cache (needs kamare enhanced build)",
|
||||||
|
["连接 Kavita 服务器的漫画与电子书"] = "Comics and e-books from a Kavita server",
|
||||||
|
["第 %1 卷"] = "Vol. %1",
|
||||||
|
["上次翻阅"] = "Last opened",
|
||||||
|
["已读完 · 共 %1 卷"] = "Finished · %1 volumes",
|
||||||
|
["开始阅读 · %1"] = "Start reading · %1",
|
||||||
|
["第 %1/%2 页 · %3%"] = "Page %1/%2 · %3%",
|
||||||
|
["继续阅读 · %1"] = "Continue reading · %1",
|
||||||
|
["重读 · %1"] = "Read again · %1",
|
||||||
|
["共 %1 页"] = "%1 pages total",
|
||||||
|
["选择卷"] = "Choose a volume",
|
||||||
|
}
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
return {
|
||||||
|
["EPUB 划线同步"] = "EPUB 畫線同步",
|
||||||
|
["书架与卷目录同步(只读)"] = "書架與卷目錄同步(唯讀)",
|
||||||
|
["同步 Kavita 书架、电子书与漫画"] = "同步 Kavita 書架、電子書與漫畫",
|
||||||
|
["漫画在线阅读与缓存(需 kamare 增强版)"] = "漫畫線上閱讀與快取(需 kamare 增強版)",
|
||||||
|
["阅读历史拉取"] = "取得閱讀歷史",
|
||||||
|
["下载文件校验失败"] = "下載檔案校驗失敗",
|
||||||
|
["确定退出 Kavita 账号?"] = "確定登出 Kavita 帳號?",
|
||||||
|
["正在下载…"] = "正在下載…",
|
||||||
|
["章节目录保存失败"] = "章節目錄儲存失敗",
|
||||||
|
["请求失败 (HTTP %1)"] = "請求失敗 (HTTP %1)",
|
||||||
|
["连接失败"] = "連接失敗",
|
||||||
|
["打开漫画阅读器失败"] = "無法開啟漫畫閱讀器",
|
||||||
|
["漫画阅读器已在运行"] = "漫畫閱讀器已在執行",
|
||||||
|
["这一卷还没缓存,联网后可下载"] = "這一卷還沒快取,連網後可下載",
|
||||||
|
["这一卷没有可显示的页面"] = "這一卷沒有可顯示的頁面",
|
||||||
|
["下一卷不在目录里"] = "下一卷不在目錄裡",
|
||||||
|
["无法写入 kamare 配置"] = "無法寫入 kamare 設定",
|
||||||
|
["没有可重试的任务"] = "沒有可重試的任務",
|
||||||
|
["正在阅读这一卷,关闭后可以删除"] = "正在閱讀這一卷,關閉後可以刪除",
|
||||||
|
["需要安装带缓存接口的增强版 kamare"] = "需要安裝帶快取介面的增強版 kamare",
|
||||||
|
["无法同步配置到 kamare"] = "無法同步設定到 kamare",
|
||||||
|
["%1 MB"] = "%1 MB",
|
||||||
|
["空间不足:需要 %1,可用 %2"] = "空間不足:需要 %1,可用 %2",
|
||||||
|
["缓存空间已满:需要 %1,上限 %2"] = "快取空間已滿:需要 %1,上限 %2",
|
||||||
|
["可用空间低于 %1,清理后再下载"] = "可用空間低於 %1,清理後再下載",
|
||||||
|
["缓存操作失败"] = "快取操作失敗",
|
||||||
|
["全部已缓存或正在下载"] = "全部已快取或正在下載",
|
||||||
|
["可用空间不足(剩余 %1),清理后再下载"] = "可用空間不足(剩餘 %1),清理後再下載",
|
||||||
|
["服务器拒绝下载(403),检查 API Key / 权限"] = "伺服器拒絕下載(403),檢查 API Key / 權限",
|
||||||
|
["下载内容不完整或不是有效压缩包"] = "下載內容不完整或不是有效壓縮檔",
|
||||||
|
["存储空间不足或写入失败"] = "儲存空間不足或寫入失敗",
|
||||||
|
["网络中断或服务器不可达"] = "網路中斷或伺服器無法連線",
|
||||||
|
["缓存失败:%1"] = "快取失敗:%1",
|
||||||
|
["配置同步失败"] = "設定同步失敗",
|
||||||
|
["增强版 v%1"] = "增強版 v%1",
|
||||||
|
["增强版"] = "增強版",
|
||||||
|
["版本不兼容"] = "版本不相容",
|
||||||
|
["官方版(无缓存接口)"] = "官方版(無快取介面)",
|
||||||
|
["未安装 / 未启用"] = "未安裝 / 未啟用",
|
||||||
|
["连接正常"] = "連線正常",
|
||||||
|
["Kavita %1"] = "Kavita %1",
|
||||||
|
["未加载"] = "未載入",
|
||||||
|
["获取增强版"] = "取得增強版",
|
||||||
|
["秒"] = "秒",
|
||||||
|
["检查 Kavita 服务器连接与版本"] = "檢查 Kavita 伺服器連線與版本",
|
||||||
|
["kamare 增强版"] = "kamare 增強版",
|
||||||
|
["点按检查 kamare 增强版更新"] = "點按檢查 kamare 增強版更新",
|
||||||
|
["点按安装 kamare 增强版"] = "點按安裝 kamare 增強版",
|
||||||
|
["点按安装兼容的 kamare 增强版"] = "點按安裝相容的 kamare 增強版",
|
||||||
|
["点按检查并安装 kamare 增强版"] = "點按檢查並安裝 kamare 增強版",
|
||||||
|
["官方版"] = "官方版",
|
||||||
|
[" 也可点上方「kamare 增强版」检查并安装最新版。"] = " 也可點上方「kamare 增強版」檢查並安裝最新版。",
|
||||||
|
["正在检查 kamare 更新…"] = "正在檢查 kamare 更新…",
|
||||||
|
["更新 kamare"] = "更新 kamare",
|
||||||
|
["发现 kamare %1(当前 %2)。下载并完整替换插件目录?"] = "發現 kamare %1(目前 %2)。下載並完整取代外掛目錄?",
|
||||||
|
["当前未安装可用的 kamare 增强版。安装最新版 %1?"] = "目前未安裝可用的 kamare 增強版。安裝最新版 %1?",
|
||||||
|
["正在下载 kamare 更新…"] = "正在下載 kamare 更新…",
|
||||||
|
["正在安装 kamare 更新…"] = "正在安裝 kamare 更新…",
|
||||||
|
["kamare 更新失败:%1"] = "kamare 更新失敗:%1",
|
||||||
|
[" 发布页:github.com/backtracker/kamare.koplugin/releases/latest"] = " 發布頁:github.com/backtracker/kamare.koplugin/releases/latest",
|
||||||
|
[" 下载 kamare.koplugin.zip,解压后把 kamare.koplugin/ 放进:%1"] = " 下載 kamare.koplugin.zip,解壓後把 kamare.koplugin/ 放進:%1",
|
||||||
|
[" 重启 KOReader。包里要有 kamarecache.lua(没有就是官方版);"] = " 重新啟動 KOReader。壓縮檔裡要有 kamarecache.lua(沒有就是官方版);",
|
||||||
|
[" 增强版与官方版目录同名,不能共存;替换前先删掉旧的 kamare.koplugin/。"] = " 增強版與官方版目錄同名,不能共存;替換前先刪掉舊的 kamare.koplugin/。",
|
||||||
|
[" 如该目录不可写,可改用:%1"] = " 如該目錄不可寫,可改用:%1",
|
||||||
|
["%1 · 已缓存"] = "%1 · 已快取",
|
||||||
|
["%1 · 待同步"] = "%1 · 待同步",
|
||||||
|
["%1 · 离线"] = "%1 · 離線",
|
||||||
|
["%1 卷成功,%2 卷失败"] = "%1 卷成功,%2 卷失敗",
|
||||||
|
["%1 等 %2 卷"] = "%1 等 %2 卷",
|
||||||
|
["下载中 %1%"] = "下載中 %1%",
|
||||||
|
["全部已缓存"] = "全部已快取",
|
||||||
|
["删除「%1」的缓存?将释放 %2。"] = "刪除「%1」的快取?將釋放 %2。",
|
||||||
|
["删除会取消这一卷的下载。"] = "刪除會取消這一卷的下載。",
|
||||||
|
["删除后离线不可读。"] = "刪除後離線不可讀。",
|
||||||
|
["删除缓存"] = "刪除快取",
|
||||||
|
["去清理空间"] = "去清理空間",
|
||||||
|
["另有 %1 卷失败将重试"] = "另有 %1 卷失敗將重試",
|
||||||
|
["完成后剩余 %1"] = "完成後剩餘 %1",
|
||||||
|
["将缓存:%1"] = "將快取:%1",
|
||||||
|
["将重试:%1"] = "將重試:%1",
|
||||||
|
["已排队"] = "已排隊",
|
||||||
|
["已暂停"] = "已暫停",
|
||||||
|
["已暂停整个下载队列"] = "已暫停整個下載佇列",
|
||||||
|
["已暂停 %1%"] = "已暫停 %1%",
|
||||||
|
["已暂停(仅 Wi-Fi 下载)"] = "已暫停(僅 Wi-Fi 下載)",
|
||||||
|
["已暂停(启动恢复)"] = "已暫停(啟動恢復)",
|
||||||
|
["已暂停(断网)"] = "已暫停(斷網)",
|
||||||
|
["已暂停(连续下载失败)"] = "已暫停(連續下載失敗)",
|
||||||
|
["已缓存 %1 卷"] = "已快取 %1 卷",
|
||||||
|
["缓存已中断"] = "快取已中斷",
|
||||||
|
["开始缓存"] = "開始快取",
|
||||||
|
["当前下载已暂停,开始缓存会恢复整个队列"] = "目前下載已暫停,開始快取會恢復整個佇列",
|
||||||
|
["未缓存"] = "未快取",
|
||||||
|
["查看失败原因"] = "查看失敗原因",
|
||||||
|
["正在缓存 %1/%2 卷"] = "正在快取 %1/%2 卷",
|
||||||
|
["清理后再下载"] = "清理後再下載",
|
||||||
|
["空间不足"] = "空間不足",
|
||||||
|
["空间不足,已暂停"] = "空間不足,已暫停",
|
||||||
|
["空间不足,已暂停。清理后再下载"] = "空間不足,已暫停。清理後再下載",
|
||||||
|
["缓存 %1 卷"] = "快取 %1 卷",
|
||||||
|
["缓存这一卷"] = "快取這一卷",
|
||||||
|
["设备可用 %1"] = "裝置可用 %1",
|
||||||
|
["部分失败"] = "部分失敗",
|
||||||
|
["重试"] = "重試",
|
||||||
|
["重试失败项并继续"] = "重試失敗項並繼續",
|
||||||
|
["重试缓存"] = "重試快取",
|
||||||
|
["预计占用 %1(峰值)"] = "預計佔用 %1(峰值)",
|
||||||
|
["缓存整部"] = "快取整部",
|
||||||
|
["缓存未读"] = "快取未讀",
|
||||||
|
["没有未读的卷"] = "沒有未讀的卷",
|
||||||
|
["缓存后 N 卷…"] = "快取後 N 卷…",
|
||||||
|
["缓存后 N 卷"] = "快取後 N 卷",
|
||||||
|
["卷数"] = "卷數",
|
||||||
|
["增强版 v%1(旧接口)"] = "增強版 v%1(舊介面)",
|
||||||
|
["增强版(旧接口)"] = "增強版(舊介面)",
|
||||||
|
["kamare API v%1 与当前支持的 v1 不兼容;装回支持 v1 的增强版后可管理缓存"] = "kamare API v%1 與目前支援的 v1 不相容;裝回支援 v1 的增強版後可管理快取",
|
||||||
|
["版本与获取"] = "版本與取得",
|
||||||
|
["正在统计…"] = "正在統計…",
|
||||||
|
["正在清理…"] = "正在清理…",
|
||||||
|
["增强版功能"] = "增強版功能",
|
||||||
|
["加载路径"] = "載入路徑",
|
||||||
|
["缓存占用"] = "快取佔用",
|
||||||
|
["已用 %1%2,可用 %3"] = "已用 %1%2,可用 %3",
|
||||||
|
["(含未关联服务器)"] = "(含未關聯伺服器)",
|
||||||
|
["重试同步"] = "重試同步",
|
||||||
|
["已重新同步配置"] = "已重新同步設定",
|
||||||
|
["服务器配置没能写入 kamare,缓存操作可能找不到服务器"] = "伺服器設定沒能寫入 kamare,快取操作可能找不到伺服器",
|
||||||
|
["未配置服务器"] = "未設定伺服器",
|
||||||
|
["填写服务器地址与 API Key 后,可按服务器清理已读或全部缓存"] = "填寫伺服器位址與 API Key 後,可按伺服器清理已讀或全部快取",
|
||||||
|
["清理已读"] = "清理已讀",
|
||||||
|
["清理本服务器"] = "清理本伺服器",
|
||||||
|
["清理全部"] = "清理全部",
|
||||||
|
["清理全部缓存"] = "清理全部快取",
|
||||||
|
["清理本系列"] = "清理本系列",
|
||||||
|
["清理本系列已读"] = "清理本系列已讀",
|
||||||
|
["没有可清理的缓存"] = "沒有可清理的快取",
|
||||||
|
["没有已读完的缓存"] = "沒有已讀完的快取",
|
||||||
|
["%1 章"] = "%1 章",
|
||||||
|
["%1 卷"] = "%1 卷",
|
||||||
|
["%1 章 · 约 %2"] = "%1 章 · 約 %2",
|
||||||
|
["含未关联服务器"] = "含未關聯伺服器",
|
||||||
|
["含未关联服务器 · %1 章 · 约 %2"] = "含未關聯伺服器 · %1 章 · 約 %2",
|
||||||
|
["将删除 %1 章已读完的缓存(约 %2)。"] = "將刪除 %1 章已讀完的快取(約 %2)。",
|
||||||
|
["将删除本服务器的 %1 章(约 %2)。"] = "將刪除本伺服器的 %1 章(約 %2)。",
|
||||||
|
["将删除所有服务器(含未关联服务器)共 %1 章(约 %2)。"] = "將刪除所有伺服器(含未關聯伺服器)共 %1 章(約 %2)。",
|
||||||
|
["将删除本系列 %1 卷缓存(约 %2)。"] = "將刪除本系列 %1 卷快取(約 %2)。",
|
||||||
|
["将删除本系列 %1 卷已读完的缓存(约 %2)。"] = "將刪除本系列 %1 卷已讀完的快取(約 %2)。",
|
||||||
|
["会中止正在下载的 %1 章,已下载的部分会被删除。"] = "會中止正在下載的 %1 章,已下載的部分會被刪除。",
|
||||||
|
["会中止正在下载的 %1 卷,已下载的部分会被删除。"] = "會中止正在下載的 %1 卷,已下載的部分會被刪除。",
|
||||||
|
["此操作不可撤销,之后阅读需要重新下载。"] = "此操作無法復原,之後閱讀需要重新下載。",
|
||||||
|
["阅读进度与 kamare journal 保留。"] = "閱讀進度與 kamare journal 保留。",
|
||||||
|
["已清理 %1 章,释放约 %2"] = "已清理 %1 章,釋放約 %2",
|
||||||
|
["已清理 %1 章,%2 章未能删除"] = "已清理 %1 章,%2 章未能刪除",
|
||||||
|
["已清理 %1 卷,释放约 %2"] = "已清理 %1 卷,釋放約 %2",
|
||||||
|
["已清理 %1 卷,%2 卷未能删除"] = "已清理 %1 卷,%2 卷未能刪除",
|
||||||
|
["已清理全部缓存,释放约 %1"] = "已清理全部快取,釋放約 %1",
|
||||||
|
["当前 kamare 没有清理接口"] = "目前 kamare 沒有清理介面",
|
||||||
|
["升级到带 chapters / delete_all 的版本后才能清理"] = "升級到帶 chapters / delete_all 的版本後才能清理",
|
||||||
|
["增强版功能随版本不同,以实际安装的版本为准。"] = "增強版功能隨版本不同,以實際安裝的版本為準。",
|
||||||
|
["漫画缓存"] = "漫畫快取",
|
||||||
|
["清理已读、按系列或全部清理"] = "清理已讀、按系列或全部清理",
|
||||||
|
["状态与获取增强版"] = "狀態與取得增強版",
|
||||||
|
["批量操作"] = "批次操作",
|
||||||
|
["请先打开月读桌面"] = "請先開啟月讀桌面",
|
||||||
|
["无法识别 Kavita 版本"] = "無法辨識 Kavita 版本",
|
||||||
|
["Kavita %1 过旧,需要 0.9 及以上"] = "Kavita %1 過舊,需要 0.9 及以上",
|
||||||
|
["部分缓存未能删除(权限或存储错误)"] = "部分快取未能刪除(權限或儲存錯誤)",
|
||||||
|
["缓存与同步"] = "快取與同步",
|
||||||
|
["诊断"] = "診斷",
|
||||||
|
["进度心跳间隔"] = "進度心跳間隔",
|
||||||
|
["阅读时补推进度,0 关闭"] = "閱讀時補推進度,0 關閉",
|
||||||
|
["请求超时"] = "請求逾時",
|
||||||
|
["%1 · 已下载"] = "%1 · 已下載",
|
||||||
|
["API Key"] = "API Key",
|
||||||
|
["Kavita"] = "Kavita",
|
||||||
|
["Kavita API Key 无效或无权限"] = "Kavita API Key 無效或無權限",
|
||||||
|
["Kavita 上没有在读的书"] = "Kavita 上沒有在讀的書",
|
||||||
|
["Kavita 未确认注解已创建"] = "Kavita 未確認註解已建立",
|
||||||
|
["Kavita 注解删除后复核失败"] = "Kavita 註解刪除後複核失敗",
|
||||||
|
["Kavita 注解删除失败"] = "Kavita 註解刪除失敗",
|
||||||
|
["Kavita 用户设置 → API Key"] = "Kavita 使用者設定 → API Key",
|
||||||
|
["Kavita 继续阅读"] = "Kavita 繼續閱讀",
|
||||||
|
["划线无法定位,本轮暂不推送:%1"] = "劃線無法定位,本輪暫不推送:%1",
|
||||||
|
["响应不是 JSON"] = "回應不是 JSON",
|
||||||
|
["图片目录格式需要安装 kamare 插件在线阅读"] = "圖片目錄格式需要安裝 kamare 外掛線上閱讀",
|
||||||
|
["正在拉取书架(%1 本)"] = "正在拉取書架(%1 本)",
|
||||||
|
["正在连接 Kavita…"] = "正在連線 Kavita…",
|
||||||
|
["联网后显示 Kavita 上在读的书"] = "連網後顯示 Kavita 上在讀的書",
|
||||||
|
["请先在设置里填写 Kavita 服务器并选择书库"] = "請先在設定裡填寫 Kavita 伺服器並選擇書庫",
|
||||||
|
["请先填写服务器地址和 API Key"] = "請先填寫伺服器位址和 API Key",
|
||||||
|
["这一卷已不在 Kavita 上"] = "這一卷已不在 Kavita 上",
|
||||||
|
["这本书在 Kavita 上没有可读的卷"] = "這本書在 Kavita 上沒有可讀的卷",
|
||||||
|
["选择书库"] = "選擇書庫",
|
||||||
|
["进度同步"] = "進度同步",
|
||||||
|
["漫画缓存(需 kamare 增强版)"] = "漫畫快取(需 kamare 增強版)",
|
||||||
|
["连接 Kavita 服务器的漫画与电子书"] = "連接 Kavita 伺服器的漫畫與電子書",
|
||||||
|
["第 %1 卷"] = "第 %1 卷",
|
||||||
|
["上次翻阅"] = "上次翻閱",
|
||||||
|
["已读完 · 共 %1 卷"] = "已讀完 · 共 %1 卷",
|
||||||
|
["开始阅读 · %1"] = "開始閱讀 · %1",
|
||||||
|
["第 %1/%2 页 · %3%"] = "第 %1/%2 頁 · %3%",
|
||||||
|
["继续阅读 · %1"] = "繼續閱讀 · %1",
|
||||||
|
["重读 · %1"] = "重讀 · %1",
|
||||||
|
["共 %1 页"] = "共 %1 頁",
|
||||||
|
["选择卷"] = "選擇卷",
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
return function()
|
||||||
|
local copy = {}
|
||||||
|
for k, v in pairs(require("moonsource_kavita._meta")) do copy[k] = v end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita 系列书评映射;个人评价列表和章节评价不混入系列书评。
|
||||||
|
|
||||||
|
@module moonsource_kavita.mapper
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local Text = require("utils.text")
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
|
||||||
|
local Mapper = {}
|
||||||
|
|
||||||
|
---@param wire table
|
||||||
|
---@param series_id string
|
||||||
|
---@return table|nil, string|nil
|
||||||
|
function Mapper.bookReviewPage(wire, series_id)
|
||||||
|
local rows = type(wire) == "table" and wire.reviews
|
||||||
|
if type(rows) ~= "table" then return nil, _("响应无效") end
|
||||||
|
local items = {}
|
||||||
|
for _idx, row in ipairs(rows) do
|
||||||
|
if type(row) ~= "table" or type(row.body) ~= "string"
|
||||||
|
or type(row.chapterId) ~= "number" or type(row.username) ~= "string" then
|
||||||
|
return nil, _("响应无效")
|
||||||
|
end
|
||||||
|
if row.isExternal ~= true and tostring(row.seriesId) ~= series_id then
|
||||||
|
return nil, _("响应无效")
|
||||||
|
end
|
||||||
|
if row.chapterId == 0 then
|
||||||
|
local body = type(row.bodyJustText) == "string" and row.bodyJustText ~= ""
|
||||||
|
and row.bodyJustText or Text.stripHtml(row.body)
|
||||||
|
local title = type(row.tagline) == "string" and Text.trim(row.tagline) or ""
|
||||||
|
local text = title ~= "" and title .. "\n" .. body or body
|
||||||
|
if Text.trim(text) ~= "" then
|
||||||
|
items[#items + 1] = { author = row.username, text = text, time = "",
|
||||||
|
grade = tonumber(row.rating), likes = tonumber(row.totalVotes) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return { items = items, total = #items, pages = 1, title = _("书评") }
|
||||||
|
end
|
||||||
|
|
||||||
|
return Mapper
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
--[[--
|
||||||
|
首页组件:Kavita「继续阅读」(On Deck)。在线且已配置时拉一次,5 分钟内复用;
|
||||||
|
跟首页「最近阅读列表」同一套封面网格(CoverCell.denseCoverMetrics + Book.widget):
|
||||||
|
每页 4 本,多了分页;点开走月读开书流程(多卷 series 会先选卷)。
|
||||||
|
|
||||||
|
@module moonsource_kavita.on_deck
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local Base = require("desktop.pages.home.base")
|
||||||
|
local Book = require("ui.widgets.book")
|
||||||
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||||
|
local CoverCell = require("ui.widgets.cover")
|
||||||
|
local Geom = require("ui/geometry")
|
||||||
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||||
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||||
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||||
|
local VerticalSpan = require("ui/widget/verticalspan")
|
||||||
|
local Pager = require("ui.themes.widgets.pager")
|
||||||
|
local Theme = require("ui.themes")
|
||||||
|
local Tap = require("ui.themes.widgets.tap")
|
||||||
|
local Text = require("ui.themes.widgets.text")
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
|
||||||
|
local ID = "kavita"
|
||||||
|
local MAX_BOOKS = 10
|
||||||
|
local TTL = 300
|
||||||
|
-- 跟首页「最近阅读」一页一样:一行 4 本(封面大),多的分页。
|
||||||
|
local COLS = 4
|
||||||
|
local ROWS = 1
|
||||||
|
|
||||||
|
---@class KavitaOnDeck : BookHomeComponent
|
||||||
|
---@field job { cancel: fun() }|nil
|
||||||
|
---@field loaded_at integer|nil
|
||||||
|
---@field err string|nil
|
||||||
|
local M = {
|
||||||
|
id = "kavita.on_deck",
|
||||||
|
label = _("Kavita 继续阅读"),
|
||||||
|
icon = "collections_bookmark",
|
||||||
|
}
|
||||||
|
setmetatable(M, Base)
|
||||||
|
M.__index = M
|
||||||
|
|
||||||
|
--- 网格尺寸:跟首页「最近阅读列表」共用 CoverCell.denseCoverMetrics,封面与槽位口径一致
|
||||||
|
---(封面在固定宽的槽里居中,标题按槽宽居中,不会一本书看着变小/错位)。
|
||||||
|
--- 列数固定 4(一页 4 本,封面才够大);area_h 有值时再收到放得下。
|
||||||
|
---@param width integer
|
||||||
|
---@param area_h integer|nil 分配到的可用高度
|
||||||
|
---@return integer slot_w
|
||||||
|
---@return integer cw
|
||||||
|
---@return integer ch
|
||||||
|
---@return integer gap
|
||||||
|
---@return integer row_gap
|
||||||
|
---@return integer cell_h
|
||||||
|
local function gridMetrics(width, area_h)
|
||||||
|
local extra = Book.captionExtra(true, false)
|
||||||
|
local max_h = CoverCell.gridCoverMaxH(area_h)
|
||||||
|
local slot_w, cw, ch, _cols, gap, row_gap, cell_h = CoverCell.denseCoverMetrics(
|
||||||
|
math.max(1, math.floor(tonumber(width) or 1)), 0, {
|
||||||
|
title_extra = extra,
|
||||||
|
max_h = max_h,
|
||||||
|
min_cols = COLS,
|
||||||
|
max_cols = COLS,
|
||||||
|
})
|
||||||
|
if ch > max_h then
|
||||||
|
ch = max_h
|
||||||
|
cw = math.max(1, math.min(slot_w, math.floor(ch * 2 / 3)))
|
||||||
|
cell_h = ch + extra
|
||||||
|
end
|
||||||
|
area_h = math.floor(tonumber(area_h) or 0)
|
||||||
|
if area_h > 0 then
|
||||||
|
local gaps = row_gap * (ROWS - 1)
|
||||||
|
if cell_h * ROWS + gaps > area_h then
|
||||||
|
local fit_cell = math.max(1, math.floor((area_h - gaps) / ROWS))
|
||||||
|
ch = math.max(1, math.min(ch, fit_cell - extra))
|
||||||
|
cw = math.max(1, math.min(slot_w, math.floor(ch * 2 / 3)))
|
||||||
|
cell_h = math.min(ch + extra, fit_cell)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return slot_w, cw, ch, gap, row_gap, cell_h
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 分页条高度:On Deck 最多 10 本 > 一页 4 本,恒有分页。
|
||||||
|
---@return integer
|
||||||
|
local function pagerHeight()
|
||||||
|
return MAX_BOOKS > COLS * ROWS and Theme.px(Theme.current().control.height) or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function M:heightRange(_ctx, opts)
|
||||||
|
local _slot_w, _cw, _ch, _gap, row_gap, cell_h = gridMetrics(tonumber(opts and opts.width) or 0)
|
||||||
|
return { height = cell_h * ROWS + row_gap * (ROWS - 1) + pagerHeight() }
|
||||||
|
end
|
||||||
|
|
||||||
|
function M:onActivate()
|
||||||
|
if self.job or (self.loaded_at and os.time() - self.loaded_at < TTL) then return end
|
||||||
|
local source = require("source.registry").resolve(ID) --[[@as KavitaSource|nil]]
|
||||||
|
if not (source and source:configured() and require("ui/network/manager"):isConnected()) then return end
|
||||||
|
self.job = source.client:json("POST", "/api/Series/on-deck", { pageNumber = 1, pageSize = MAX_BOOKS }, {},
|
||||||
|
function(list, err)
|
||||||
|
self.job = nil
|
||||||
|
self.loaded_at, self.err = os.time(), err
|
||||||
|
if list then
|
||||||
|
local books = {}
|
||||||
|
for idx, series in ipairs(list) do
|
||||||
|
local pages = tonumber(series.pages) or 0
|
||||||
|
books[idx] = {
|
||||||
|
source_id = ID,
|
||||||
|
stable_id = tostring(series.id),
|
||||||
|
title = series.name,
|
||||||
|
percent = pages > 0 and math.min(100, (tonumber(series.pagesRead) or 0) * 100 / pages) or 0,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
self.data = books
|
||||||
|
end
|
||||||
|
self:refresh()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M:onDeactivate()
|
||||||
|
if self.job then
|
||||||
|
self.job:cancel()
|
||||||
|
self.job = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param w integer
|
||||||
|
---@param h integer
|
||||||
|
---@param text string
|
||||||
|
---@return table
|
||||||
|
local function hint(w, h, text)
|
||||||
|
return CenterContainer:new{
|
||||||
|
dimen = Geom:new{ w = w, h = h },
|
||||||
|
Text.line("body", text, { width = w, color = Theme.current().color.muted }),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function M:createWidget()
|
||||||
|
local ctx, w, h = self.ctx, self.opts.width, self.opts.height
|
||||||
|
local books = self.data
|
||||||
|
if not books then return hint(w, h, self.err or _("联网后显示 Kavita 上在读的书")) end
|
||||||
|
if #books == 0 then return hint(w, h, _("Kavita 上没有在读的书")) end
|
||||||
|
local page_size = COLS * ROWS
|
||||||
|
local pages = math.max(1, math.ceil(#books / page_size))
|
||||||
|
local pager_h = pages > 1 and Theme.px(Theme.current().control.height) or 0
|
||||||
|
local grid_h = math.max(1, h - pager_h)
|
||||||
|
local slot_w, cw, ch, gap, row_gap = gridMetrics(w, grid_h)
|
||||||
|
local page = math.max(1, math.min(self.page or 1, pages))
|
||||||
|
self.page = page
|
||||||
|
local first = (page - 1) * page_size + 1
|
||||||
|
local last = math.min(#books, first + page_size - 1)
|
||||||
|
local grid = VerticalGroup:new{ align = "center" }
|
||||||
|
local row, col = nil, 0
|
||||||
|
for i = first, last do
|
||||||
|
if not row or col == COLS then
|
||||||
|
if row then grid[#grid + 1] = VerticalSpan:new{ width = row_gap } end
|
||||||
|
row, col = HorizontalGroup:new{ align = "top" }, 0
|
||||||
|
grid[#grid + 1] = row
|
||||||
|
end
|
||||||
|
col = col + 1
|
||||||
|
if col > 1 then row[#row + 1] = HorizontalSpan:new{ width = gap } end
|
||||||
|
local book = books[i]
|
||||||
|
-- 跟最近阅读列表同一条路:Book.widget 居中封面 + 标题,槽宽用 slot_w。
|
||||||
|
local cell = Book.widget(ctx.plugin, nil, book, cw, ch, {
|
||||||
|
slot_w = slot_w,
|
||||||
|
badge = false,
|
||||||
|
ribbon = false,
|
||||||
|
download = false,
|
||||||
|
show_parent = ctx.desktop,
|
||||||
|
home = true,
|
||||||
|
})
|
||||||
|
row[#row + 1] = Tap.wrap(cell, function() Base.openBook(ctx, book) end)
|
||||||
|
end
|
||||||
|
local out = VerticalGroup:new{
|
||||||
|
align = "center",
|
||||||
|
CenterContainer:new{ dimen = Geom:new{ w = w, h = grid_h }, grid },
|
||||||
|
}
|
||||||
|
if pages > 1 then
|
||||||
|
out[#out + 1] = Pager.widget({
|
||||||
|
width = w,
|
||||||
|
page = page,
|
||||||
|
pages = pages,
|
||||||
|
on_prev = function() self.page = page - 1; self:refresh() end,
|
||||||
|
on_next = function() self.page = page + 1; self:refresh() end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -0,0 +1,259 @@
|
|||||||
|
--[[--
|
||||||
|
KOReader xpointer ↔ Kavita 书籍进度(pageNum + bookScrollId)。
|
||||||
|
|
||||||
|
Kavita 的 epub 进度以 spine 为单位:pageNum 是 0-based spine 序号(KOReader 的
|
||||||
|
`DocFragment[D]` = spine D-1),pageNum == pages 表示读完;bookScrollId 是章内锚点,
|
||||||
|
本插件上报 `//body/...` 路径,Kavita 网页端上报 `id("X")`,后者要读本地 epub 才能还原成路径。
|
||||||
|
|
||||||
|
@module moonsource_kavita.position
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local Position = {}
|
||||||
|
|
||||||
|
local VOID = {
|
||||||
|
br = true, img = true, hr = true, meta = true, link = true, input = true,
|
||||||
|
area = true, base = true, col = true, embed = true, source = true, track = true, wbr = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
--- xpointer 所在 spine(0-based)。单 spine 书 crengine 写 `DocFragment/body`(无下标)。
|
||||||
|
---@param locator string|nil
|
||||||
|
---@return integer|nil
|
||||||
|
function Position.spine(locator)
|
||||||
|
if type(locator) ~= "string" then return nil end
|
||||||
|
local d = locator:match("DocFragment%[(%d+)%]")
|
||||||
|
if d then return tonumber(d) - 1 end
|
||||||
|
if locator:match("/DocFragment/") then return 0 end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- xpointer → `//body/...`(同名兄弟下标补全为 [1],丢弃文本偏移)。body 内无元素返回 nil。
|
||||||
|
---@param locator string|nil
|
||||||
|
---@return string|nil
|
||||||
|
function Position.toScrollId(locator)
|
||||||
|
if type(locator) ~= "string" then return nil end
|
||||||
|
-- crengine 两种写法都有:`/body/DocFragment[N]/body/...` 与归一化的 `/body[1]/DocFragment[N]/body[1]/...`。
|
||||||
|
local rest = locator:match("^/body%[%d+%]/DocFragment%[?%d*%]?/body%[%d+%](.*)$")
|
||||||
|
or locator:match("^/body/DocFragment%[?%d*%]?/body(.*)$")
|
||||||
|
if not rest then return nil end
|
||||||
|
local parts = {}
|
||||||
|
for seg in rest:gmatch("[^/]+") do
|
||||||
|
if not seg:match("^text%(") then
|
||||||
|
local name, index = seg:match("^([%w:_%-]+)%[(%d+)%]$")
|
||||||
|
name = name or seg:match("^([%w:_%-]+)")
|
||||||
|
if name then parts[#parts + 1] = name .. "[" .. (index or "1") .. "]" end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #parts == 0 then return nil end
|
||||||
|
return "//body/" .. table.concat(parts, "/")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- spine + `//body/...` → xpointer。pageNum == pages(读完)落回最后一个 spine。
|
||||||
|
---@param spine integer
|
||||||
|
---@param scroll_id string|nil
|
||||||
|
---@param pages integer spine 总数
|
||||||
|
---@return string
|
||||||
|
function Position.toXPointer(spine, scroll_id, pages)
|
||||||
|
local n = math.max(0, math.min(spine, pages - 1))
|
||||||
|
local tail = ""
|
||||||
|
local path = type(scroll_id) == "string" and scroll_id:match("^//body/(.+)$")
|
||||||
|
if path then
|
||||||
|
for seg in path:gmatch("[^/]+") do
|
||||||
|
-- crengine 规范:[1] 省略。
|
||||||
|
tail = tail .. "/" .. (seg:gsub("%[1%]$", ""))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local fragment = pages == 1 and "DocFragment" or ("DocFragment[" .. (n + 1) .. "]")
|
||||||
|
return "/body/" .. fragment .. "/body" .. tail
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param base string
|
||||||
|
---@param href string
|
||||||
|
---@return string
|
||||||
|
local function joinPath(base, href)
|
||||||
|
local parts = {}
|
||||||
|
for seg in ((base ~= "" and base .. "/" or "") .. href):gmatch("[^/]+") do
|
||||||
|
if seg == ".." then
|
||||||
|
table.remove(parts)
|
||||||
|
elseif seg ~= "." then
|
||||||
|
parts[#parts + 1] = seg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return table.concat(parts, "/")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 打开 epub 交给 fn({ count, html(spine) })。用户的 epub 什么样都有:
|
||||||
|
--- 打不开、解析抛错一律返回 nil,调用方降级(只按 spine 定位 / 不带锚点),不能让开书或同步失败。
|
||||||
|
---@param epub_path string|nil
|
||||||
|
---@param fn fun(doc: { count: integer, html: fun(spine: integer): string|nil }): any
|
||||||
|
---@return any
|
||||||
|
local function withEpub(epub_path, fn)
|
||||||
|
if not epub_path then return nil end
|
||||||
|
local arc = require("ffi/archiver").Reader:new()
|
||||||
|
if not arc:open(epub_path) then return nil end
|
||||||
|
local ok, result = pcall(function()
|
||||||
|
-- archiver 要先扫一遍条目,extractToMemory 才找得到文件。
|
||||||
|
for _entry in arc:iterate() do end
|
||||||
|
local opf_path = (arc:extractToMemory("META-INF/container.xml") or ""):match('full%-path="([^"]+)"')
|
||||||
|
local opf = opf_path and arc:extractToMemory(opf_path) or ""
|
||||||
|
local manifest, hrefs = {}, {}
|
||||||
|
for tag in opf:gmatch("<item%s[^>]*>") do
|
||||||
|
local id, href = tag:match('%sid="([^"]*)"'), tag:match('%shref="([^"]*)"')
|
||||||
|
if id and href then manifest[id] = href end
|
||||||
|
end
|
||||||
|
for idref in (opf:match("<spine[^>]*>(.-)</spine>") or ""):gmatch('idref="([^"]*)"') do
|
||||||
|
hrefs[#hrefs + 1] = manifest[idref]
|
||||||
|
end
|
||||||
|
local base = opf_path and opf_path:match("^(.*)/") or ""
|
||||||
|
return fn({
|
||||||
|
count = #hrefs,
|
||||||
|
html = function(spine)
|
||||||
|
local href = hrefs[spine + 1]
|
||||||
|
return href and arc:extractToMemory(joinPath(base, href))
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
arc:close()
|
||||||
|
return ok and result or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
---@class KavitaElement
|
||||||
|
---@field name string
|
||||||
|
---@field tag string 开标签原文(不含尖括号)
|
||||||
|
---@field path string 相对 body 的路径,同名兄弟下标补全:`section[1]/p[3]`
|
||||||
|
---@field text string[] 元素内(含后代)的文本片段
|
||||||
|
|
||||||
|
--- body 内元素按文档顺序展开,路径口径与 Kavita 的 `//body/...` 一致。
|
||||||
|
---@param html string
|
||||||
|
---@return KavitaElement[]
|
||||||
|
local function elements(html)
|
||||||
|
local body = html:match("<body[^>]*>(.-)</body>") or html
|
||||||
|
local out, stack = {}, { { path = "", counts = {} } }
|
||||||
|
local pos = 1
|
||||||
|
while true do
|
||||||
|
local lt = body:find("<", pos, true)
|
||||||
|
local text = body:sub(pos, (lt or 0) - 1)
|
||||||
|
if text ~= "" then
|
||||||
|
for i = 2, #stack do stack[i].text[#stack[i].text + 1] = text end
|
||||||
|
end
|
||||||
|
if not lt then break end
|
||||||
|
local gt = body:find(">", lt, true)
|
||||||
|
if not gt then break end
|
||||||
|
local tag = body:sub(lt + 1, gt - 1)
|
||||||
|
pos = gt + 1
|
||||||
|
local close = tag:match("^/%s*([%w:_%-]+)")
|
||||||
|
local name = not close and tag:match("^([%w:_%-]+)")
|
||||||
|
if close then
|
||||||
|
for i = #stack, 2, -1 do
|
||||||
|
if stack[i].name == close then
|
||||||
|
for j = #stack, i, -1 do stack[j] = nil end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif name then
|
||||||
|
local parent = stack[#stack]
|
||||||
|
local idx = (parent.counts[name] or 0) + 1
|
||||||
|
parent.counts[name] = idx
|
||||||
|
local el = {
|
||||||
|
name = name, tag = tag, text = {}, counts = {},
|
||||||
|
path = (parent.path == "" and "" or parent.path .. "/") .. name .. "[" .. idx .. "]",
|
||||||
|
}
|
||||||
|
out[#out + 1] = el
|
||||||
|
if not VOID[name] and tag:sub(-1) ~= "/" then stack[#stack + 1] = el end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 远端 bookScrollId → `//body/...`。`id("X")` 需读本地 epub 第 spine 个文档定位;
|
||||||
|
--- 读不到 / 找不到返回 nil,调用方退回只按 spine 定位。
|
||||||
|
---@param epub_path string|nil
|
||||||
|
---@param spine integer
|
||||||
|
---@param scroll_id string|nil
|
||||||
|
---@return string|nil
|
||||||
|
function Position.resolveScrollId(epub_path, spine, scroll_id)
|
||||||
|
if type(scroll_id) ~= "string" then return nil end
|
||||||
|
if scroll_id:match("^//body/") then return scroll_id end
|
||||||
|
local id = scroll_id:match('^id%("(.-)"%)$') or scroll_id:match("^id%('(.-)'%)$")
|
||||||
|
if not id or id == "" then return nil end
|
||||||
|
return withEpub(epub_path, function(doc)
|
||||||
|
for _idx, el in ipairs(elements(doc.html(spine) or "")) do
|
||||||
|
if (el.tag:match("%sid%s*=%s*\"([^\"]*)\"") or el.tag:match("%sid%s*=%s*'([^']*)'")) == id then
|
||||||
|
return "//body/" .. el.path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 段落匹配用:解实体,去脚注标记(上标数字与 [N])和全部空白。
|
||||||
|
---@param s string|nil
|
||||||
|
---@return string
|
||||||
|
local function normalizeText(s)
|
||||||
|
s = require("utils.text").xmlDecode(s or "")
|
||||||
|
s = s:gsub("%[%d+%]", ""):gsub("\194[\185\178\179]", ""):gsub("\226\129[\176-\185]", "")
|
||||||
|
return (s:gsub("%s+", ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 选中文本落在哪几段:首行定起始段(探针由长到短:整行 → 前 32 / 16 字节,容忍段内差异),
|
||||||
|
--- 末行尾部定结束段。KOReader 跨段选区按段换行,所以首末行各自落在一段里。
|
||||||
|
---@param paras { path: string, text: string }[]
|
||||||
|
---@param head string 首行(已规范化)
|
||||||
|
---@param tail string 末行(已规范化)
|
||||||
|
---@return integer|nil first, integer|nil last
|
||||||
|
local function findRange(paras, head, tail)
|
||||||
|
local probes = { head }
|
||||||
|
if #head > 32 then probes[#probes + 1] = head:sub(1, 32) end
|
||||||
|
if #head > 16 then probes[#probes + 1] = head:sub(1, 16) end
|
||||||
|
tail = tail:sub(-math.min(24, #tail))
|
||||||
|
for _pidx, probe in ipairs(probes) do
|
||||||
|
for i, para in ipairs(paras) do
|
||||||
|
if para.text:find(probe, 1, true) then
|
||||||
|
for j = i, #paras do
|
||||||
|
if paras[j].text:find(tail, 1, true) then return i, j end
|
||||||
|
end
|
||||||
|
return i, i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- KOReader 划线 → Kavita 注解锚点 { pageNumber, xPath, endingXPath }。
|
||||||
|
--- 先在 pos0 所在 spine 找,找不到由近及远搜其它 spine;都找不到返回 nil(调用方只带 spine)。
|
||||||
|
---@param text string|nil 划线原文
|
||||||
|
---@param pos0 string|nil 起点 xpointer
|
||||||
|
---@param epub_path string|nil
|
||||||
|
---@return { pageNumber: integer, xPath: string, endingXPath: string }|nil
|
||||||
|
function Position.anchor(text, pos0, epub_path)
|
||||||
|
local lines = {}
|
||||||
|
for line in (text or ""):gmatch("[^\n]+") do
|
||||||
|
local clean = normalizeText(line)
|
||||||
|
if clean ~= "" then lines[#lines + 1] = clean end
|
||||||
|
end
|
||||||
|
if #table.concat(lines) < 2 then return nil end
|
||||||
|
local primary = Position.spine(pos0) or 0
|
||||||
|
return withEpub(epub_path, function(doc)
|
||||||
|
local function try(spine)
|
||||||
|
local html = doc.html(spine)
|
||||||
|
if not html then return nil end
|
||||||
|
local paras = {}
|
||||||
|
for _idx, el in ipairs(elements(html)) do
|
||||||
|
if el.name == "p" then
|
||||||
|
paras[#paras + 1] = { path = el.path, text = normalizeText(table.concat(el.text)) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local first, last = findRange(paras, lines[1], lines[#lines])
|
||||||
|
return first and {
|
||||||
|
pageNumber = spine,
|
||||||
|
xPath = "//body/" .. paras[first].path,
|
||||||
|
endingXPath = "//body/" .. paras[last].path,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
local hit = try(primary)
|
||||||
|
for distance = 1, doc.count do
|
||||||
|
hit = hit or try(primary - distance) or try(primary + distance)
|
||||||
|
end
|
||||||
|
return hit
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Position
|
||||||
@@ -0,0 +1,750 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita 源设置:服务器地址、API Key、书库选择、测试连接。
|
||||||
|
配置经月读 utils.settings.getSource / saveSource("kavita") 落盘。
|
||||||
|
|
||||||
|
@module moonsource_kavita.setting
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local Text = require("utils.text")
|
||||||
|
local Cache = require("moonsource_kavita.cache")
|
||||||
|
local KamareUpdate = require("moonsource_kavita.kamare_update")
|
||||||
|
local _ = require("l10n").get("moonsource_kavita")
|
||||||
|
local T = require("ffi/util").template
|
||||||
|
|
||||||
|
local ID = "kavita"
|
||||||
|
|
||||||
|
local Setting = {}
|
||||||
|
|
||||||
|
---@return table
|
||||||
|
local function config()
|
||||||
|
return require("utils.settings").getSource(ID)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param text string
|
||||||
|
---@param timeout number|nil 秒,缺省 3
|
||||||
|
local function toast(text, timeout)
|
||||||
|
require("ui.themes.widgets.toast"):new{ text = text, timeout = timeout or 3 }:show()
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param plugin table|nil
|
||||||
|
local function repaint(plugin)
|
||||||
|
local desktop = plugin and plugin.desktop
|
||||||
|
if desktop and desktop.settings_overlay then desktop.settings_overlay:updateView() end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param plugin table|nil
|
||||||
|
local function shelfChanged(plugin)
|
||||||
|
if plugin and plugin.desktop then plugin.desktop:onEvent("shelf_changed") end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 服务器身份:地址 + API Key。换了就是另一套书架(seriesId 会撞)。
|
||||||
|
local function libraryFingerprint(cfg)
|
||||||
|
return table.concat({
|
||||||
|
Text.rtrimSlashes(Text.stripWhitespace(cfg.base_url)),
|
||||||
|
Text.stripWhitespace(cfg.api_key),
|
||||||
|
}, "\0")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 落盘并作废源实例,让新地址 / Key / 书库立即生效。
|
||||||
|
--- 不走 SourceChanged:那会把设置页复位到根目录;这里只重画当前叠层。
|
||||||
|
--- 保存后把配置镜像给 kamare(02 A5 第二处);kamare 侧失败只提示,不阻断 moon 自己的保存。
|
||||||
|
--- 换服务器 / Key:整源撕本地书架(replaceLibrary 会 reload),不再只靠下次 reconcile。
|
||||||
|
---@param cfg table
|
||||||
|
---@param plugin table|nil
|
||||||
|
---@param refresh_shelf boolean|nil 连接配置 / 书库变了才让书架作废旧数据
|
||||||
|
---@param previous_fingerprint string|nil 保存前的库身份;与现在不同则清书架
|
||||||
|
local function save(cfg, plugin, refresh_shelf, previous_fingerprint)
|
||||||
|
local function commit()
|
||||||
|
require("utils.settings").saveSource(ID, cfg)
|
||||||
|
end
|
||||||
|
local replaced = previous_fingerprint and previous_fingerprint ~= libraryFingerprint(cfg)
|
||||||
|
if replaced then
|
||||||
|
if not require("source.logout").replaceLibrary(ID, commit) then
|
||||||
|
toast(_("准备本地同步失败"))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
commit()
|
||||||
|
require("source.registry").invalidate()
|
||||||
|
end
|
||||||
|
local configured = (cfg.base_url or "") ~= "" and (cfg.api_key or "") ~= ""
|
||||||
|
if configured and Cache.probe().ok then
|
||||||
|
local server_key, code = Cache.registerServer(cfg.base_url, cfg.api_key)
|
||||||
|
if not server_key or code then toast(_("无法同步配置到 kamare")) end
|
||||||
|
end
|
||||||
|
repaint(plugin)
|
||||||
|
if refresh_shelf and not replaced then shelfChanged(plugin) end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 未配置 / 断网当场提示;否则带忙碌提示调 fn(client, done),fn 结束时必须调 done()。
|
||||||
|
---@param fn fun(client: KavitaClient, done: fun())
|
||||||
|
local function withServer(fn)
|
||||||
|
local client = require("moonsource_kavita.client").new(config())
|
||||||
|
if not client:configured() then
|
||||||
|
toast(_("请先填写服务器地址和 API Key"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if not require("ui/network/manager"):isConnected() then
|
||||||
|
toast(_("网络不可用,请先连接 Wi-Fi"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local busy = require("ui.themes.widgets.toast"):new{ text = _("正在连接 Kavita…"), dismissable = false }
|
||||||
|
busy:show()
|
||||||
|
fn(client, function() busy:close() end)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param key string
|
||||||
|
---@param title string
|
||||||
|
---@param hint string
|
||||||
|
---@param password boolean
|
||||||
|
---@param normalize fun(value: string|nil): string
|
||||||
|
---@param icon string
|
||||||
|
---@return fun(iw: number): table
|
||||||
|
local function field(plugin, key, title, hint, password, normalize, icon)
|
||||||
|
return function(iw)
|
||||||
|
local value = config()[key] or ""
|
||||||
|
return require("ui.themes.widgets.row").widget({
|
||||||
|
width = iw, chevron = true,
|
||||||
|
kind = "nav", icon = icon, title = title,
|
||||||
|
status = value ~= "" and (password and "******" or value) or _("未设置"),
|
||||||
|
status_on = value ~= "",
|
||||||
|
callback = function()
|
||||||
|
local cfg = config()
|
||||||
|
require("ui.themes.widgets.input"):new{
|
||||||
|
title = title,
|
||||||
|
fields = { { text = cfg[key] or "", hint = hint, text_type = password and "password" or nil } },
|
||||||
|
ok_text = _("保存"),
|
||||||
|
callback = function(input)
|
||||||
|
local before = libraryFingerprint(cfg)
|
||||||
|
local next_cfg = require("util").tableDeepCopy(cfg)
|
||||||
|
next_cfg[key] = normalize(input)
|
||||||
|
save(next_cfg, plugin, true, before)
|
||||||
|
end,
|
||||||
|
}:show()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 多选书库:只同步选中的库,书架分类即库名。
|
||||||
|
local function pickLibraries(plugin)
|
||||||
|
withServer(function(client, done)
|
||||||
|
client:json("GET", "/api/Library/libraries", nil, nil, function(libraries, err)
|
||||||
|
done()
|
||||||
|
if not libraries then
|
||||||
|
toast(err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local cfg = config()
|
||||||
|
local chosen = cfg.libraries or {}
|
||||||
|
local items = {}
|
||||||
|
for _idx, lib in ipairs(libraries) do
|
||||||
|
local id = tostring(lib.id)
|
||||||
|
items[#items + 1] = { text = lib.name or id, value = id, checked = chosen[id] == true }
|
||||||
|
end
|
||||||
|
require("ui.themes.widgets.list"):new{
|
||||||
|
title = _("选择书库"),
|
||||||
|
multi = true,
|
||||||
|
items = items,
|
||||||
|
close_callback = function()
|
||||||
|
local picked = {}
|
||||||
|
for _idx, item in ipairs(items) do
|
||||||
|
if item.checked then picked[item.value] = true end
|
||||||
|
end
|
||||||
|
cfg.libraries = picked
|
||||||
|
save(cfg, plugin, true)
|
||||||
|
end,
|
||||||
|
}:show()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 请求超时(秒):全量书架(all-v2)在慢设备 / 慢服务器上一次要几十秒,
|
||||||
|
--- 硬上限会让整轮同步中断、书架永远加载不出来。留个设置行按设备调大。
|
||||||
|
---@return fun(iw: number): table
|
||||||
|
local function timeoutRow(plugin)
|
||||||
|
return function(iw)
|
||||||
|
local client = require("moonsource_kavita.client")
|
||||||
|
local value = tonumber(config().timeout) or client.DEFAULT_TIMEOUT
|
||||||
|
return require("ui.themes.widgets.row").widget({
|
||||||
|
width = iw, chevron = true,
|
||||||
|
kind = "nav", icon = "hourglass_top", title = _("请求超时"),
|
||||||
|
status = T(_("%1 秒"), value),
|
||||||
|
status_on = value ~= client.DEFAULT_TIMEOUT,
|
||||||
|
callback = function()
|
||||||
|
local cfg = config()
|
||||||
|
require("ui.themes.widgets.spin"):new{
|
||||||
|
title = _("请求超时"),
|
||||||
|
fields = { {
|
||||||
|
value = tonumber(cfg.timeout) or client.DEFAULT_TIMEOUT,
|
||||||
|
min = 10, max = client.MAX_TIMEOUT, step = 10,
|
||||||
|
label = _("秒"),
|
||||||
|
} },
|
||||||
|
callback = function(seconds)
|
||||||
|
cfg.timeout = seconds ~= client.DEFAULT_TIMEOUT and math.floor(seconds) or nil
|
||||||
|
save(cfg, plugin)
|
||||||
|
end,
|
||||||
|
}:show()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 进度心跳间隔(秒):Kavita 的阅读会话时长 = 相邻两次进度写入的间隔,只在关书推一次会是
|
||||||
|
--- 0 秒会话;阅读期按这个间隔补推当前位置。0 = 关闭(关书 / 切章 / 休眠的推送不受影响)。
|
||||||
|
---@return fun(iw: number): table
|
||||||
|
local function heartbeatRow(plugin)
|
||||||
|
return function(iw)
|
||||||
|
local Source = require("moonsource_kavita.source")
|
||||||
|
local default = Source.DEFAULT_HEARTBEAT_INTERVAL
|
||||||
|
local value = tonumber(config().heartbeat_interval) or default
|
||||||
|
return require("ui.themes.widgets.row").widget({
|
||||||
|
width = iw, chevron = true,
|
||||||
|
kind = "nav", icon = "favorite", title = _("进度心跳间隔"),
|
||||||
|
-- 行副标题是单行截断的(TextWidget 带 max_width 不换行),这行还有状态与箭头,
|
||||||
|
-- 右边留给文字的位置很窄:副标题必须短,长解释放不进来。
|
||||||
|
subtitle = _("阅读时补推进度,0 关闭"),
|
||||||
|
status = value > 0 and T(_("%1 秒"), value) or _("已关闭"),
|
||||||
|
status_on = value > 0,
|
||||||
|
callback = function()
|
||||||
|
local cfg = config()
|
||||||
|
require("ui.themes.widgets.spin"):new{
|
||||||
|
title = _("进度心跳间隔"),
|
||||||
|
fields = { {
|
||||||
|
value = tonumber(cfg.heartbeat_interval) or default,
|
||||||
|
min = 0, max = 600, step = 10,
|
||||||
|
label = _("秒"),
|
||||||
|
} },
|
||||||
|
callback = function(seconds)
|
||||||
|
cfg.heartbeat_interval = seconds ~= default and math.floor(seconds) or nil
|
||||||
|
save(cfg, plugin)
|
||||||
|
end,
|
||||||
|
}:show()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 探测结果是否带清理接口(03 A):只有能用且具备 chapters + delete 才能按章删除。
|
||||||
|
--- 缺任一项就是「旧接口」,设置行与详情页都据此降级。
|
||||||
|
---@param probe table
|
||||||
|
---@return boolean
|
||||||
|
local function cleanupReady(probe)
|
||||||
|
if not probe.ok then return false end
|
||||||
|
local caps = probe.capabilities or {}
|
||||||
|
return caps.chapters == true and caps.delete == true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 五态文案(02 A8):镜像失败优先于「增强版」,其余按探测态。
|
||||||
|
--- 增强版再分「能力齐 / 旧接口」两态(03 A 七态矩阵);旧接口不高亮。
|
||||||
|
--- 行副标题只留结论,API 版本 / 能力清单不再展示(用户不需要,也会误导)。
|
||||||
|
---@param probe table
|
||||||
|
---@return string, boolean
|
||||||
|
local function cacheStatus(probe)
|
||||||
|
if probe.state == "enhanced" then
|
||||||
|
if Cache.mirrorFailed() then return _("配置同步失败"), false end
|
||||||
|
local ready = cleanupReady(probe)
|
||||||
|
if probe.version then
|
||||||
|
return ready and T(_("增强版 v%1"), probe.version)
|
||||||
|
or T(_("增强版 v%1(旧接口)"), probe.version), ready
|
||||||
|
end
|
||||||
|
return ready and _("增强版") or _("增强版(旧接口)"), ready
|
||||||
|
elseif probe.state == "incompatible" then
|
||||||
|
return _("版本不兼容"), false
|
||||||
|
elseif probe.state == "official" then
|
||||||
|
return _("官方版(无缓存接口)"), false
|
||||||
|
end
|
||||||
|
return _("未安装 / 未启用"), false
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 测试连接结果:结论一行 + 明细一行或多行(Toast 用 TextBoxWidget,换行生效)。
|
||||||
|
---@param headline string
|
||||||
|
---@param detail string|nil
|
||||||
|
---@return string
|
||||||
|
local function connectResult(headline, detail)
|
||||||
|
return detail and (headline .. "\n" .. detail) or headline
|
||||||
|
end
|
||||||
|
|
||||||
|
local function testConnection()
|
||||||
|
withServer(function(client, done)
|
||||||
|
client:request("GET", "/api/Plugin/version", { apiKey = client.api_key }, nil, function(version, err)
|
||||||
|
done()
|
||||||
|
local major, minor = (version or ""):match("^(%d+)%.(%d+)")
|
||||||
|
if not major then
|
||||||
|
toast(connectResult(err and _("连接失败") or _("连接正常"),
|
||||||
|
err or _("无法识别 Kavita 版本")))
|
||||||
|
elseif tonumber(major) == 0 and tonumber(minor) < 9 then
|
||||||
|
toast(connectResult(_("连接正常"),
|
||||||
|
T(_("Kavita %1 过旧,需要 0.9 及以上"), Text.trim(version))))
|
||||||
|
else
|
||||||
|
toast(table.concat({
|
||||||
|
_("连接正常"),
|
||||||
|
T(_("Kavita %1"), Text.trim(version)),
|
||||||
|
}, "\n"))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param plugin table|nil
|
||||||
|
---@return fun(iw: number): table
|
||||||
|
local function libraryRow(plugin)
|
||||||
|
return function(iw)
|
||||||
|
local count = 0
|
||||||
|
for _id in pairs(config().libraries or {}) do count = count + 1 end
|
||||||
|
return require("ui.themes.widgets.row").widget({
|
||||||
|
width = iw, chevron = true,
|
||||||
|
kind = "nav", icon = "library_books", title = _("书库"),
|
||||||
|
status = count > 0 and T(_("%1 个"), count) or _("未选择"),
|
||||||
|
status_on = count > 0,
|
||||||
|
callback = function() pickLibraries(plugin) end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return fun(iw: number): table
|
||||||
|
local function testRow()
|
||||||
|
return function(iw)
|
||||||
|
return require("ui.themes.widgets.row").widget({
|
||||||
|
width = iw,
|
||||||
|
kind = "action", icon = "network_check", title = _("测试连接"),
|
||||||
|
subtitle = _("检查 Kavita 服务器连接与版本"),
|
||||||
|
callback = testConnection,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读占用:当前服务器。
|
||||||
|
---@return table|nil
|
||||||
|
local function serverUsage()
|
||||||
|
if not Cache.available("summary") then return nil end
|
||||||
|
local usage = Cache.summary()
|
||||||
|
return type(usage) == "table" and usage or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 只读占用:所有服务器(含未关联)。
|
||||||
|
---@return table|nil
|
||||||
|
local function allUsage()
|
||||||
|
if not Cache.available("summary") then return nil end
|
||||||
|
local usage = Cache.summaryAll()
|
||||||
|
return type(usage) == "table" and usage or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 详情页打开时的一次统计(03 E):配置了服务器时「本服务器」与「合计」各一次;
|
||||||
|
--- 没配置时两者都是合计,只走盘一次。`need_all` 由「清理全部」是否出现决定。
|
||||||
|
---@param need_all boolean
|
||||||
|
---@return table|nil usage, table|nil all_usage
|
||||||
|
local function loadUsage(need_all)
|
||||||
|
local configured = (config().base_url or "") ~= ""
|
||||||
|
if not configured then
|
||||||
|
local all = allUsage()
|
||||||
|
return all, all
|
||||||
|
end
|
||||||
|
return serverUsage(), need_all and allUsage() or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 设置行的构建函数(sections 每次重绘都按新宽度重建)。
|
||||||
|
local function mk(opts)
|
||||||
|
return function(iw)
|
||||||
|
opts.width = iw
|
||||||
|
return require("ui.themes.widgets.row").widget(opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function installText(plugin)
|
||||||
|
local dir = require("utils.paths").userPath(Cache.pluginsDir(plugin and plugin.path))
|
||||||
|
return table.concat({
|
||||||
|
_("获取增强版"),
|
||||||
|
_(" 发布页:github.com/backtracker/kamare.koplugin/releases/latest"),
|
||||||
|
T(_(" 下载 kamare.koplugin.zip,解压后把 kamare.koplugin/ 放进:%1"), dir),
|
||||||
|
_(" 也可点上方「kamare 增强版」检查并安装最新版。"),
|
||||||
|
_(" 重启 KOReader。包里要有 kamarecache.lua(没有就是官方版);"),
|
||||||
|
_(" 增强版与官方版目录同名,不能共存;替换前先删掉旧的 kamare.koplugin/。"),
|
||||||
|
T(_(" 如该目录不可写,可改用:%1"),
|
||||||
|
require("utils.paths").userPath(require("datastorage"):getDataDir() .. "/plugins")),
|
||||||
|
"",
|
||||||
|
_("增强版功能随版本不同,以实际安装的版本为准。"),
|
||||||
|
}, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 叠层的占用是打开时算的一份;清理之后只 updateView 会留着删前的数字,
|
||||||
|
--- 所以写入路径显式标记「占用过期」,下次重建先回「正在统计…」再走盘。
|
||||||
|
local usage_stale = false
|
||||||
|
|
||||||
|
---@param plugin table|nil
|
||||||
|
---@param reload_usage boolean|nil 写入路径传 true(删除后占用要重算)
|
||||||
|
local function refreshOverlay(plugin, reload_usage)
|
||||||
|
if reload_usage then usage_stale = true end
|
||||||
|
repaint(plugin)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 删除后复查:请求里属于「删除前已缓存」的章如果还在,就是没删掉。
|
||||||
|
local function leftoverCount(entries, ids)
|
||||||
|
local wanted = {}
|
||||||
|
for __, id in ipairs(ids or {}) do wanted[tostring(id)] = true end
|
||||||
|
local left = 0
|
||||||
|
for __, entry in ipairs(type(entries) == "table" and entries or {}) do
|
||||||
|
if wanted[tostring(entry.chapterId)] then left = left + 1 end
|
||||||
|
end
|
||||||
|
return left
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param title string
|
||||||
|
---@param fn fun(): boolean|nil, string|nil, string|nil, any
|
||||||
|
---@return boolean|nil, string|nil, string|nil, any
|
||||||
|
local function runBusy(title, fn)
|
||||||
|
return require("moonsource_kavita.busy").run(title, fn)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function runCleanup(plugin, filter, title)
|
||||||
|
local entries, code = Cache.chapters()
|
||||||
|
if not entries then
|
||||||
|
toast(Cache.message(code) or _("缓存操作失败"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local plan = Cache.plan(entries, filter)
|
||||||
|
if plan.chapters == 0 then
|
||||||
|
toast(filter == "read" and _("没有已读完的缓存") or _("没有可清理的缓存"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local first = filter == "read"
|
||||||
|
and T(_("将删除 %1 章已读完的缓存(约 %2)。"), plan.chapters, Cache.sizeText(plan.bytes))
|
||||||
|
or T(_("将删除本服务器的 %1 章(约 %2)。"), plan.chapters, Cache.sizeText(plan.bytes))
|
||||||
|
local lines = { first }
|
||||||
|
if plan.queued > 0 then
|
||||||
|
lines[#lines + 1] = T(_("会中止正在下载的 %1 章,已下载的部分会被删除。"), plan.queued)
|
||||||
|
end
|
||||||
|
lines[#lines + 1] = _("阅读进度与 kamare journal 保留。")
|
||||||
|
|
||||||
|
require("ui.themes.widgets.confirm"):new{
|
||||||
|
title = title,
|
||||||
|
text = table.concat(lines, "\n"),
|
||||||
|
ok_text = _("清理"),
|
||||||
|
cancel_text = _("取消"),
|
||||||
|
ok_callback = function()
|
||||||
|
local ok, err, message = runBusy(title, function() return Cache.delete(plan.ids) end)
|
||||||
|
if not ok then
|
||||||
|
toast(Cache.message(err, message))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local left = leftoverCount(Cache.chapters(), plan.ids)
|
||||||
|
if left > 0 then
|
||||||
|
toast(T(_("已清理 %1 章,%2 章未能删除"), plan.chapters - left, left), 3)
|
||||||
|
else
|
||||||
|
toast(T(_("已清理 %1 章,释放约 %2"), plan.chapters, Cache.sizeText(plan.bytes)), 3)
|
||||||
|
end
|
||||||
|
refreshOverlay(plugin, true)
|
||||||
|
shelfChanged(plugin)
|
||||||
|
end,
|
||||||
|
}:show()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function runCleanupAll(plugin)
|
||||||
|
local usage = allUsage()
|
||||||
|
local chapters = usage and tonumber(usage.chapters) or 0
|
||||||
|
local bytes = usage and tonumber(usage.used) or 0
|
||||||
|
require("ui.themes.widgets.confirm"):new{
|
||||||
|
title = _("清理全部缓存"),
|
||||||
|
text = table.concat({
|
||||||
|
T(_("将删除所有服务器(含未关联服务器)共 %1 章(约 %2)。"),
|
||||||
|
chapters, Cache.sizeText(bytes)),
|
||||||
|
_("此操作不可撤销,之后阅读需要重新下载。"),
|
||||||
|
_("阅读进度与 kamare journal 保留。"),
|
||||||
|
}, "\n"),
|
||||||
|
ok_text = _("清理"),
|
||||||
|
cancel_text = _("取消"),
|
||||||
|
ok_callback = function()
|
||||||
|
local ok, err, message, detail = runBusy(_("清理全部缓存"),
|
||||||
|
function() return Cache.deleteAll() end)
|
||||||
|
if not ok then
|
||||||
|
toast(Cache.message(err, message))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local freed = detail and tonumber(detail.bytes) or bytes
|
||||||
|
toast(T(_("已清理全部缓存,释放约 %1"), Cache.sizeText(freed)), 3)
|
||||||
|
refreshOverlay(plugin, true)
|
||||||
|
shelfChanged(plugin)
|
||||||
|
end,
|
||||||
|
}:show()
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 详情页状态:占用走盘,先画「正在统计…」,下一拍算完再整页刷新(03 E)。
|
||||||
|
---@class KavitaCachePageState
|
||||||
|
---@field pending boolean 占用还在统计
|
||||||
|
---@field usage table|nil 当前服务器(未配置时是所有服务器合计)
|
||||||
|
---@field all table|nil 所有服务器合计(「清理全部」用;拿不到就是 nil)
|
||||||
|
|
||||||
|
--- 详情页:状态 → 清理(+ 非增强态的安装说明)。
|
||||||
|
---@param plugin table|nil
|
||||||
|
---@param state KavitaCachePageState|nil
|
||||||
|
---@return BookThemeSection[]
|
||||||
|
local function cacheSections(plugin, state)
|
||||||
|
state = state or { pending = false }
|
||||||
|
local probe = Cache.probe()
|
||||||
|
local caps = probe.capabilities or {}
|
||||||
|
local configured = (config().base_url or "") ~= ""
|
||||||
|
local can_plan = cleanupReady(probe)
|
||||||
|
local can_all = probe.ok and caps.delete_all == true
|
||||||
|
local usage = state.usage
|
||||||
|
local all_usage = state.all
|
||||||
|
local out = {}
|
||||||
|
|
||||||
|
local version_status, version_hint
|
||||||
|
if probe.ok then
|
||||||
|
version_status, version_hint = probe.version, _("点按检查 kamare 增强版更新")
|
||||||
|
elseif probe.state == "official" then
|
||||||
|
version_status, version_hint = _("官方版"), _("点按安装 kamare 增强版")
|
||||||
|
elseif probe.state == "incompatible" then
|
||||||
|
version_status, version_hint = _("版本不兼容"), _("点按安装兼容的 kamare 增强版")
|
||||||
|
else
|
||||||
|
version_status, version_hint = _("未安装"), _("点按检查并安装 kamare 增强版")
|
||||||
|
end
|
||||||
|
local status = {
|
||||||
|
mk({ icon = "info", title = _("kamare 增强版"),
|
||||||
|
subtitle = version_hint,
|
||||||
|
status = version_status, status_on = probe.ok == true,
|
||||||
|
chevron = true,
|
||||||
|
callback = function() KamareUpdate:manualCheck(plugin) end }),
|
||||||
|
}
|
||||||
|
if probe.ok then
|
||||||
|
local features = Cache.featureText(probe)
|
||||||
|
if features then
|
||||||
|
status[#status + 1] = mk({ icon = "book", title = _("增强版功能"),
|
||||||
|
subtitle = features, chevron = false })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
status[#status + 1] = mk({ icon = "info", title = _("加载路径"),
|
||||||
|
subtitle = probe.path and require("utils.paths").userPath(probe.path) or _("未加载"), chevron = false })
|
||||||
|
if state.pending and Cache.available("summary") then
|
||||||
|
status[#status + 1] = mk({
|
||||||
|
icon = "storage", title = _("缓存占用"),
|
||||||
|
subtitle = _("正在统计…"), chevron = false,
|
||||||
|
})
|
||||||
|
elseif usage then
|
||||||
|
local scope = configured and "" or _("(含未关联服务器)")
|
||||||
|
status[#status + 1] = mk({
|
||||||
|
icon = "storage", title = _("缓存占用"),
|
||||||
|
subtitle = T(_("已用 %1%2,可用 %3"),
|
||||||
|
Cache.sizeText(usage.used), scope, Cache.sizeText(usage.available)),
|
||||||
|
status = T(_("%1 章"), tostring(usage.chapters or 0)),
|
||||||
|
status_on = true, chevron = false,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
if probe.ok and Cache.mirrorFailed() then
|
||||||
|
status[#status + 1] = mk({
|
||||||
|
icon = "warning", title = _("配置同步失败"),
|
||||||
|
subtitle = _("服务器配置没能写入 kamare,缓存操作可能找不到服务器"),
|
||||||
|
status = _("重试同步"), chevron = false,
|
||||||
|
callback = function()
|
||||||
|
local cfg = config()
|
||||||
|
local server_key, code = Cache.registerServer(cfg.base_url, cfg.api_key)
|
||||||
|
toast(server_key and _("已重新同步配置") or Cache.message(code) or _("同步失败"))
|
||||||
|
refreshOverlay(plugin)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
out[#out + 1] = { title = _("状态"), rows = status }
|
||||||
|
|
||||||
|
--- 「清理全部」一行:跨服务器(含未关联),数字来自 summaryAll 而不是本服务器。
|
||||||
|
--- 统计到 0 章时置灰并写「没有可清理的缓存」(03 待确认 3);还没统计完 /
|
||||||
|
--- 拿不到统计时不猜,保持可点(删除时以 kamare 的事实为准)。
|
||||||
|
local function cleanupAllRow()
|
||||||
|
local count = all_usage and tonumber(all_usage.chapters) or nil
|
||||||
|
local empty = count ~= nil and count <= 0
|
||||||
|
local subtitle
|
||||||
|
if empty then
|
||||||
|
subtitle = _("没有可清理的缓存")
|
||||||
|
elseif all_usage then
|
||||||
|
subtitle = T(_("含未关联服务器 · %1 章 · 约 %2"), tostring(all_usage.chapters or 0),
|
||||||
|
Cache.sizeText(all_usage.used))
|
||||||
|
else
|
||||||
|
subtitle = _("含未关联服务器")
|
||||||
|
end
|
||||||
|
return mk({
|
||||||
|
icon = "delete", title = _("清理全部"),
|
||||||
|
subtitle = subtitle,
|
||||||
|
enabled = not empty,
|
||||||
|
chevron = not empty,
|
||||||
|
callback = function() runCleanupAll(plugin) end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
if can_plan and configured then
|
||||||
|
local entries = Cache.chapters() or {}
|
||||||
|
local read_plan = Cache.plan(entries, "read")
|
||||||
|
local all_plan = Cache.plan(entries, "all")
|
||||||
|
local cleanup = {
|
||||||
|
mk({
|
||||||
|
icon = "delete", title = _("清理已读"),
|
||||||
|
subtitle = read_plan.chapters > 0
|
||||||
|
and T(_("%1 章 · 约 %2"), read_plan.chapters, Cache.sizeText(read_plan.bytes))
|
||||||
|
or _("没有可清理的缓存"),
|
||||||
|
enabled = read_plan.chapters > 0,
|
||||||
|
chevron = read_plan.chapters > 0,
|
||||||
|
callback = function() runCleanup(plugin, "read", _("清理已读")) end,
|
||||||
|
}),
|
||||||
|
mk({
|
||||||
|
icon = "delete", title = _("清理本服务器"),
|
||||||
|
subtitle = all_plan.chapters > 0
|
||||||
|
and T(_("%1 章 · 约 %2"), all_plan.chapters, Cache.sizeText(all_plan.bytes))
|
||||||
|
or _("没有可清理的缓存"),
|
||||||
|
enabled = all_plan.chapters > 0,
|
||||||
|
chevron = all_plan.chapters > 0,
|
||||||
|
callback = function() runCleanup(plugin, "all", _("清理本服务器")) end,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
if can_all then
|
||||||
|
cleanup[#cleanup + 1] = cleanupAllRow()
|
||||||
|
end
|
||||||
|
out[#out + 1] = { title = _("清理"), rows = cleanup }
|
||||||
|
elseif can_all and not configured then
|
||||||
|
out[#out + 1] = { title = _("清理"), rows = {
|
||||||
|
mk({ icon = "info", title = _("未配置服务器"),
|
||||||
|
subtitle = _("填写服务器地址与 API Key 后,可按服务器清理已读或全部缓存"),
|
||||||
|
chevron = false }),
|
||||||
|
cleanupAllRow(),
|
||||||
|
} }
|
||||||
|
elseif probe.ok and not can_plan then
|
||||||
|
out[#out + 1] = { title = _("清理"), rows = {
|
||||||
|
mk({ icon = "info", title = _("当前 kamare 没有清理接口"),
|
||||||
|
subtitle = _("升级到带 chapters / delete_all 的版本后才能清理"),
|
||||||
|
chevron = false }),
|
||||||
|
} }
|
||||||
|
end
|
||||||
|
|
||||||
|
if not probe.ok then
|
||||||
|
local rows = {}
|
||||||
|
if probe.state == "incompatible" and probe.api_version then
|
||||||
|
rows[#rows + 1] = mk({
|
||||||
|
icon = "warning", title = _("版本不兼容"),
|
||||||
|
subtitle = T(_("kamare API v%1 与当前支持的 v1 不兼容;装回支持 v1 的增强版后可管理缓存"),
|
||||||
|
tostring(probe.api_version)),
|
||||||
|
chevron = false,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
local text = installText(plugin)
|
||||||
|
rows[#rows + 1] = function(iw) return require("ui.themes.widgets.row").note(iw, text) end
|
||||||
|
out[#out + 1] = {
|
||||||
|
title = probe.state == "incompatible" and _("版本与获取") or _("获取增强版"),
|
||||||
|
rows = rows,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param plugin table|nil
|
||||||
|
local function showCachePage(plugin)
|
||||||
|
local desktop = plugin and plugin.desktop
|
||||||
|
if not desktop then
|
||||||
|
toast(_("请先打开月读桌面"))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local state = { pending = true }
|
||||||
|
local scheduled = false
|
||||||
|
require("desktop.pages.setting.overlay").push(desktop, {
|
||||||
|
title = _("漫画缓存"),
|
||||||
|
sections = function()
|
||||||
|
-- 占用走盘:先让叠层用「正在统计…」画出来,下一拍算完再刷新(03 E)。
|
||||||
|
-- 删除后 refreshOverlay(…, true) 把占用标脏,这里重新走一遍同一条路径。
|
||||||
|
if usage_stale then
|
||||||
|
usage_stale = false
|
||||||
|
state.pending = true
|
||||||
|
state.usage, state.all = nil, nil
|
||||||
|
end
|
||||||
|
if state.pending and not scheduled then
|
||||||
|
scheduled = true
|
||||||
|
require("ui/uimanager"):nextTick(function()
|
||||||
|
scheduled = false
|
||||||
|
local probe = Cache.probe()
|
||||||
|
local need_all = probe.ok and (probe.capabilities or {}).delete_all == true
|
||||||
|
state.usage, state.all = loadUsage(need_all)
|
||||||
|
state.pending = false
|
||||||
|
refreshOverlay(plugin)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
return cacheSections(plugin, state)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param plugin table|nil
|
||||||
|
---@return fun(iw: number): table
|
||||||
|
local function cacheRow(plugin)
|
||||||
|
return function(iw)
|
||||||
|
local probe = Cache.probe()
|
||||||
|
local status, on = cacheStatus(probe)
|
||||||
|
return require("ui.themes.widgets.row").widget({
|
||||||
|
width = iw, chevron = true,
|
||||||
|
kind = "nav", icon = "download_done", title = _("漫画缓存"),
|
||||||
|
-- 副标题只承诺真能做到的事:旧接口没有清理入口。
|
||||||
|
subtitle = cleanupReady(probe)
|
||||||
|
and _("清理已读、按系列或全部清理")
|
||||||
|
or _("状态与获取增强版"),
|
||||||
|
status = status, status_on = on,
|
||||||
|
callback = function() showCachePage(plugin) end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param value string|nil
|
||||||
|
---@return string
|
||||||
|
local function normalizeUrl(value)
|
||||||
|
return Text.rtrimSlashes(Text.stripWhitespace(value))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 设置页按 03 原型分三块:连接 / 缓存与同步 / 诊断。
|
||||||
|
---@param plugin table|nil 月读插件实例(取 plugin.path 定位实际安装目录)
|
||||||
|
---@return BookThemeSection[]
|
||||||
|
function Setting.sections(plugin)
|
||||||
|
local connect = {
|
||||||
|
field(plugin, "base_url", _("服务器地址"), "https://kavita.example.com", false, normalizeUrl, "dns"),
|
||||||
|
field(plugin, "api_key", _("API Key"), _("Kavita 用户设置 → API Key"), true, Text.stripWhitespace, "key"),
|
||||||
|
libraryRow(plugin),
|
||||||
|
}
|
||||||
|
if (config().api_key or "") ~= "" then
|
||||||
|
connect[#connect + 1] = require("source.logout").row(ID, _("确定退出 Kavita 账号?"), function()
|
||||||
|
local cfg = config()
|
||||||
|
cfg.api_key = ""
|
||||||
|
require("utils.settings").saveSource(ID, cfg)
|
||||||
|
local Cache = require("moonsource_kavita.cache")
|
||||||
|
Cache.deleteAll()
|
||||||
|
Cache.reset()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
return {
|
||||||
|
{
|
||||||
|
title = _("连接"),
|
||||||
|
rows = connect,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = _("缓存与同步"),
|
||||||
|
rows = { cacheRow(plugin), heartbeatRow(plugin), timeoutRow(plugin) },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = _("诊断"),
|
||||||
|
rows = { testRow() },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 扁平行列表(兼容只认 rows 的调用方与测试);顺序与分组一致。
|
||||||
|
---@param plugin table|nil
|
||||||
|
---@return table[]
|
||||||
|
function Setting.rows(plugin)
|
||||||
|
local rows = {}
|
||||||
|
for _idx, section in ipairs(Setting.sections(plugin)) do
|
||||||
|
for _row_idx, row in ipairs(section.rows) do rows[#rows + 1] = row end
|
||||||
|
end
|
||||||
|
return rows
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 远程管理「连接配置」网页上的表单;书库要连服务器挑,仍在设备上选。
|
||||||
|
Setting.remote = {
|
||||||
|
{ key = "base_url", label = _("服务器地址"), type = "url", placeholder = "https://kavita.example.com",
|
||||||
|
normalize = normalizeUrl },
|
||||||
|
{ key = "api_key", label = _("API Key"), secret = true, normalize = Text.stripWhitespace },
|
||||||
|
}
|
||||||
|
Setting.replace_on_remote = { "base_url", "api_key" }
|
||||||
|
|
||||||
|
return Setting
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,417 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita 阅读统计纯核心:reading-history 条目 + 身份 / 时区上下文 → reading_stats 行与替换指令。
|
||||||
|
|
||||||
|
条目是「会话 × 系列」切片。日 / 时归属按服务端给的 UTC 时刻(`startTimeUtc`)在**设备本地时区**
|
||||||
|
自行分桶:展示端(SQLite `localtime`、`os.date`)用的是同一个进程时区,两边同一真源才对得上账。
|
||||||
|
服务端 `localDate` 是它按请求的 `TimeZoneId` 预先算的日期,映射不上时回退 UTC 会把整段挪一天,
|
||||||
|
所以它只当拿不到 `startTimeUtc` 时的兜底。
|
||||||
|
|
||||||
|
时长取各章活动段之和(有效阅读时间,不含会话内空档,与本地计时语义一致);
|
||||||
|
条目级与聚合结果 `<= 0` 一律丢弃 —— Kavita 会把「打开没读」的会话也写一条 0 时长记录。
|
||||||
|
|
||||||
|
身份粒度由调用方给(`volumes`:本地目录章数):1 章的单卷系列记 series 行,多卷系列记
|
||||||
|
`seriesId:chapterId` 卷行。一条会话可以跨章(多卷)——时长 / 页数按章拆到各卷,
|
||||||
|
否则会把《2001》的时长记到《2010》头上。
|
||||||
|
|
||||||
|
账户日桶 `__kv:day:<当天零点>` 的页数按天**先求和再钳制**(`max(0, ·)`):服务端 pagesRead
|
||||||
|
实测有负数(退页),逐条钳制会让 +1 / -1 相抵的当天凭空多出 1 页。漫画不用 pagesRead 求和,
|
||||||
|
而是按最远进度算新推进的页数(见下),贡献本身已 >= 0。
|
||||||
|
|
||||||
|
账户时段桶 `__kv:hour:<整点>`:每条活动行的时长记在它起始时刻所在的那个本地整点(跨整点的活动行
|
||||||
|
整体算起始小时,与「跨零点的会话整体算起始日」同一口径),供「阅读时段」图用;云端只有这一层
|
||||||
|
粒度,再细就要按跨度分摊,而活动行的跨度含空档,分摊反而把空档算到隔壁小时。
|
||||||
|
|
||||||
|
阅读会话行(`cloud_session`):每个「会话 × 章」切片的起始时刻与时长单独落一行,
|
||||||
|
供书详情 / 统计页的「阅读记录」列出真的读了几点几分;时长不计入日 / 时段 / 总量行
|
||||||
|
(那些桶已经包含它),只在 `sessionRows` 里读。页数(`event_count`)不另写记录类型:
|
||||||
|
核心从这一行累加单书页数。页数口径分两种:
|
||||||
|
|
||||||
|
- 漫画(Image / Archive):`event_count` = **本次新推进的页数**,不是 `pagesRead`。
|
||||||
|
`pagesRead` 是「这次翻了多少页」,重读会重复计入(实测 194 页的卷求和 284);
|
||||||
|
按最远进度算,`SUM(event_count)` 才等于读到的最远页码(≤ 总页数),与 Kavita 的百分比一致。
|
||||||
|
所以漫画还要补 `page = endPage` / `total_pages = 卷级总页数`。
|
||||||
|
- epub / PDF:`pagesRead` 是唯一页数来源,`event_count` 照旧;页坐标仍为 0。
|
||||||
|
|
||||||
|
全量重拉:日桶 / 时段桶 / 总量行按「前缀 + 覆盖到最后观测桶的时间窗」替换;单书行按「上次 ∪ 本次
|
||||||
|
身份」精确替换,顺带清掉身份漂移(单卷 ↔ 多卷、系列重建)遗留的孤儿行。
|
||||||
|
|
||||||
|
纯函数(无文件 / 网络 IO、无全局状态,只经 `logger` 写日志):目录、卷名与「上次身份」由源钩子经 ctx 注入。
|
||||||
|
|
||||||
|
@module moonsource_kavita.stats
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local logger = require("utils.log")
|
||||||
|
|
||||||
|
local Stats = {}
|
||||||
|
|
||||||
|
local DAY_PREFIX = "__kv:day:"
|
||||||
|
local HOUR_PREFIX = "__kv:hour:"
|
||||||
|
local TOTAL_ID = "__kv:total"
|
||||||
|
--- 单条阅读会话(会话 × 章切片)——只给「阅读记录」列表用,不参与任何时长汇总。
|
||||||
|
local SESSION_RECORD = "cloud_session"
|
||||||
|
|
||||||
|
--- features/clock/init.lua 的 Clock.TIMEZONES 的 19 项 POSIX 串 → Kavita 的 TimeZoneId。
|
||||||
|
--- 只查表:不读 /etc/localtime(KOReader 设备上不保证存在,读到的也未必是用户选的时区),
|
||||||
|
--- 不按偏移猜地区。映射不上就按 UTC 请求 —— 只影响 `localDate` 这个兜底(正常条目都带
|
||||||
|
--- `startTimeUtc`,分日 / 分时按设备本地时区自行换算,见 utcEpoch / dayStart)。
|
||||||
|
local IANA_BY_POSIX = {
|
||||||
|
["HST10"] = "Pacific/Honolulu",
|
||||||
|
["AKST9AKDT,M3.2.0,M11.1.0"] = "America/Anchorage",
|
||||||
|
["PST8PDT,M3.2.0,M11.1.0"] = "America/Los_Angeles",
|
||||||
|
["MST7MDT,M3.2.0,M11.1.0"] = "America/Denver",
|
||||||
|
["CST6CDT,M3.2.0,M11.1.0"] = "America/Chicago",
|
||||||
|
["EST5EDT,M3.2.0,M11.1.0"] = "America/New_York",
|
||||||
|
["<-03>3"] = "America/Sao_Paulo",
|
||||||
|
["UTC0"] = "UTC",
|
||||||
|
["GMT0BST,M3.5.0/1,M10.5.0"] = "Europe/London",
|
||||||
|
["CET-1CEST,M3.5.0,M10.5.0/3"] = "Europe/Berlin",
|
||||||
|
["EET-2EEST,M3.5.0/3,M10.5.0/4"] = "Europe/Athens",
|
||||||
|
["MSK-3"] = "Europe/Moscow",
|
||||||
|
["<+04>-4"] = "Asia/Dubai",
|
||||||
|
["IST-5:30"] = "Asia/Kolkata",
|
||||||
|
["<+07>-7"] = "Asia/Bangkok",
|
||||||
|
["CST-8"] = "Asia/Shanghai",
|
||||||
|
["JST-9"] = "Asia/Tokyo",
|
||||||
|
["AEST-10AEDT,M10.1.0,M4.1.0/3"] = "Australia/Sydney",
|
||||||
|
["NZST-12NZDT,M9.5.0,M4.1.0/3"] = "Pacific/Auckland",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- 设备时钟的 POSIX 串 → IANA。未知 / 空串(跟随系统)回退 UTC 并记日志。
|
||||||
|
---@param posix string|nil 进程 TZ 环境变量(时钟功能按设置写入)
|
||||||
|
---@return string
|
||||||
|
function Stats.ianaTimezone(posix)
|
||||||
|
local iana = type(posix) == "string" and IANA_BY_POSIX[posix] or nil
|
||||||
|
if iana then return iana end
|
||||||
|
logger.warn("kavita stats timezone unmapped, fallback to UTC", posix)
|
||||||
|
return "UTC"
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 合成 reading_stats 行;云端默认没有页坐标,page / total_pages 恒为 0。
|
||||||
|
--- 漫画(Image / Archive)的会话行由调用方在拿到 endPage / totalPages 后补上。
|
||||||
|
---@param source_id string
|
||||||
|
---@param stable_id string
|
||||||
|
---@param record_type string
|
||||||
|
---@param start_time number
|
||||||
|
---@param duration number
|
||||||
|
---@param last_time number
|
||||||
|
---@return BookStatsRow
|
||||||
|
local function statsRow(source_id, stable_id, record_type, start_time, duration, last_time)
|
||||||
|
return {
|
||||||
|
source_id = source_id,
|
||||||
|
stable_id = stable_id,
|
||||||
|
record_type = record_type,
|
||||||
|
page = 0,
|
||||||
|
start_time = start_time,
|
||||||
|
duration = duration,
|
||||||
|
total_pages = 0,
|
||||||
|
last_time = last_time,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 服务端 localDate("2026-10-15T00:00:00")→ 当天设备本地零点;解不出返回 nil。
|
||||||
|
--- 只取日期部分:时刻是被请求时区下的零点,换算成设备本地同一日期即可。
|
||||||
|
---@param local_date any
|
||||||
|
---@return number|nil
|
||||||
|
local function localMidnight(local_date)
|
||||||
|
local y, m, d = tostring(local_date):match("^(%d%d%d%d)-(%d%d)-(%d%d)")
|
||||||
|
if not y then return nil end
|
||||||
|
return os.time({ year = tonumber(y), month = tonumber(m), day = tonumber(d), hour = 0 })
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 服务端 UTC 时间戳("2026-10-15T23:51:47.4527045")→ 设备本地 epoch;解不出返回 nil。
|
||||||
|
--- os.time 按进程 TZ(POSIX 串,自带夏令时规则)解释墙钟,所以先把 UTC 墙钟当本地算出 E',
|
||||||
|
--- 再补回一个用 E' 处的本地偏移量的差。偏移的表必须重建:os.date 给的表带 `isdst`,直接回喂
|
||||||
|
--- os.time 会把夏令时钉成标准时、整整差一小时(跨夏令时切换的时区实测过)。
|
||||||
|
---@param text any
|
||||||
|
---@return number|nil
|
||||||
|
local function utcEpoch(text)
|
||||||
|
local y, mo, d, h, mi, s = tostring(text):match("^(%d%d%d%d)%-(%d%d)%-(%d%d)T(%d%d):(%d%d):(%d%d)")
|
||||||
|
if not y then return nil end
|
||||||
|
local as_local = os.time({ year = tonumber(y), month = tonumber(mo), day = tonumber(d),
|
||||||
|
hour = tonumber(h), min = tonumber(mi), sec = tonumber(s) })
|
||||||
|
if not as_local then return nil end
|
||||||
|
local u = os.date("!*t", as_local)
|
||||||
|
local back = os.time({ year = u.year, month = u.month, day = u.day, hour = u.hour, min = u.min, sec = u.sec })
|
||||||
|
return as_local + os.difftime(as_local, back)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 设备本地时区的当日零点。`isdst` 取自本地分解,跨切换的零点不会被挪一小时。
|
||||||
|
---@param epoch number
|
||||||
|
---@return number
|
||||||
|
local function dayStart(epoch)
|
||||||
|
local t = os.date("*t", epoch)
|
||||||
|
return os.time({ year = t.year, month = t.month, day = t.day, hour = 0, isdst = t.isdst })
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 时段桶键:`day` 那天的、`epoch` 所在小时。跨零点的活动行仍记在条目那天(取小时、换日期),
|
||||||
|
--- 这样「日页面逐格之和 = 当日日桶」,不会出现某天的时段和比标题少一截。
|
||||||
|
---@param day number 当日零点
|
||||||
|
---@param epoch number 活动行起始时刻
|
||||||
|
---@return number
|
||||||
|
local function hourBucket(day, epoch)
|
||||||
|
local d = os.date("*t", day)
|
||||||
|
local a = os.date("*t", epoch)
|
||||||
|
return os.time({ year = d.year, month = d.month, day = d.day, hour = a.hour, isdst = a.isdst })
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 本地目录章数:1 = 单卷(读在 series 行),>1 = 多卷(读在卷行);拿不到返回 nil。
|
||||||
|
--- 数字 / 字符串键都收:状态文件里的 seriesId 可能两种写法。
|
||||||
|
---@param volumes table
|
||||||
|
---@param series_id string
|
||||||
|
---@return number|nil
|
||||||
|
local function volumeCount(volumes, series_id)
|
||||||
|
local count = volumes[series_id]
|
||||||
|
if count == nil then count = volumes[tonumber(series_id) or series_id] end
|
||||||
|
count = tonumber(count)
|
||||||
|
if not count or count < 1 then return nil end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 漫画章行:页数贡献要按身份排完序才能算(见 fromHistory 里「漫画最远进度」一段)。
|
||||||
|
---@class KavitaComicSlice
|
||||||
|
---@field identity string 卷身份(单卷 = seriesId,多卷 = seriesId:chapterId)
|
||||||
|
---@field day number 该活动行归属的本地零点(推进的页数记进这一天)
|
||||||
|
---@field epoch number|nil 会话行 start_time(也是排序键)
|
||||||
|
---@field order number 回包顺序,仅用于同一时刻的稳定排序
|
||||||
|
---@field duration number 秒;`> 0` 才发行
|
||||||
|
---@field page number 原始 endPage(会话行的进度坐标)
|
||||||
|
---@field end_page number 钳到总页数后的结束页(算推进页数用)
|
||||||
|
---@field total_pages number 卷级总页数
|
||||||
|
|
||||||
|
---@class KavitaStatsContext
|
||||||
|
---@field source_id string 本源 id(写进每行)
|
||||||
|
---@field fetched_at number|nil 拉取时刻(缺省 now);写进行 / 桶的 last_time
|
||||||
|
---@field volumes table<number|string, number>|nil seriesId → 本地目录章数(1 = 单卷)
|
||||||
|
---@field seen string[]|nil 上次拉取的身份列表(用于清身份漂移遗留的孤儿行)
|
||||||
|
|
||||||
|
--- reading-history 条目 → reading_stats 行 + 替换指令 + 本次身份。
|
||||||
|
---@param entries table[]|nil reading-history 条目(wire 已解码),通常为分页合并后的全量
|
||||||
|
---@param ctx KavitaStatsContext
|
||||||
|
---@return { rows: BookStatsRow[], replace: BookStatsPullReplace, identities: string[] }
|
||||||
|
function Stats.fromHistory(entries, ctx)
|
||||||
|
ctx = ctx or {}
|
||||||
|
local source_id = ctx.source_id
|
||||||
|
local fetched_at = tonumber(ctx.fetched_at) or os.time()
|
||||||
|
local volumes = ctx.volumes or {}
|
||||||
|
|
||||||
|
local rows = {}
|
||||||
|
local book_days = {} ---@type table<string, table<number, number>> 身份 → 日 → 秒
|
||||||
|
local book_totals = {} ---@type table<string, number>
|
||||||
|
local day_durations = {} ---@type table<number, number>
|
||||||
|
local day_pages = {} ---@type table<number, number>
|
||||||
|
local hour_durations = {} ---@type table<number, number> 整点 → 秒(账户时段桶)
|
||||||
|
local last_day = 0 ---@type number 本次回包里最晚的观测日(零点)
|
||||||
|
local last_hour = 0 ---@type number 本次回包里最晚的观测整点
|
||||||
|
local comic_slices = {} ---@type KavitaComicSlice[] 漫画章行,算完进度贡献再落行
|
||||||
|
local identities, known, warned_series = {}, {}, {}
|
||||||
|
|
||||||
|
--- 记下本次出现的身份。零时长条目也记:它上次可能有行,靠 replace.books 清掉。
|
||||||
|
local function noteIdentity(identity)
|
||||||
|
if identity and not known[identity] then
|
||||||
|
known[identity] = true
|
||||||
|
identities[#identities + 1] = identity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _idx, entry in ipairs(type(entries) == "table" and entries or {}) do
|
||||||
|
local series_id = entry.seriesId ~= nil and tostring(entry.seriesId) or nil
|
||||||
|
local count = series_id and volumeCount(volumes, series_id) or nil
|
||||||
|
if not count then
|
||||||
|
-- 判不出单卷 / 多卷的系列整体跳过:身份是错的比缺行更糟(源钩子侧也会记)。
|
||||||
|
if series_id and not warned_series[series_id] then
|
||||||
|
warned_series[series_id] = true
|
||||||
|
logger.warn("kavita stats skip series without volume info", series_id)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- 有 UTC 时刻就按设备本地分日 / 分时;没有才退服务端按请求时区算好的 localDate(无小时)。
|
||||||
|
local anchor = utcEpoch(entry.startTimeUtc)
|
||||||
|
local day
|
||||||
|
if anchor then
|
||||||
|
day = dayStart(anchor)
|
||||||
|
else
|
||||||
|
day = localMidnight(entry.localDate)
|
||||||
|
if day then logger.warn("kavita stats entry without usable startTimeUtc", series_id) end
|
||||||
|
end
|
||||||
|
if not day then
|
||||||
|
logger.warn("kavita stats entry without usable day", series_id)
|
||||||
|
else
|
||||||
|
if day > last_day then last_day = day end
|
||||||
|
local chapters = type(entry.chapters) == "table" and entry.chapters or {}
|
||||||
|
-- 漫画才有真实页坐标:Kavita 的 seriesFormat 0 = Image、1 = Archive 是图片页;
|
||||||
|
-- epub(3)的 chapter.pages 是 spine / 阅读单元(6 万字的书 32 个),PDF(4)同理,
|
||||||
|
-- 都不是渲染页,填进 page / total_pages 会让详情页的「读了多少页」变成假的。
|
||||||
|
-- seriesFormat 在条目顶层,不在 chapter 上(实测响应见 history-7453-all.json)。
|
||||||
|
local fmt = tonumber(entry.seriesFormat)
|
||||||
|
local comic = fmt == 0 or fmt == 1
|
||||||
|
local entry_duration = 0
|
||||||
|
for _ci, chapter in ipairs(chapters) do
|
||||||
|
entry_duration = entry_duration + (tonumber(chapter.durationSeconds) or 0)
|
||||||
|
end
|
||||||
|
-- 单卷:没有章行也读在 series 上;多卷:没有 chapterId 就拆不出来,跳过该章。
|
||||||
|
if count == 1 then noteIdentity(series_id) end
|
||||||
|
local contributes = entry_duration > 0
|
||||||
|
for _ci, chapter in ipairs(chapters) do
|
||||||
|
local identity = series_id
|
||||||
|
if count > 1 then
|
||||||
|
identity = chapter.chapterId ~= nil
|
||||||
|
and (series_id .. ":" .. tostring(chapter.chapterId)) or nil
|
||||||
|
if not identity then
|
||||||
|
logger.warn("kavita stats chapter without chapterId", series_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
noteIdentity(identity)
|
||||||
|
if identity then
|
||||||
|
local duration = tonumber(chapter.durationSeconds) or 0
|
||||||
|
-- 章活动行自己的起始时刻(时段桶 / 会话行 / 漫画排序共用);拿不到就退回条目起始时刻。
|
||||||
|
local chapter_epoch = utcEpoch(chapter.startTimeUtc) or anchor
|
||||||
|
if contributes and duration > 0 then
|
||||||
|
local days = book_days[identity]
|
||||||
|
if not days then
|
||||||
|
days = {}
|
||||||
|
book_days[identity] = days
|
||||||
|
end
|
||||||
|
days[day] = (days[day] or 0) + duration
|
||||||
|
book_totals[identity] = (book_totals[identity] or 0) + duration
|
||||||
|
day_durations[day] = (day_durations[day] or 0) + duration
|
||||||
|
-- 时段桶:按活动行自己的起始小时;拿不到就退回条目起始时刻。
|
||||||
|
if chapter_epoch then
|
||||||
|
local bucket = hourBucket(day, chapter_epoch)
|
||||||
|
hour_durations[bucket] = (hour_durations[bucket] or 0) + duration
|
||||||
|
if bucket > last_hour then last_hour = bucket end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if comic then
|
||||||
|
-- 漫画的页数不能边遍历边累加:`pagesRead` 是「这次翻了多少页」,重读会重复计入。
|
||||||
|
-- 先收集,按身份(卷)× 起始时刻排序后再算「本次新推进的页数」。
|
||||||
|
local total_pages = math.max(0, tonumber(chapter.totalPages) or 0)
|
||||||
|
local page = math.max(0, tonumber(chapter.endPage) or 0)
|
||||||
|
comic_slices[#comic_slices + 1] = {
|
||||||
|
identity = identity,
|
||||||
|
day = day,
|
||||||
|
epoch = chapter_epoch,
|
||||||
|
order = #comic_slices + 1,
|
||||||
|
duration = duration,
|
||||||
|
page = page,
|
||||||
|
-- 只有拿到总页数才钳:缺总页数时别凭空假设一个上界。
|
||||||
|
end_page = total_pages > 0 and math.min(page, total_pages) or page,
|
||||||
|
total_pages = total_pages,
|
||||||
|
}
|
||||||
|
elseif contributes then
|
||||||
|
if duration > 0 and chapter_epoch then
|
||||||
|
-- 阅读会话行:详情「阅读记录」按真实起止时间列出这一段。
|
||||||
|
local session = statsRow(source_id, identity, SESSION_RECORD,
|
||||||
|
chapter_epoch, duration, fetched_at)
|
||||||
|
session.event_count = math.max(0, tonumber(chapter.pagesRead) or 0)
|
||||||
|
rows[#rows + 1] = session
|
||||||
|
end
|
||||||
|
day_pages[day] = (day_pages[day] or 0) + (tonumber(chapter.pagesRead) or 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 漫画:按身份(卷)分别按起始时刻升序走一遍,只留「比此前更远」的页数 —— 这样重读不再重复计入,
|
||||||
|
-- 跳读也只按推进到哪算,`SUM(event_count)` = 读到的最远页码(天然 ≤ 总页数),与 Kavita 百分比一致。
|
||||||
|
-- 回包可能是新→旧(服务端按时间倒序),所以必须排序,不能依赖遍历顺序。
|
||||||
|
table.sort(comic_slices, function(a, b)
|
||||||
|
if a.identity ~= b.identity then return a.identity < b.identity end
|
||||||
|
local ae, be = a.epoch or 0, b.epoch or 0
|
||||||
|
if ae ~= be then return ae < be end
|
||||||
|
return a.order < b.order
|
||||||
|
end)
|
||||||
|
local reached = {} ---@type table<string, number> 身份(卷)→ 此前到达的最远页码
|
||||||
|
for _idx, slice in ipairs(comic_slices) do
|
||||||
|
local previous = reached[slice.identity] or 0
|
||||||
|
local advance = slice.end_page - previous
|
||||||
|
if advance < 0 then advance = 0 end
|
||||||
|
if slice.end_page > previous then reached[slice.identity] = slice.end_page end
|
||||||
|
-- 零时长章行不发行(会话行说的是「这一段读了多久」),但推进照样算进当天页数:
|
||||||
|
-- 否则这次跳读会从当天页数里消失,而后续会话又因 reached 更高而少算。
|
||||||
|
day_pages[slice.day] = (day_pages[slice.day] or 0) + advance
|
||||||
|
-- 零时长章行也要发行:Kavita 的会话是「两次进度写入之间」,只写一次(开书 / 关书各一次)
|
||||||
|
-- 就是 0 秒,但推进的页数是真的。丢掉它,详情页「已读页数 / 上次阅读」会整段消失
|
||||||
|
-- (另一台设备刚读的那一卷尤其明显)。既没时长又没推进的(打开没翻)才跳过。
|
||||||
|
if slice.epoch and (slice.duration > 0 or advance > 0) then
|
||||||
|
local session = statsRow(source_id, slice.identity, SESSION_RECORD,
|
||||||
|
slice.epoch, slice.duration, fetched_at)
|
||||||
|
session.event_count = advance
|
||||||
|
-- page = endPage(读到哪一页,核心 reading_stats.page 的语义);total_pages 取卷级,
|
||||||
|
-- 多卷系列汇总处取 MAX。pagesRead = 0 是合法值(打开没翻页),不是缺数据。
|
||||||
|
session.page = slice.page
|
||||||
|
session.total_pages = slice.total_pages
|
||||||
|
rows[#rows + 1] = session
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for identity, days in pairs(book_days) do
|
||||||
|
for day, duration in pairs(days) do
|
||||||
|
if duration > 0 then
|
||||||
|
rows[#rows + 1] = statsRow(source_id, identity, "book_day", day, duration, fetched_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for identity, duration in pairs(book_totals) do
|
||||||
|
if duration > 0 then
|
||||||
|
rows[#rows + 1] = statsRow(source_id, identity, "book_total", fetched_at, duration, fetched_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local grand_total = 0
|
||||||
|
for day, duration in pairs(day_durations) do
|
||||||
|
grand_total = grand_total + duration
|
||||||
|
if duration > 0 then
|
||||||
|
local row = statsRow(source_id, DAY_PREFIX .. tostring(day), "day", day, duration, fetched_at)
|
||||||
|
row.event_count = math.max(0, day_pages[day] or 0)
|
||||||
|
rows[#rows + 1] = row
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for hour, duration in pairs(hour_durations) do
|
||||||
|
if duration > 0 then
|
||||||
|
rows[#rows + 1] = statsRow(source_id, HOUR_PREFIX .. tostring(hour), "hour", hour, duration, fetched_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if grand_total > 0 then
|
||||||
|
rows[#rows + 1] = statsRow(source_id, TOTAL_ID, "total", 0, grand_total, fetched_at)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 稳定输出:持久化顺序与对账都别受 pairs 遍历顺序影响。
|
||||||
|
table.sort(rows, function(a, b)
|
||||||
|
if a.record_type ~= b.record_type then return a.record_type < b.record_type end
|
||||||
|
if a.start_time ~= b.start_time then return a.start_time < b.start_time end
|
||||||
|
return a.stable_id < b.stable_id
|
||||||
|
end)
|
||||||
|
table.sort(identities)
|
||||||
|
|
||||||
|
local books, book_known = {}, {}
|
||||||
|
local function addBook(stable_id)
|
||||||
|
if type(stable_id) == "string" and stable_id ~= "" and not book_known[stable_id] then
|
||||||
|
book_known[stable_id] = true
|
||||||
|
books[#books + 1] = stable_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for _idx, stable_id in ipairs(type(ctx.seen) == "table" and ctx.seen or {}) do addBook(stable_id) end
|
||||||
|
for _idx, identity in ipairs(identities) do addBook(identity) end
|
||||||
|
table.sort(books)
|
||||||
|
|
||||||
|
return {
|
||||||
|
rows = rows,
|
||||||
|
replace = {
|
||||||
|
mode = "ranges",
|
||||||
|
ranges = {
|
||||||
|
-- 全量重拉:窗口一直连到最后观测日 / 整点的桶止,清掉本次回包里已消失的桶。
|
||||||
|
-- 上界不能只取拉取时刻:服务端「当天」可能晚于设备本地的拉取时刻(设备为负偏移),
|
||||||
|
-- 桶零点会落在窗口外、清不掉(残留到下一轮)。
|
||||||
|
{ stable_prefix = DAY_PREFIX, from_ts = 0, to_ts = math.max(fetched_at, last_day + 86399) },
|
||||||
|
{ stable_prefix = HOUR_PREFIX, from_ts = 0, to_ts = math.max(fetched_at, last_hour + 3599) },
|
||||||
|
{ stable_prefix = TOTAL_ID, from_ts = 0, to_ts = 0 },
|
||||||
|
},
|
||||||
|
-- 上次 ∪ 本次:身份漂移后旧身份不再出现在回包里,只能按它精确清。
|
||||||
|
books = books,
|
||||||
|
},
|
||||||
|
-- 交回给源持久化:下次拉取当「上次身份」用。
|
||||||
|
identities = identities,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return Stats
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- 版本号由 tools/package.sh 打包时把占位符换成发布版本;源码运行显示 0.0.0-dev。
|
||||||
|
local VERSION = "@VERSION@"
|
||||||
|
if VERSION:find("^@") then return "0.0.0-dev" end
|
||||||
|
return VERSION
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,211 @@
|
|||||||
|
--[[--
|
||||||
|
extensions/moonsource-kavita.koplugin:注解线上形态(写入 / 读回)与同一性键。
|
||||||
|
|
||||||
|
备注在 Kavita 侧是 Quill Delta JSON(`comment`)+ Quill HTML(`commentHtml`),
|
||||||
|
纯文本 `commentPlainText` 由后端从 HTML 去标签算出来。拉取、推送、冲突判定必须
|
||||||
|
共用这一套归一,否则同一段备注每次都会判「改过」→ 无限 update。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.annotation_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
local JsonStub = require("support.json_stub")
|
||||||
|
|
||||||
|
-- 模块内部 require("json");这里给真实语义的往返桩(encode 出的串 decode 得回同一结构)。
|
||||||
|
package.loaded["json"] = { encode = JsonStub.encode, decode = JsonStub.decode }
|
||||||
|
|
||||||
|
local Annotation = dofile((debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita") .. "/annotation.lua")
|
||||||
|
|
||||||
|
-- 读回:空值集合一律空串(漏判的后果不是显示花括号,而是 note 变成 "{}" → 无限 update)。
|
||||||
|
Assert.eq(Annotation.noteText(nil), "")
|
||||||
|
Assert.eq(Annotation.noteText(""), "")
|
||||||
|
Assert.eq(Annotation.noteText(" "), "")
|
||||||
|
Assert.eq(Annotation.noteText("{}"), "")
|
||||||
|
Assert.eq(Annotation.noteText('{"ops":[]}'), "")
|
||||||
|
Assert.eq(Annotation.noteText('{"ops":[{"insert":"\\n"}]}'), "")
|
||||||
|
Assert.eq(Annotation.noteText('{"ops":[{"insert":" \\n"}]}'), "", "只含空白 insert 也是空")
|
||||||
|
Assert.eq(Annotation.noteText("null"), "")
|
||||||
|
|
||||||
|
-- Delta:拼接字符串 insert,跳过 embed,忽略 attributes,剥掉末尾换行。
|
||||||
|
Assert.eq(Annotation.noteText('{"ops":[{"insert":"一句话\\n"}]}'), "一句话")
|
||||||
|
Assert.eq(
|
||||||
|
Annotation.noteText('{"ops":[{"insert":"第一行\\n"},{"insert":"第二行","attributes":{"bold":true}},{"insert":"\\n"}]}'),
|
||||||
|
"第一行\n第二行"
|
||||||
|
)
|
||||||
|
Assert.eq(
|
||||||
|
Annotation.noteText('{"ops":[{"insert":"有图\\n"},{"insert":{"image":"x.png"}},{"insert":"\\n"}]}'),
|
||||||
|
"有图",
|
||||||
|
"非字符串 insert(图片等 embed)跳过"
|
||||||
|
)
|
||||||
|
Assert.eq(Annotation.noteText('{"ops":[{"insert":"a\\nb\\n"}]}'), "a\nb", "文内换行原样保留")
|
||||||
|
|
||||||
|
-- 非 JSON 的 legacy 纯文本:原样返回(不能当空,也不能当 Delta 报错)。
|
||||||
|
Assert.eq(Annotation.noteText("存量纯文本备注"), "存量纯文本备注")
|
||||||
|
|
||||||
|
-- 优先级:commentHtml → commentPlainText → 解析 comment。
|
||||||
|
Assert.eq(Annotation.noteText('{"ops":[{"insert":"delta\\n"}]}', "<p>html</p>", "plain"), "html")
|
||||||
|
Assert.eq(Annotation.noteText('{"ops":[{"insert":"delta\\n"}]}', "", "plain"), "plain")
|
||||||
|
Assert.eq(Annotation.noteText('{"ops":[{"insert":"delta\\n"}]}', " ", " "), "delta")
|
||||||
|
|
||||||
|
-- commentHtml:块级边界转换行(后端 StripHtml 不插分隔,块之间会粘)。
|
||||||
|
Assert.eq(Annotation.noteText(nil, "<p>第一段</p><p>第二段</p>", ""), "第一段\n第二段")
|
||||||
|
Assert.eq(Annotation.noteText(nil, "<p>a<br>b</p>", ""), "a\nb")
|
||||||
|
Assert.eq(Annotation.noteText(nil, "<p>a</p><p><br></p><p>b</p>", ""), "a\n\nb", "Quill 空行")
|
||||||
|
Assert.eq(Annotation.noteText(nil, "<div>a</div><div>b</div>", ""), "a\nb")
|
||||||
|
Assert.eq(Annotation.noteText(nil, "<p>a & b <c> "d"</p>", ""), 'a & b <c> "d"', "实体解码")
|
||||||
|
Assert.eq(Annotation.noteText(nil, "<p><br></p>", ""), "", "全删后的空 HTML 也是空")
|
||||||
|
|
||||||
|
-- 写入:空备注与 Web「新建未输入」字节一致("{}" + ""),不能写 {"ops":[...]}。
|
||||||
|
for _idx, note in ipairs({ nil, "", " ", "\n\n", " \n \n" }) do
|
||||||
|
local remote = Annotation.toRemote(note)
|
||||||
|
Assert.eq(remote.comment, "{}", "空备注 comment")
|
||||||
|
Assert.eq(remote.commentHtml, "", "空备注 commentHtml")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 写入:单个 insert op、末尾补 \n(Delta 文档必须以换行结尾);每行一个 <p>。
|
||||||
|
local one = Annotation.toRemote("第一行\n第二行")
|
||||||
|
local ops = JsonStub.decode(one.comment).ops
|
||||||
|
Assert.eq(#ops, 1, "只有一个 insert op")
|
||||||
|
Assert.eq(ops[1].insert, "第一行\n第二行\n")
|
||||||
|
Assert.eq(one.commentHtml, "<p>第一行</p><p>第二行</p>", "空行写 <p><br></p>")
|
||||||
|
Assert.eq(Annotation.toRemote("a\n\nb").commentHtml, "<p>a</p><p><br></p><p>b</p>")
|
||||||
|
|
||||||
|
-- 写入:转义 & < > ";先转 & 再转别的,避免二次转义。
|
||||||
|
Assert.eq(
|
||||||
|
Annotation.toRemote('a & b < c > d "e"').commentHtml,
|
||||||
|
"<p>a & b < c > d "e"</p>"
|
||||||
|
)
|
||||||
|
|
||||||
|
-- 写入:CRLF 归一、尾部换行去掉(否则每轮读回都多一行 → 判改过)。
|
||||||
|
local crlf = Annotation.toRemote("a\r\nb\n\n")
|
||||||
|
Assert.eq(JsonStub.decode(crlf.comment).ops[1].insert, "a\nb\n")
|
||||||
|
Assert.eq(crlf.commentHtml, "<p>a</p><p>b</p>")
|
||||||
|
|
||||||
|
-- 往返:自己写的备注读回后与归一后的 note 一致(push / pull 同一口径 → 零 update)。
|
||||||
|
for _idx, note in ipairs({
|
||||||
|
"一句话",
|
||||||
|
"第一行\n第二行",
|
||||||
|
"a\n\nb",
|
||||||
|
'引号 " 与反斜杠 \\ 都原样',
|
||||||
|
"小于 < 大于 > 和 & 号",
|
||||||
|
"好书📚 与 emoji 👍🏽",
|
||||||
|
" 行首缩进保留",
|
||||||
|
}) do
|
||||||
|
local remote = Annotation.toRemote(note)
|
||||||
|
Assert.eq(Annotation.noteText(remote.comment), note, "Delta 读回:" .. note)
|
||||||
|
Assert.eq(
|
||||||
|
Annotation.noteText(remote.comment, remote.commentHtml, ""),
|
||||||
|
note,
|
||||||
|
"完整 DTO 读回(commentHtml 优先):" .. note
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 比较归一:trim + 内部连续空白压一个 + 零宽剔除;两边都空判等。
|
||||||
|
Assert.is_true(Annotation.sameNote(nil, ""))
|
||||||
|
Assert.is_true(Annotation.sameNote("", " "))
|
||||||
|
Assert.is_true(Annotation.sameNote("a b", " a b "))
|
||||||
|
Assert.is_true(Annotation.sameNote("a\nb", "a b"), "换行也是空白")
|
||||||
|
Assert.is_true(Annotation.sameNote("a\226\128\139b", "ab"), "零宽空格剔除")
|
||||||
|
Assert.is_true(Annotation.sameNote("a\239\187\191b", "ab"), "BOM 剔除")
|
||||||
|
Assert.is_false(Annotation.sameNote("a", "b"))
|
||||||
|
Assert.is_false(Annotation.sameNote("", "a"))
|
||||||
|
|
||||||
|
-- 幂等键:comment 不参与、selectedText 空白归一、xPath 精确。
|
||||||
|
local base = { chapterId = 7, xPath = "//body/p[1]", endingXPath = "//body/p[2]", selectedText = "选中 文本" }
|
||||||
|
local function keyOf(over)
|
||||||
|
local ann = {}
|
||||||
|
for k, v in pairs(base) do ann[k] = v end
|
||||||
|
for k, v in pairs(over or {}) do ann[k] = v end
|
||||||
|
return Annotation.key(ann)
|
||||||
|
end
|
||||||
|
Assert.eq(keyOf({ comment = "甲" }), keyOf({ comment = "乙" }), "改备注不是新建")
|
||||||
|
Assert.eq(keyOf({ selectedText = " 选中\n文本 " }), keyOf({}), "选中文本的空白差异命中")
|
||||||
|
Assert.is_true(keyOf({ xPath = "//body/p[9]" }) ~= keyOf({}))
|
||||||
|
Assert.is_true(keyOf({ endingXPath = "//body/p[9]" }) ~= keyOf({}))
|
||||||
|
Assert.is_true(keyOf({ chapterId = 8 }) ~= keyOf({}))
|
||||||
|
Assert.eq(keyOf({}), "7" .. string.char(31) .. "//body/p[1]" .. string.char(31) .. "//body/p[2]" .. string.char(31) .. "选中 文本")
|
||||||
|
-- 分隔符对外导出:源侧拼「同坐标」判定键用的是同一个字符,不各写一份字面量。
|
||||||
|
Assert.eq(Annotation.KEY_SEP, string.char(31))
|
||||||
|
-- pull 落库后的本地条目把选中文本叫 text。
|
||||||
|
Assert.eq(
|
||||||
|
Annotation.key({ chapterId = 7, xPath = "//body/p[1]", endingXPath = "//body/p[2]", text = "选中 文本" }),
|
||||||
|
keyOf({})
|
||||||
|
)
|
||||||
|
-- payload 形状(pull 落库后 / 阅读器快照里的条目)没有 DTO 字段名:xPath / endingXPath / selectedText
|
||||||
|
-- 的回退是 kavita_xpath / kavita_ending_xpath / text。源侧「远端同键去重」直接拿它当键。
|
||||||
|
Assert.eq(
|
||||||
|
Annotation.key({ chapterId = 7, kavita_xpath = "//body/p[1]", kavita_ending_xpath = "//body/p[2]",
|
||||||
|
text = "选中 文本" }),
|
||||||
|
keyOf({}),
|
||||||
|
"payload 字段与 DTO 字段算出同一个键"
|
||||||
|
)
|
||||||
|
Assert.eq(
|
||||||
|
Annotation.key({ kavita_xpath = "//body/p[1]", kavita_ending_xpath = "//body/p[2]", text = "选中 文本" }),
|
||||||
|
Annotation.key({ xPath = "//body/p[1]", endingXPath = "//body/p[2]", selectedText = "选中 文本" })
|
||||||
|
)
|
||||||
|
Assert.eq(
|
||||||
|
Annotation.key({ chapterId = 7, xPath = "//body/p[1]", kavita_xpath = "//body/p[9]", endingXPath = "//body/p[2]",
|
||||||
|
text = "选中 文本" }),
|
||||||
|
keyOf({}),
|
||||||
|
"DTO 字段优先,回退只在缺失时生效"
|
||||||
|
)
|
||||||
|
|
||||||
|
-- 对账命中:同键多条取 id 最小;无命中 nil。
|
||||||
|
local remote = {
|
||||||
|
{ id = 9, chapterId = 7, xPath = "//body/p[1]", endingXPath = "//body/p[2]", selectedText = "选中 文本", comment = "{}" },
|
||||||
|
{ id = 3, chapterId = 7, xPath = "//body/p[1]", endingXPath = "//body/p[2]", selectedText = " 选中\n文本 ", comment = "{ops}" },
|
||||||
|
{ id = 1, chapterId = 7, xPath = "//body/p[5]", endingXPath = "//body/p[6]", selectedText = "别的划线" },
|
||||||
|
}
|
||||||
|
Assert.eq(Annotation.match(remote, base).id, 3, "同键两条取 id 最小")
|
||||||
|
Assert.eq(Annotation.match({ { id = "12", chapterId = 7, xPath = "//body/p[1]", endingXPath = "//body/p[2]", selectedText = "选中 文本" } }, base).id, "12", "字符串 id 也能比")
|
||||||
|
Assert.is_nil(Annotation.match(remote, { chapterId = 7, xPath = "//body/p[7]", endingXPath = "//body/p[8]", selectedText = "x" }))
|
||||||
|
Assert.is_nil(Annotation.match(nil, base))
|
||||||
|
|
||||||
|
-- 列表:`GET /api/Annotation/all?chapterId=`,无分页;owner_id 非空才按 ownerUserId 过滤
|
||||||
|
-- (owner_id 为空是 `/api/Users/me` 不可用时的降级:不过滤,宁可多看到自己的)。
|
||||||
|
local chapter = {
|
||||||
|
{ id = 1, ownerUserId = 5, comment = "{}" },
|
||||||
|
{ id = 2, ownerUserId = 9, comment = "别人的纯文本备注" },
|
||||||
|
{ id = 3, ownerUserId = 5, comment = "" },
|
||||||
|
}
|
||||||
|
local calls = {}
|
||||||
|
local function clientReturning(data, err)
|
||||||
|
return {
|
||||||
|
json = function(_self, method, path, query, body, cb)
|
||||||
|
calls[#calls + 1] = { method = method, path = path, query = query, body = body }
|
||||||
|
cb(data, err)
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local got, got_err
|
||||||
|
Annotation.listByChapter(clientReturning(chapter), 12763, nil, function(list, err) got, got_err = list, err end)
|
||||||
|
Assert.eq(calls[1].method, "GET")
|
||||||
|
Assert.eq(calls[1].path, "/api/Annotation/all")
|
||||||
|
Assert.eq(calls[1].query.chapterId, 12763)
|
||||||
|
Assert.is_nil(calls[1].query.pageNumber, "该接口没有分页")
|
||||||
|
Assert.is_nil(calls[1].body)
|
||||||
|
Assert.eq(#got, 3, "owner_id 为空时不过滤")
|
||||||
|
Assert.is_nil(got_err)
|
||||||
|
|
||||||
|
calls = {}
|
||||||
|
Annotation.listByChapter(clientReturning(chapter), 12763, 5, function(list) got = list end)
|
||||||
|
Assert.eq(#got, 2, "只留自己的注解")
|
||||||
|
Assert.eq(got[1].id, 1)
|
||||||
|
Assert.eq(got[2].id, 3)
|
||||||
|
|
||||||
|
calls = {}
|
||||||
|
Annotation.listByChapter(clientReturning(chapter), 12763, "5", function(list) got = list end)
|
||||||
|
Assert.eq(#got, 2, "字符串 owner_id 也能对上数字 ownerUserId")
|
||||||
|
|
||||||
|
Annotation.listByChapter(clientReturning(nil, "请求失败 (HTTP 400)"), 12763, 5, function(list, err)
|
||||||
|
got, got_err = list, err
|
||||||
|
end)
|
||||||
|
Assert.is_nil(got, "失败回 nil")
|
||||||
|
Assert.eq(got_err, "请求失败 (HTTP 400)")
|
||||||
|
|
||||||
|
Annotation.listByChapter(clientReturning({}), 12763, 5, function(list) got = list end)
|
||||||
|
Assert.eq(#got, 0, "该章没有注解 = 空列表,不是 nil")
|
||||||
@@ -0,0 +1,859 @@
|
|||||||
|
--[[--
|
||||||
|
book.koplugin/source/kavita/cache.lua:kamare 缓存适配层。
|
||||||
|
|
||||||
|
kamare 的 `kamarecache` 是唯一的缓存执行者。这里只做探测、能力门面、配置镜像、
|
||||||
|
错误文案、书架投影与删除保护,所有 kamare 模块都在函数内 pcall require、不持有 table。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.cache_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
|
||||||
|
local PLUGIN = (debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita")
|
||||||
|
|
||||||
|
-- 源配置:每个用例自己改;cache 只读 base_url / api_key。
|
||||||
|
local cfg = {}
|
||||||
|
package.preload["utils.settings"] = function()
|
||||||
|
return {
|
||||||
|
getSource = function() return cfg end,
|
||||||
|
saveSource = function() end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 日志:记录每一行,供「一次性 / 不刷屏」断言。
|
||||||
|
local logs = {}
|
||||||
|
package.preload["utils.log"] = function()
|
||||||
|
local function push(level, ...)
|
||||||
|
local parts = {}
|
||||||
|
for index = 1, select("#", ...) do
|
||||||
|
parts[#parts + 1] = tostring(select(index, ...))
|
||||||
|
end
|
||||||
|
logs[#logs + 1] = { level = level, text = table.concat(parts, " ") }
|
||||||
|
end
|
||||||
|
return {
|
||||||
|
dbg = function(...) push("dbg", ...) end,
|
||||||
|
info = function(...) push("info", ...) end,
|
||||||
|
warn = function(...) push("warn", ...) end,
|
||||||
|
error = function(...) push("error", ...) end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
package.preload["moonsource_kavita.cache"] = function()
|
||||||
|
return dofile(PLUGIN .. "/cache.lua")
|
||||||
|
end
|
||||||
|
local Cache = require("moonsource_kavita.cache")
|
||||||
|
|
||||||
|
--- 清空 kamare 模块,模拟未安装。
|
||||||
|
local function uninstall()
|
||||||
|
package.loaded["kamarecache"] = nil
|
||||||
|
package.preload["kamarecache"] = nil
|
||||||
|
package.loaded["kamareimageviewer"] = nil
|
||||||
|
package.preload["kamareimageviewer"] = nil
|
||||||
|
package.loaded["kamareversion"] = nil
|
||||||
|
package.preload["kamareversion"] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 装一个 kamarecache 桩;status 用 loadstring 造出可预测的模块路径。
|
||||||
|
---@param spec table { api_version, capabilities, version, path, viewer }
|
||||||
|
---@return table
|
||||||
|
local function installCache(spec)
|
||||||
|
package.loaded["kamareimageviewer"] = spec.viewer
|
||||||
|
local mod = {
|
||||||
|
api_version = spec.api_version,
|
||||||
|
capabilities = spec.capabilities or {},
|
||||||
|
}
|
||||||
|
if spec.path then
|
||||||
|
mod.status = assert(loadstring("return function() end", "@" .. spec.path))()
|
||||||
|
end
|
||||||
|
package.loaded["kamarecache"] = mod
|
||||||
|
if spec.version then
|
||||||
|
package.loaded["kamareversion"] = spec.version
|
||||||
|
end
|
||||||
|
Cache.reset()
|
||||||
|
return mod
|
||||||
|
end
|
||||||
|
|
||||||
|
local function resetLogs()
|
||||||
|
logs = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function logText()
|
||||||
|
local parts = {}
|
||||||
|
for _idx, line in ipairs(logs) do parts[#parts + 1] = line.text end
|
||||||
|
return table.concat(parts, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 含某段文字的行数(一次性 / 不刷屏断言用)。
|
||||||
|
---@param fragment string
|
||||||
|
---@return integer
|
||||||
|
local function countLines(fragment)
|
||||||
|
local count = 0
|
||||||
|
for _idx, line in ipairs(logs) do
|
||||||
|
if line.text:find(fragment, 1, true) then count = count + 1 end
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 探测:四安装态、版本、加载路径;成功记忆、失败不记忆。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
uninstall()
|
||||||
|
Cache.reset()
|
||||||
|
local probe = Cache.probe()
|
||||||
|
Assert.is_false(probe.ok, "没有 kamarecache 不可用")
|
||||||
|
Assert.eq(probe.state, "missing", "未安装 / 已安装但被禁用")
|
||||||
|
Assert.eq(probe.reason, "missing")
|
||||||
|
Assert.eq(Cache.available("open"), false, "未安装时没有任何缓存能力")
|
||||||
|
|
||||||
|
uninstall()
|
||||||
|
package.loaded["kamareimageviewer"] = { new = function() end }
|
||||||
|
Cache.reset()
|
||||||
|
probe = Cache.probe()
|
||||||
|
Assert.is_false(probe.ok, "官方版没有缓存接口")
|
||||||
|
Assert.eq(probe.state, "official", "有查看器但无 kamarecache")
|
||||||
|
|
||||||
|
installCache({ api_version = 2, capabilities = { status = true, open = true } })
|
||||||
|
probe = Cache.probe()
|
||||||
|
Assert.is_false(probe.ok, "主版本不符整体禁用")
|
||||||
|
Assert.eq(probe.state, "incompatible")
|
||||||
|
Assert.eq(probe.api_version, 2)
|
||||||
|
Assert.eq(probe.reason, "major_mismatch")
|
||||||
|
Assert.eq(Cache.available("status"), false, "主版本不符整体禁用缓存")
|
||||||
|
Assert.eq(Cache.available("open"), false, "没有查看器可退回时 open 也不可用")
|
||||||
|
|
||||||
|
local fake_path = "/fake/plugins/kamare.koplugin/src/kamarecache.lua"
|
||||||
|
installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { status = true, open = true },
|
||||||
|
version = "0.10.0-dev",
|
||||||
|
path = fake_path,
|
||||||
|
})
|
||||||
|
probe = Cache.probe()
|
||||||
|
Assert.is_true(probe.ok)
|
||||||
|
Assert.eq(probe.state, "enhanced")
|
||||||
|
Assert.eq(probe.api_version, 1)
|
||||||
|
Assert.eq(probe.version, "0.10.0-dev", "kamareversion 返回字符串")
|
||||||
|
Assert.eq(probe.path, fake_path, "加载路径取自 debug.getinfo(module.status)")
|
||||||
|
|
||||||
|
-- data 目录里的插件路径是 `plugins//x.koplugin`(KOReader 的 extra_plugin_paths 带尾斜杠):
|
||||||
|
-- 展示前归一,否则用户会以为路径坏了。
|
||||||
|
installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { status = true, open = true },
|
||||||
|
version = "0.10.0-dev",
|
||||||
|
path = "/fake/plugins//kamare.koplugin/kamarecache.lua",
|
||||||
|
})
|
||||||
|
Assert.eq(Cache.probe().path, "/fake/plugins/kamare.koplugin/kamarecache.lua", "重复斜杠归一")
|
||||||
|
Assert.eq(probe.capabilities.status, true)
|
||||||
|
Assert.eq(Cache.available("status"), true)
|
||||||
|
Assert.eq(Cache.available("index"), false, "能力逐项判断")
|
||||||
|
|
||||||
|
-- 成功结果进程内记忆:模块从 package 里消失后仍按上次结果
|
||||||
|
package.loaded["kamarecache"] = nil
|
||||||
|
Assert.eq(Cache.probe().state, "enhanced", "成功结果记住,不重复 require")
|
||||||
|
Assert.eq(Cache.reprobe().state, "missing", "「重新检测」清掉成功记忆")
|
||||||
|
Cache.reset()
|
||||||
|
Assert.eq(Cache.probe().state, "missing", "reset 后重新探测")
|
||||||
|
|
||||||
|
-- 失败不记忆:装上模块后立刻能看到增强版
|
||||||
|
Assert.eq(Cache.probe().state, "missing")
|
||||||
|
installCache({ api_version = 1, capabilities = {} })
|
||||||
|
Assert.eq(Cache.probe().state, "enhanced", "失败结果不缓存")
|
||||||
|
|
||||||
|
-- kamareversion 用表形状也认(老写法)
|
||||||
|
package.loaded["kamareversion"] = { version = "0.9.9" }
|
||||||
|
Cache.reset()
|
||||||
|
Assert.eq(Cache.probe().version, "0.9.9")
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 功能清单:kamarefeatures.lua 原样展示;缺文件 / 版本不符 / 结构不合法都不显示。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
local function withManifest(value)
|
||||||
|
package.loaded["kamarefeatures"] = value
|
||||||
|
Cache.reset()
|
||||||
|
return Cache.featureText()
|
||||||
|
end
|
||||||
|
|
||||||
|
uninstall()
|
||||||
|
installCache({ api_version = 1, capabilities = { open = true }, path = fake_path })
|
||||||
|
Assert.eq(withManifest({ api_version = 1, features = { "缓存", "双页", "裁切" } }),
|
||||||
|
"缓存 · 双页 · 裁切", "按清单顺序拼接")
|
||||||
|
Assert.eq(withManifest({ api_version = 1, features = { "缓存", "缓存", "", 42, "裁切" } }),
|
||||||
|
"缓存 · 裁切", "去重并忽略空串 / 非字符串")
|
||||||
|
Assert.is_nil(withManifest({ api_version = 2, features = { "缓存" } }), "api_version 不符")
|
||||||
|
Assert.is_nil(withManifest({ api_version = 1, features = {} }), "空清单")
|
||||||
|
Assert.is_nil(withManifest({ api_version = 1, features = "缓存" }), "不是数组")
|
||||||
|
Assert.is_nil(withManifest({ api_version = 1 }), "没有 features")
|
||||||
|
Assert.is_nil(withManifest("not a table"), "不是表")
|
||||||
|
package.loaded["kamarefeatures"] = nil
|
||||||
|
Cache.reset()
|
||||||
|
Assert.is_nil(Cache.featureText(), "没有清单不显示")
|
||||||
|
|
||||||
|
-- 最多 8 项
|
||||||
|
local many = {}
|
||||||
|
for i = 1, 10 do many[i] = "功能" .. i end
|
||||||
|
local text = withManifest({ api_version = 1, features = many })
|
||||||
|
Assert.not_nil(text:find("功能8", 1, true), "保留前 8 项")
|
||||||
|
Assert.is_nil(text:find("功能9", 1, true), "超出 8 项截断")
|
||||||
|
|
||||||
|
-- 未安装 kamare 时,即使有清单也不显示。
|
||||||
|
package.loaded["kamarefeatures"] = { api_version = 1, features = { "缓存" } }
|
||||||
|
uninstall()
|
||||||
|
Cache.reset()
|
||||||
|
Assert.is_nil(Cache.featureText(), "非增强版不显示")
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 门面:每个能力一个显式包装,参数只从配置补 base_url;缺能力则 unsupported。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
cfg = { base_url = "http://kav/", api_key = " k " }
|
||||||
|
|
||||||
|
local calls = {}
|
||||||
|
local function record(name, impl)
|
||||||
|
return function(...)
|
||||||
|
calls[#calls + 1] = { name = name, args = { ... } }
|
||||||
|
if impl then return impl(...) end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function lastCall(name)
|
||||||
|
for index = #calls, 1, -1 do
|
||||||
|
if calls[index].name == name then return calls[index] end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local index_result = { used = 1, available = 2, series = { ["60"] = { seriesId = 60 } } }
|
||||||
|
local mod = installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = {
|
||||||
|
status = true, summary = true, resume = true, queue = true,
|
||||||
|
index = true, enqueue = true, delete = true, estimate = true,
|
||||||
|
queue_control = true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
mod.index = record("index", function() return index_result end)
|
||||||
|
mod.status = record("status", function() return { state = "complete" } end)
|
||||||
|
mod.resume_page = record("resume_page", function() return { page = 7 } end)
|
||||||
|
mod.summary = record("summary", function() return { used = 10, available = 20, chapters = 3 } end)
|
||||||
|
mod.queue_state = record("queue_state", function() return { state = "idle" } end)
|
||||||
|
mod.enqueue = record("enqueue", function() return true, nil, { chapters = 1 } end)
|
||||||
|
mod.delete = record("delete", function() return true, nil, 1 end)
|
||||||
|
mod.estimate = record("estimate", function() return { ok = true, chapters = 1, bytes = 1, available = 2 } end)
|
||||||
|
|
||||||
|
Assert.eq(Cache.index(), index_result)
|
||||||
|
Assert.eq(lastCall("index").args[1], "http://kav", "base_url 去尾斜杠;不传 api_key")
|
||||||
|
|
||||||
|
Assert.eq(Cache.status(6001).state, "complete")
|
||||||
|
Assert.eq(lastCall("status").args[1], "http://kav")
|
||||||
|
Assert.eq(lastCall("status").args[2], 6001)
|
||||||
|
|
||||||
|
Assert.eq(Cache.resumePage(6001, 60).page, 7)
|
||||||
|
Assert.eq(lastCall("resume_page").args[1], "http://kav")
|
||||||
|
Assert.eq(lastCall("resume_page").args[2], 6001)
|
||||||
|
Assert.eq(lastCall("resume_page").args[3], 60)
|
||||||
|
|
||||||
|
Assert.eq(Cache.summary().chapters, 3)
|
||||||
|
Assert.eq(lastCall("summary").args[1], "http://kav")
|
||||||
|
|
||||||
|
Assert.eq(Cache.queueState().state, "idle")
|
||||||
|
Assert.eq(lastCall("queue_state").args[1], "http://kav")
|
||||||
|
|
||||||
|
local ok, code, info = Cache.enqueue({ { chapterId = 6001 } })
|
||||||
|
Assert.is_true(ok)
|
||||||
|
Assert.is_nil(code)
|
||||||
|
Assert.eq(info.chapters, 1, "成功时第三个返回值原样透出")
|
||||||
|
Assert.eq(lastCall("enqueue").args[1], "http://kav")
|
||||||
|
Assert.eq(lastCall("enqueue").args[2][1].chapterId, 6001)
|
||||||
|
|
||||||
|
local deleted_ok, deleted_code, deleted = Cache.delete({ 6001 })
|
||||||
|
Assert.is_true(deleted_ok)
|
||||||
|
Assert.is_nil(deleted_code)
|
||||||
|
Assert.eq(deleted, 1)
|
||||||
|
Assert.eq(lastCall("delete").args[1], "http://kav")
|
||||||
|
Assert.eq(lastCall("delete").args[2][1], 6001)
|
||||||
|
|
||||||
|
Assert.is_true(Cache.estimate({ { chapterId = 6001 } }).ok)
|
||||||
|
Assert.eq(lastCall("estimate").args[1], "http://kav")
|
||||||
|
Assert.eq(lastCall("estimate").args[2][1].chapterId, 6001)
|
||||||
|
|
||||||
|
-- 队列控制:三个显式包装,全部作用在全局队列上。
|
||||||
|
mod.queue_pause = record("queue_pause")
|
||||||
|
mod.queue_resume = record("queue_resume")
|
||||||
|
mod.queue_retry = record("queue_retry")
|
||||||
|
Assert.is_true(Cache.queuePause())
|
||||||
|
Assert.is_true(Cache.queueResume())
|
||||||
|
Assert.is_true(Cache.queueRetry({ 6001, 6002 }))
|
||||||
|
Assert.eq(lastCall("queue_pause").args[1], "http://kav")
|
||||||
|
Assert.eq(lastCall("queue_resume").args[1], "http://kav")
|
||||||
|
Assert.eq(lastCall("queue_retry").args[1], "http://kav")
|
||||||
|
Assert.eq(lastCall("queue_retry").args[2][2], 6002)
|
||||||
|
|
||||||
|
-- 缺能力:对应功能单独降级,kamare 的函数不会被调用。
|
||||||
|
calls = {}
|
||||||
|
installCache({ api_version = 1, capabilities = { status = true } })
|
||||||
|
local value, code = Cache.status(1)
|
||||||
|
Assert.eq(code, "unsupported", "能力声明了但没有函数也按缺失处理")
|
||||||
|
value, code = Cache.index()
|
||||||
|
Assert.is_nil(value, "缺 index 返回 nil")
|
||||||
|
Assert.eq(code, "unsupported")
|
||||||
|
value, code = Cache.summary()
|
||||||
|
Assert.is_nil(value)
|
||||||
|
Assert.eq(code, "unsupported")
|
||||||
|
Assert.eq(select(2, Cache.queueState()), "unsupported")
|
||||||
|
Assert.eq(select(2, Cache.queueState()), "unsupported")
|
||||||
|
Assert.eq(select(2, Cache.queuePause()), "unsupported")
|
||||||
|
Assert.eq(select(2, Cache.enqueue({ { chapterId = 1 } })), "unsupported")
|
||||||
|
Assert.eq(select(2, Cache.delete({ 1 })), "unsupported")
|
||||||
|
Assert.eq(select(2, Cache.estimate({ { chapterId = 1 } })), "unsupported")
|
||||||
|
|
||||||
|
-- 未配置服务器:静默 unknown_server,不碰 kamare。
|
||||||
|
cfg = { base_url = "", api_key = "" }
|
||||||
|
calls = {}
|
||||||
|
Assert.eq(select(2, Cache.index()), "unknown_server")
|
||||||
|
Assert.eq(select(2, Cache.enqueue({ { chapterId = 1 } })), "unknown_server")
|
||||||
|
Assert.len(calls, 0, "未配置时不发任何调用")
|
||||||
|
|
||||||
|
-- kamare 的错误码原样透出,文案交给 message 表。
|
||||||
|
cfg = { base_url = "http://kav/", api_key = "k" }
|
||||||
|
installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { index = true, enqueue = true },
|
||||||
|
})
|
||||||
|
mod = package.loaded["kamarecache"]
|
||||||
|
mod.index = function() return nil, "unknown_server" end
|
||||||
|
mod.enqueue = function() return nil, "not_enough_space", "空间不足", { needed = 3, available = 1 } end
|
||||||
|
local read, read_code = Cache.index()
|
||||||
|
Assert.is_nil(read)
|
||||||
|
Assert.eq(read_code, "unknown_server")
|
||||||
|
local written, write_code, write_message, write_detail = Cache.enqueue({ { chapterId = 1 } })
|
||||||
|
Assert.is_nil(written)
|
||||||
|
Assert.eq(write_code, "not_enough_space")
|
||||||
|
Assert.eq(write_message, "空间不足")
|
||||||
|
Assert.eq(write_detail.available, 1)
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 配置镜像:首次缓存操作前 + 每次写操作前;只传 base_url + api_key,不传 name。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
cfg = { base_url = "http://kav/", api_key = " k " }
|
||||||
|
calls = {}
|
||||||
|
resetLogs()
|
||||||
|
local mirror_mod = installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { server = true, index = true, status = true, enqueue = true,
|
||||||
|
delete = true, queue_control = true, estimate = true },
|
||||||
|
})
|
||||||
|
mirror_mod.register_server = record("register_server", function() return "srv-1" end)
|
||||||
|
mirror_mod.index = record("index", function() return { series = {} } end)
|
||||||
|
mirror_mod.status = record("status")
|
||||||
|
mirror_mod.enqueue = record("enqueue", function() return true end)
|
||||||
|
mirror_mod.delete = record("delete", function() return true, nil, 1 end)
|
||||||
|
mirror_mod.queue_pause = record("queue_pause")
|
||||||
|
mirror_mod.queue_resume = record("queue_resume")
|
||||||
|
mirror_mod.queue_retry = record("queue_retry")
|
||||||
|
mirror_mod.estimate = record("estimate", function() return { ok = true } end)
|
||||||
|
|
||||||
|
local function callCount(name)
|
||||||
|
local n = 0
|
||||||
|
for _idx, call in ipairs(calls) do
|
||||||
|
if call.name == name then n = n + 1 end
|
||||||
|
end
|
||||||
|
return n
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 某次调用在 calls 里的位置(从 1 起;没有为 0)
|
||||||
|
local function callIndex(name)
|
||||||
|
for index, call in ipairs(calls) do
|
||||||
|
if call.name == name then return index end
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
Cache.index()
|
||||||
|
Assert.eq(callCount("register_server"), 1, "首次缓存操作前镜像一次")
|
||||||
|
local registered = lastCall("register_server").args[1]
|
||||||
|
Assert.eq(registered.base_url, "http://kav", "URL 规范化:去尾斜杠")
|
||||||
|
Assert.eq(registered.api_key, "k", "API Key 去空白")
|
||||||
|
Assert.is_nil(registered.name, "不传固定显示名(否则两台服务器会共用一个缓存目录)")
|
||||||
|
|
||||||
|
Cache.status(1)
|
||||||
|
Assert.eq(callCount("register_server"), 1, "读操作不重复镜像")
|
||||||
|
|
||||||
|
Cache.enqueue({ { chapterId = 1 } })
|
||||||
|
Assert.eq(callCount("register_server"), 2, "每次写操作前幂等兜底")
|
||||||
|
Assert.is_true(callIndex("register_server") < callIndex("enqueue"), "镜像先于写入")
|
||||||
|
|
||||||
|
Cache.delete({ 1 })
|
||||||
|
Cache.queuePause()
|
||||||
|
Cache.queueResume()
|
||||||
|
Cache.queueRetry({ 1 })
|
||||||
|
Cache.estimate({ { chapterId = 1 } })
|
||||||
|
Assert.eq(callCount("register_server"), 6, "delete / queue_* / 估计写盘前路径都镜像")
|
||||||
|
|
||||||
|
-- 显式调用:设置页保存后走这一个入口。
|
||||||
|
local server_key, mirror_code = Cache.registerServer("http://kav/", " k ")
|
||||||
|
Assert.eq(server_key, "srv-1")
|
||||||
|
Assert.is_nil(mirror_code)
|
||||||
|
Assert.eq(callCount("register_server"), 7)
|
||||||
|
|
||||||
|
-- 失败:后台只记一次日志,功能照常交给 kamare(按 unknown_server 静默降级)。
|
||||||
|
mirror_mod.register_server = record("register_server", function() return nil, "settings_write_failed" end)
|
||||||
|
local before = callCount("register_server")
|
||||||
|
Cache.enqueue({ { chapterId = 2 } })
|
||||||
|
Assert.eq(callCount("register_server"), before + 1)
|
||||||
|
Assert.eq(callCount("enqueue"), 2, "镜像失败不阻断写操作,最终以 kamare 为准")
|
||||||
|
Assert.is_true(Cache.mirrorFailed(), "本次会话镜像失败")
|
||||||
|
Assert.matches(logText(), "settings_write_failed", "失败记一行")
|
||||||
|
local mirror_lines = 0
|
||||||
|
for _idx, line in ipairs(logs) do
|
||||||
|
if line.text:find("mirror", 1, true) then mirror_lines = mirror_lines + 1 end
|
||||||
|
end
|
||||||
|
Assert.eq(mirror_lines, 1, "同一原因只记一次")
|
||||||
|
Cache.enqueue({ { chapterId = 3 } })
|
||||||
|
mirror_lines = 0
|
||||||
|
for _idx, line in ipairs(logs) do
|
||||||
|
if line.text:find("mirror", 1, true) then mirror_lines = mirror_lines + 1 end
|
||||||
|
end
|
||||||
|
Assert.eq(mirror_lines, 1, "重复失败不刷屏")
|
||||||
|
|
||||||
|
mirror_mod.register_server = record("register_server", function() return "srv-1" end)
|
||||||
|
Cache.enqueue({ { chapterId = 4 } })
|
||||||
|
Assert.is_false(Cache.mirrorFailed(), "成功后清除失败态")
|
||||||
|
|
||||||
|
-- 未配置 / 未安装时不假装镜像。
|
||||||
|
cfg = { base_url = "", api_key = "" }
|
||||||
|
calls = {}
|
||||||
|
Cache.index()
|
||||||
|
Assert.len(calls, 0, "未配置不发镜像")
|
||||||
|
|
||||||
|
cfg = { base_url = "http://kav/", api_key = "k" }
|
||||||
|
uninstall()
|
||||||
|
Cache.reset()
|
||||||
|
calls = {}
|
||||||
|
Cache.available("index")
|
||||||
|
Assert.len(calls, 0, "未安装不发镜像")
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 文案:02 A9 的 code 表 + 07 A7 的 lastError 特征。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
local CODE_CASES = {
|
||||||
|
{ "offline_not_cached", "这一卷还没缓存,联网后可下载" },
|
||||||
|
{ "viewer_running", "漫画阅读器已在运行" },
|
||||||
|
{ "no_pages", "这一卷没有可显示的页面" },
|
||||||
|
{ "settings_write_failed", "无法写入 kamare 配置" },
|
||||||
|
{ "retry_no_entry", "没有可重试的任务" },
|
||||||
|
{ "chapter_open", "正在阅读这一卷,关闭后可以删除" },
|
||||||
|
}
|
||||||
|
for _idx, case in ipairs(CODE_CASES) do
|
||||||
|
Assert.eq(Cache.message(case[1]), case[2], "code → 文案: " .. case[1])
|
||||||
|
end
|
||||||
|
-- 静默:已是目标状态 / 未知服务器都当无缓存,不打扰用户。
|
||||||
|
Assert.is_nil(Cache.message("unknown_server"), "unknown_server 静默")
|
||||||
|
Assert.is_nil(Cache.message("already_cached"), "已缓存静默")
|
||||||
|
Assert.is_nil(Cache.message("already_queued"), "已排队静默")
|
||||||
|
Assert.is_nil(Cache.message(nil), "没有 code 没有说话")
|
||||||
|
-- 未知 code:kamare 的 message 优先,再退通用文案。
|
||||||
|
Assert.eq(Cache.message("weird_code", "kamare 的原话"), "kamare 的原话")
|
||||||
|
Assert.eq(Cache.message("weird_code"), "缓存操作失败")
|
||||||
|
|
||||||
|
local MB = 1024 * 1024
|
||||||
|
Assert.eq(Cache.sizeText(3 * MB), "3.0 MB")
|
||||||
|
Assert.eq(Cache.message("not_enough_space", nil, { needed = 3 * MB, available = MB }),
|
||||||
|
"空间不足:需要 3.0 MB,可用 1.0 MB")
|
||||||
|
Assert.eq(Cache.message("cache_limit_reached", nil, { needed = 2 * MB, limit = 9 * MB }),
|
||||||
|
"缓存空间已满:需要 2.0 MB,上限 9.0 MB")
|
||||||
|
Assert.eq(Cache.message("low_space", nil, { available = MB, low_water = 500 * MB }),
|
||||||
|
"可用空间低于 500.0 MB,清理后再下载")
|
||||||
|
|
||||||
|
-- estimate 的三种裁决:确认框就地换文案,不复制 kamare 的 2.05 / 500MB 常量。
|
||||||
|
Assert.eq(Cache.estimateMessage({ reason = "nothing_to_do" }), "全部已缓存或正在下载")
|
||||||
|
Assert.eq(Cache.estimateMessage({ reason = "space", bytes = 3 * MB, available = MB }),
|
||||||
|
"空间不足:需要 3.0 MB,可用 1.0 MB")
|
||||||
|
Assert.eq(Cache.estimateMessage({ reason = "low_water", available = MB }),
|
||||||
|
"可用空间不足(剩余 1.0 MB),清理后再下载")
|
||||||
|
Assert.is_nil(Cache.estimateMessage({ ok = true, reason = nil }), "可下载时没有额外文案")
|
||||||
|
Assert.is_nil(Cache.estimateMessage(nil))
|
||||||
|
|
||||||
|
-- 失败原因(07 A7):按 kamare 的 lastError 特征归并成可读文案。
|
||||||
|
local FAILED = {
|
||||||
|
{ "http 403 while fetching page 3", "服务器拒绝下载(403),检查 API Key / 权限" },
|
||||||
|
{ "not an archive: text/html", "下载内容不完整或不是有效压缩包" },
|
||||||
|
{ "size 120/900", "下载内容不完整或不是有效压缩包" },
|
||||||
|
{ "extracted 3 of 5 pages", "下载内容不完整或不是有效压缩包" },
|
||||||
|
{ "sink write failed: no space left on device", "存储空间不足或写入失败" },
|
||||||
|
{ "socket closed", "网络中断或服务器不可达" },
|
||||||
|
{ "connect timeout", "网络中断或服务器不可达" },
|
||||||
|
{ "connection truncated", "网络中断或服务器不可达" },
|
||||||
|
}
|
||||||
|
for _idx, case in ipairs(FAILED) do
|
||||||
|
Assert.eq(Cache.failureText(case[1]), case[2], "lastError → 文案: " .. case[1])
|
||||||
|
end
|
||||||
|
Assert.eq(Cache.failureText("weird failure"), "缓存失败:weird failure", "未知错误前缀保留原话")
|
||||||
|
Assert.is_nil(Cache.failureText(nil))
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 打开:enhanced 有 open 走 kamare;官方 / 缺 open 退回 legacy;记录当前打开的章。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
cfg = { base_url = "http://kav/", api_key = "k" }
|
||||||
|
calls = {}
|
||||||
|
local opened = installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { open = true, delete = true, server = true },
|
||||||
|
})
|
||||||
|
opened.register_server = record("register_server", function() return "srv-1" end)
|
||||||
|
local closed = {}
|
||||||
|
local nexts = {}
|
||||||
|
local fake_viewer = { kind = "viewer" }
|
||||||
|
opened.open = record("open", function() return fake_viewer end)
|
||||||
|
Assert.is_true(Cache.enhancedOpen(), "增强版有 open:由 kamare 决定起始页 / 离线")
|
||||||
|
local open_result, open_code = Cache.open({
|
||||||
|
base_url = "http://kav/", api_key = "k",
|
||||||
|
entry = { chapterId = 6001, pages = 20 }, title = "漫画",
|
||||||
|
on_close = function(page, total) closed[#closed + 1] = { page, total } end,
|
||||||
|
on_next = function(id) nexts[#nexts + 1] = id end,
|
||||||
|
})
|
||||||
|
Assert.eq(open_result, fake_viewer)
|
||||||
|
Assert.is_nil(open_code)
|
||||||
|
local open_opts = lastCall("open").args[1]
|
||||||
|
Assert.eq(open_opts.entry.chapterId, 6001, "目录条目原样交给 kamare")
|
||||||
|
Assert.eq(open_opts.title, "漫画")
|
||||||
|
Assert.not_nil(open_opts.on_next)
|
||||||
|
Assert.is_true(Cache.isChapterOpen(6001), "打开成功记下当前章")
|
||||||
|
Assert.is_false(Cache.isChapterOpen(6002))
|
||||||
|
|
||||||
|
open_opts.on_close(7, 20)
|
||||||
|
Assert.eq(closed[1][1], 7, "关闭回调原样透出")
|
||||||
|
Assert.eq(closed[1][2], 20)
|
||||||
|
Assert.is_false(Cache.isChapterOpen(6001), "关闭后清除当前章")
|
||||||
|
|
||||||
|
-- 打开失败不留 active。
|
||||||
|
opened.open = function() return nil, "viewer_running", "漫画阅读器已在运行" end
|
||||||
|
local failed, failed_code, failed_message = Cache.open({
|
||||||
|
base_url = "http://kav/", api_key = "k", entry = { chapterId = 6003, pages = 4 },
|
||||||
|
})
|
||||||
|
Assert.is_nil(failed)
|
||||||
|
Assert.eq(failed_code, "viewer_running")
|
||||||
|
Assert.eq(failed_message, "漫画阅读器已在运行")
|
||||||
|
Assert.is_false(Cache.isChapterOpen(6003))
|
||||||
|
|
||||||
|
-- 删除保护:本地先拦,kamare 的 delete 根本不会被调用。
|
||||||
|
calls = {}
|
||||||
|
local deleted_viewer = installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { open = true, delete = true },
|
||||||
|
})
|
||||||
|
deleted_viewer.open = record("open", function() return { kind = "viewer" } end)
|
||||||
|
deleted_viewer.delete = record("delete", function() return true, nil, 1 end)
|
||||||
|
Cache.open({ base_url = "http://kav/", api_key = "k", entry = { chapterId = 6001, pages = 20 } })
|
||||||
|
local del_ok, del_code = Cache.delete({ 6001 })
|
||||||
|
Assert.is_nil(del_ok)
|
||||||
|
Assert.eq(del_code, "chapter_open", "正在读的章拒绝删除")
|
||||||
|
Assert.eq(Cache.message(del_code), "正在阅读这一卷,关闭后可以删除")
|
||||||
|
Assert.eq(callCount("delete"), 0, "kamare 的 delete 不被调用")
|
||||||
|
|
||||||
|
Assert.is_true(Cache.delete({ 6002 }), "别的章照删")
|
||||||
|
Assert.eq(lastCall("delete").args[2][1], 6002)
|
||||||
|
|
||||||
|
-- 关掉查看器后可以删。
|
||||||
|
lastCall("open").args[1].on_close(1, 20)
|
||||||
|
Assert.is_true(Cache.delete({ 6001 }))
|
||||||
|
|
||||||
|
-- 官方版 / enhanced 缺 open:退回 legacy 通道(今天的在线看图能力不能丢)。
|
||||||
|
uninstall()
|
||||||
|
package.loaded["kamareimageviewer"] = { new = function(_self, spec) return spec end }
|
||||||
|
local streamed = {}
|
||||||
|
package.loaded["kavitaclient"] = {
|
||||||
|
streamChapter = function(_self, id) streamed[#streamed + 1] = id; return { { pageNumber = 1 } } end,
|
||||||
|
}
|
||||||
|
local shown = {}
|
||||||
|
package.loaded["ui/uimanager"] = { show = function(_, widget) shown[#shown + 1] = widget end }
|
||||||
|
Cache.reset()
|
||||||
|
Assert.is_true(Cache.available("open"), "官方版仍能在线看图")
|
||||||
|
Assert.is_false(Cache.enhancedOpen(), "官方版不接管 open:起始页由 moon 补")
|
||||||
|
local legacy_viewer, legacy_code = Cache.open({
|
||||||
|
base_url = "http://kav/", api_key = "k", entry = { chapterId = 6001, pages = 20 }, title = "漫画",
|
||||||
|
start_page = 3, on_close = function() end, on_next = function() end,
|
||||||
|
})
|
||||||
|
Assert.is_nil(legacy_code)
|
||||||
|
Assert.eq(legacy_viewer.metadata.chapterId, 6001)
|
||||||
|
Assert.eq(legacy_viewer.metadata.startPage, 3)
|
||||||
|
Assert.eq(legacy_viewer.images_list_nb, 20)
|
||||||
|
Assert.eq(legacy_viewer.title, "漫画")
|
||||||
|
Assert.eq(require("kavitaclient").api_key, "k")
|
||||||
|
Assert.eq(require("kavitaclient").device_id, "moon-kavita")
|
||||||
|
Assert.eq(streamed[1], 6001)
|
||||||
|
Assert.eq(shown[1], legacy_viewer, "交给 UIManager 显示")
|
||||||
|
Assert.is_true(Cache.isChapterOpen(6001), "legacy 也记当前章")
|
||||||
|
|
||||||
|
-- enhanced 但缺 open 能力:同样退回 legacy。
|
||||||
|
installCache({ api_version = 1, capabilities = { status = true } })
|
||||||
|
Assert.is_false(Cache.enhancedOpen(), "增强版缺 open:退回 legacy,由 moon 给起始页")
|
||||||
|
package.loaded["kamareimageviewer"] = { new = function(_self, spec) return spec end }
|
||||||
|
package.loaded["kavitaclient"] = { streamChapter = function() return { { pageNumber = 1 } } end }
|
||||||
|
Cache.reset()
|
||||||
|
local fallback = Cache.open({
|
||||||
|
base_url = "http://kav/", api_key = "k", entry = { chapterId = 6004, pages = 4 },
|
||||||
|
})
|
||||||
|
Assert.not_nil(fallback, "增强版缺 open 时退回查看器")
|
||||||
|
Assert.eq(fallback.metadata.chapterId, 6004)
|
||||||
|
|
||||||
|
-- legacy 没有页面 / 查看器已被占用 / 串流失败:稳定 code。
|
||||||
|
Cache.reset()
|
||||||
|
local no_pages, no_pages_code = Cache.open({
|
||||||
|
base_url = "http://kav/", api_key = "k", entry = { chapterId = 6005, pages = 0 },
|
||||||
|
})
|
||||||
|
Assert.is_nil(no_pages)
|
||||||
|
Assert.eq(no_pages_code, "no_pages")
|
||||||
|
|
||||||
|
package.loaded["kamareimageviewer"] = { new = function(_self, spec) spec._aborted = true; return spec end }
|
||||||
|
local running, running_code = Cache.open({
|
||||||
|
base_url = "http://kav/", api_key = "k", entry = { chapterId = 6006, pages = 3 },
|
||||||
|
})
|
||||||
|
Assert.is_nil(running)
|
||||||
|
Assert.eq(running_code, "viewer_running")
|
||||||
|
|
||||||
|
package.loaded["kamareimageviewer"] = { new = function(_self, spec) return spec end }
|
||||||
|
package.loaded["kavitaclient"] = { streamChapter = function() return nil end }
|
||||||
|
local broken, broken_code, broken_message = Cache.open({
|
||||||
|
base_url = "http://kav/", api_key = "k", entry = { chapterId = 6007, pages = 3 },
|
||||||
|
})
|
||||||
|
Assert.is_nil(broken)
|
||||||
|
Assert.eq(broken_code, "open_failed")
|
||||||
|
Assert.eq(broken_message, "打开漫画阅读器失败")
|
||||||
|
|
||||||
|
-- 完全没有 kamare:不能假装能打开。
|
||||||
|
uninstall()
|
||||||
|
Cache.reset()
|
||||||
|
Assert.is_false(Cache.available("open"))
|
||||||
|
local none, none_code = Cache.open({ base_url = "http://kav/", api_key = "k", entry = { chapterId = 1, pages = 1 } })
|
||||||
|
Assert.is_nil(none)
|
||||||
|
Assert.eq(none_code, "unsupported")
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 书架投影:complete / stale 才算已缓存;三张表按服务器记忆,无 TTL。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
cfg = { base_url = "http://kav/", api_key = "k" }
|
||||||
|
local work = Config.dir() .. "/cache_spec"
|
||||||
|
os.execute("mkdir -p '" .. work .. "'")
|
||||||
|
local cover = work .. "/cover-60.jpg"
|
||||||
|
local cover_file = assert(io.open(cover, "wb"))
|
||||||
|
cover_file:write("jpeg")
|
||||||
|
cover_file:close()
|
||||||
|
|
||||||
|
calls = {}
|
||||||
|
local shelf_mod = installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { index = true, server = true, enqueue = true, delete = true, queue_control = true },
|
||||||
|
})
|
||||||
|
shelf_mod.register_server = record("register_server", function() return "srv" end)
|
||||||
|
local shelf_index = {
|
||||||
|
series = {
|
||||||
|
["60"] = { seriesId = 60, chapters = 2, complete = true, coverPath = cover },
|
||||||
|
["61"] = { seriesId = 61, chapters = 0, complete = true, coverPath = work .. "/missing.jpg" },
|
||||||
|
["62"] = { seriesId = 62, chapters = 1, stale = true },
|
||||||
|
["63"] = { seriesId = 63, chapters = 1 },
|
||||||
|
["64"] = { seriesId = 64, chapters = 3, stale = true, complete = false },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
shelf_mod.index = record("index", function() return shelf_index end)
|
||||||
|
shelf_mod.enqueue = record("enqueue", function() return true end)
|
||||||
|
shelf_mod.delete = record("delete", function() return true, nil, 1 end)
|
||||||
|
shelf_mod.queue_pause = record("queue_pause", function() return true end)
|
||||||
|
|
||||||
|
local shelf = Cache.shelf()
|
||||||
|
Assert.is_true(shelf.series_ids["60"], "complete 算已缓存")
|
||||||
|
Assert.is_true(shelf.mark["60"])
|
||||||
|
Assert.is_true(shelf.series_ids["62"], "stale 与 complete 等价")
|
||||||
|
Assert.is_true(shelf.series_ids["64"])
|
||||||
|
Assert.is_nil(shelf.series_ids["61"], "没有章不算(chapters = 0)")
|
||||||
|
Assert.is_nil(shelf.series_ids["63"], "queued / downloading 不算")
|
||||||
|
Assert.eq(shelf.cover["60"], cover, "封面路径存在才给")
|
||||||
|
Assert.is_nil(shelf.cover["61"], "文件不存在不给")
|
||||||
|
Assert.eq(callCount("index"), 1)
|
||||||
|
|
||||||
|
Cache.shelf()
|
||||||
|
Assert.eq(callCount("index"), 1, "进程内记忆,无 TTL、翻页不重拉")
|
||||||
|
|
||||||
|
-- 三类失效:写操作成功、手动刷新、Registry.reload(源实例重建时调 resetShelf)。
|
||||||
|
Cache.enqueue({ { chapterId = 6001 } })
|
||||||
|
Cache.shelf()
|
||||||
|
Assert.eq(callCount("index"), 2, "enqueue 成功后失效")
|
||||||
|
Cache.delete({ 6001 })
|
||||||
|
Cache.shelf()
|
||||||
|
Assert.eq(callCount("index"), 3, "delete 成功后失效")
|
||||||
|
Cache.queuePause()
|
||||||
|
Cache.shelf()
|
||||||
|
Assert.eq(callCount("index"), 4, "queue_* 成功后失效")
|
||||||
|
Cache.resetShelf()
|
||||||
|
Cache.shelf()
|
||||||
|
Assert.eq(callCount("index"), 5, "手动刷新 / Registry.reload")
|
||||||
|
|
||||||
|
-- 写失败不能误伤投影(失败时缓存没变)。
|
||||||
|
shelf_mod.enqueue = record("enqueue", function() return nil, "not_enough_space" end)
|
||||||
|
Cache.enqueue({ { chapterId = 6002 } })
|
||||||
|
Cache.shelf()
|
||||||
|
Assert.eq(callCount("index"), 5, "失败的写操作不失效")
|
||||||
|
|
||||||
|
-- 按服务器分开记忆:切回旧服务器不重拉。
|
||||||
|
cfg.base_url = "http://other/"
|
||||||
|
Cache.shelf()
|
||||||
|
Assert.eq(callCount("index"), 6)
|
||||||
|
Assert.eq(lastCall("index").args[1], "http://other")
|
||||||
|
cfg.base_url = "http://kav/"
|
||||||
|
Cache.shelf()
|
||||||
|
Assert.eq(callCount("index"), 6, "旧服务器的投影还在")
|
||||||
|
|
||||||
|
-- unknown_server 不记忆:下次进书架再试(可能刚镜像完)。
|
||||||
|
shelf_mod.index = record("index", function() return nil, "unknown_server" end)
|
||||||
|
cfg.base_url = "http://third/"
|
||||||
|
Assert.is_nil(Cache.shelf())
|
||||||
|
Assert.is_nil(Cache.shelf())
|
||||||
|
Assert.eq(callCount("index"), 8, "无缓存不写空投影")
|
||||||
|
|
||||||
|
-- 缺 index 能力:整块降级为无标记。
|
||||||
|
installCache({ api_version = 1, capabilities = { status = true } })
|
||||||
|
Assert.is_nil(Cache.shelf(), "缺 index 无书架标记")
|
||||||
|
|
||||||
|
-- 「已缓存」口径只在一处:章状态与 index 摘要两种形状都认(03 A3)。
|
||||||
|
Assert.is_true(Cache.isCached({ state = "complete" }))
|
||||||
|
Assert.is_true(Cache.isCached({ state = "stale" }))
|
||||||
|
Assert.is_false(Cache.isCached({ state = "partial" }))
|
||||||
|
Assert.is_false(Cache.isCached(nil))
|
||||||
|
Assert.is_true(Cache.isCached({ chapters = 1, complete = true }))
|
||||||
|
Assert.is_false(Cache.isCached({ chapters = 1 }))
|
||||||
|
|
||||||
|
-- 能力名单排序与拼接:设置页与日志共用同一份(08)。
|
||||||
|
Assert.eq(Cache.capabilityNames({ open = true, index = true }), "index,open")
|
||||||
|
Assert.eq(Cache.capabilityNames({ open = true, index = true }, "、"), "index、open")
|
||||||
|
Assert.eq(Cache.capabilityNames(nil), "none")
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 日志:探测每进程一次、写操作一行、open 失败去重、暂停原因只在变化时记。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
cfg = { base_url = "http://kav/", api_key = "secret-key" }
|
||||||
|
uninstall()
|
||||||
|
resetLogs()
|
||||||
|
Cache.reset()
|
||||||
|
Cache.probe()
|
||||||
|
Cache.probe()
|
||||||
|
Assert.eq(countLines("kamare probe"), 1, "探测结果每进程只记一次")
|
||||||
|
Assert.matches(logText(), "kamare probe ok=false state=missing")
|
||||||
|
Assert.is_nil(logText():find("secret-key", 1, true), "日志里绝不出现 API Key")
|
||||||
|
|
||||||
|
installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { status = true, index = true, enqueue = true, delete = true,
|
||||||
|
queue = true, queue_control = true, open = true },
|
||||||
|
version = "0.10.0",
|
||||||
|
path = "/fake/plugins/kamare.koplugin/kamarecache.lua",
|
||||||
|
})
|
||||||
|
resetLogs()
|
||||||
|
Cache.probe()
|
||||||
|
Cache.probe()
|
||||||
|
Assert.eq(countLines("kamare probe ok=true"), 1)
|
||||||
|
Assert.matches(logText(), "state=enhanced")
|
||||||
|
Assert.matches(logText(), "version=0.10.0")
|
||||||
|
Assert.matches(logText(), "caps=.*index")
|
||||||
|
Assert.is_nil(logText():find("secret-key", 1, true))
|
||||||
|
|
||||||
|
local log_mod = package.loaded["kamarecache"]
|
||||||
|
log_mod.status = function() return { state = "complete" } end
|
||||||
|
log_mod.index = function() return { series = {} } end
|
||||||
|
log_mod.enqueue = function() return nil, "not_enough_space", "空间不足", { needed = 9, available = 1 } end
|
||||||
|
resetLogs()
|
||||||
|
Cache.enqueue({ { chapterId = 6001 }, { chapterId = 6002 } })
|
||||||
|
Cache.enqueue({ { chapterId = 6003 } })
|
||||||
|
Assert.eq(countLines("cache enqueue cid=6001,6002 code=not_enough_space"), 1, "每次写操作一行,带 code 与章 id")
|
||||||
|
Assert.eq(countLines("cache enqueue cid=6003 code=not_enough_space"), 1, "另一次失败另记一行")
|
||||||
|
|
||||||
|
log_mod.delete = function() return true, nil, 1 end
|
||||||
|
resetLogs()
|
||||||
|
Cache.delete({ 6004 })
|
||||||
|
Assert.eq(countLines("cache delete cid=6004 code=ok"), 1)
|
||||||
|
|
||||||
|
log_mod.queue_pause = function() return true end
|
||||||
|
resetLogs()
|
||||||
|
Cache.queuePause()
|
||||||
|
Assert.eq(countLines("cache queue_pause cid=- code=ok"), 1, "队列动作没有章 id,记 -")
|
||||||
|
|
||||||
|
-- 轮询路径不刷日志,只在暂停原因变化时记一行。
|
||||||
|
log_mod.queue_state = function() return { state = "paused", pause_reason = "offline" } end
|
||||||
|
resetLogs()
|
||||||
|
Cache.queueState()
|
||||||
|
Cache.queueState()
|
||||||
|
Assert.eq(countLines("queue paused reason=offline"), 1, "1 秒轮询不重复记")
|
||||||
|
log_mod.queue_state = function() return { state = "idle" } end
|
||||||
|
Cache.queueState()
|
||||||
|
log_mod.queue_state = function() return { state = "paused", pause_reason = "offline" } end
|
||||||
|
Cache.queueState()
|
||||||
|
Assert.eq(countLines("queue paused reason=offline"), 2, "恢复后再次暂停要再记")
|
||||||
|
log_mod.queue_state = function() return { state = "paused", pause_reason = "network" } end
|
||||||
|
Cache.queueState()
|
||||||
|
Assert.eq(countLines("queue paused reason=network"), 1)
|
||||||
|
|
||||||
|
-- 读操作不写日志。
|
||||||
|
resetLogs()
|
||||||
|
Cache.status(6001)
|
||||||
|
Cache.index()
|
||||||
|
Assert.len(logs, 0, "读路径零日志")
|
||||||
|
|
||||||
|
-- open 失败同一原因只记一次。
|
||||||
|
log_mod.open = function() return nil, "viewer_running" end
|
||||||
|
resetLogs()
|
||||||
|
Cache.open({ base_url = "http://kav/", api_key = "k", entry = { chapterId = 6001, pages = 4 } })
|
||||||
|
Cache.open({ base_url = "http://kav/", api_key = "k", entry = { chapterId = 6001, pages = 4 } })
|
||||||
|
Assert.eq(countLines("cache open cid=6001 code=viewer_running"), 1, "open 失败去重")
|
||||||
|
|
||||||
|
-- chapters / delete_all / plan / summaryAll:清理门面
|
||||||
|
cfg.base_url, cfg.api_key = "http://kav", "k"
|
||||||
|
local cleanup_calls = {}
|
||||||
|
local cleanup_mod = installCache({
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = { status = true, summary = true, chapters = true, delete = true,
|
||||||
|
delete_all = true, server = true },
|
||||||
|
version = "0.10.0",
|
||||||
|
})
|
||||||
|
function cleanup_mod.chapters(base_url, series_id)
|
||||||
|
cleanup_calls.chapters = { base_url, series_id }
|
||||||
|
return { { chapterId = 1, pages = 10, bytes = 100, read = true } }
|
||||||
|
end
|
||||||
|
function cleanup_mod.delete_all()
|
||||||
|
cleanup_calls.delete_all = (cleanup_calls.delete_all or 0) + 1
|
||||||
|
return true, nil, { chapters = 3, bytes = 300 }
|
||||||
|
end
|
||||||
|
function cleanup_mod.summary(base_url)
|
||||||
|
cleanup_calls.summary = (cleanup_calls.summary or 0) + 1
|
||||||
|
cleanup_calls.summary_base = base_url
|
||||||
|
return { used = 300, available = 1000, chapters = 3 }
|
||||||
|
end
|
||||||
|
function cleanup_mod.register_server() return "srv" end
|
||||||
|
Cache.reset()
|
||||||
|
|
||||||
|
local plan_rows = Cache.chapters(42)
|
||||||
|
Assert.eq(cleanup_calls.chapters[1], "http://kav", "chapters 用当前服务器")
|
||||||
|
Assert.eq(cleanup_calls.chapters[2], 42, "chapters 透传 series_id")
|
||||||
|
Assert.len(plan_rows, 1, "chapters 返回数组")
|
||||||
|
|
||||||
|
local ok, _code, _message, detail = Cache.deleteAll()
|
||||||
|
Assert.is_true(ok, "deleteAll 成功")
|
||||||
|
Assert.eq(detail and detail.chapters, 3, "deleteAll 透传估算")
|
||||||
|
Assert.eq(cleanup_calls.delete_all, 1, "deleteAll 调 kamare 一次")
|
||||||
|
|
||||||
|
Assert.eq(Cache.summaryAll().chapters, 3, "summaryAll 返回合计")
|
||||||
|
Assert.eq(cleanup_calls.summary_base, nil, "summaryAll 不传 base_url")
|
||||||
|
|
||||||
|
local plan = Cache.plan(plan_rows, "read", nil)
|
||||||
|
Assert.eq(plan.chapters, 1, "read 过滤保留已读")
|
||||||
|
Assert.eq(plan.bytes, 100, "字节合计")
|
||||||
|
Assert.eq(plan.ids[1], 1, "ids 供批量删除")
|
||||||
|
local not_read = Cache.plan({ { chapterId = 2, pages = 10, bytes = 50, read = false } }, "read", nil)
|
||||||
|
Assert.eq(not_read.chapters, 0, "未读不入选")
|
||||||
|
local via_toc = Cache.plan({ { chapterId = 3, pages = 10, bytes = 50, read = false } }, "read",
|
||||||
|
{ ["3"] = 10 })
|
||||||
|
Assert.eq(via_toc.chapters, 1, "toc 的 pagesRead 补第三源")
|
||||||
|
local queued = Cache.plan({ { chapterId = 4, pages = 10, bytes = 1, read = true, queued = true } }, "all", nil)
|
||||||
|
Assert.eq(queued.queued, 1, "排队数进计划")
|
||||||
|
|
||||||
|
|
||||||
|
return true
|
||||||
@@ -0,0 +1,256 @@
|
|||||||
|
--[[--
|
||||||
|
漫画缓存的后台任务:登记 passive 任务、按本批卷轮询、暂停时放行自动休眠、收尾只提示一次。
|
||||||
|
|
||||||
|
kamare 仍是执行者,这里只观察 queue_state / status;队列全局共享,所以进度只数本批的卷。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.cache_task_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field, redundant-parameter
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
local Kit = require("support.widget_stubs")
|
||||||
|
Kit.install("paper")
|
||||||
|
|
||||||
|
local Themed = require("support.theme_stubs")
|
||||||
|
Themed.install()
|
||||||
|
|
||||||
|
package.preload["ui/network/manager"] = function()
|
||||||
|
return { isConnected = function() return true end }
|
||||||
|
end
|
||||||
|
package.preload["ui.guard"] = function()
|
||||||
|
return {
|
||||||
|
call = function(_label, fn, ...) return fn(...) end,
|
||||||
|
wrap = function(_label, fn) return fn end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["utils.log"] = function()
|
||||||
|
return { info = function() end, warn = function() end, err = function() end, dbg = function() end }
|
||||||
|
end
|
||||||
|
|
||||||
|
local PLUGIN = (debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita")
|
||||||
|
|
||||||
|
-- 缓存适配层:只提供 cache_task 用到的读接口;写操作不经过这里。
|
||||||
|
local st = { queue = { state = "idle", entries = {} }, statuses = {}, queue_ok = true }
|
||||||
|
package.preload["moonsource_kavita.cache"] = function()
|
||||||
|
return {
|
||||||
|
available = function(cap) return st.queue_ok and cap == "queue" end,
|
||||||
|
queueState = function() return st.queue end,
|
||||||
|
status = function(id) return st.statuses[tostring(id)] end,
|
||||||
|
isCached = function(status)
|
||||||
|
return type(status) == "table" and (status.state == "complete" or status.state == "stale")
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local Tasks = require("workers.tasks")
|
||||||
|
local CacheTask = dofile(PLUGIN .. "/cache_task.lua")
|
||||||
|
|
||||||
|
local series = { stable_id = "900", title = "测试系列" }
|
||||||
|
local entries = {
|
||||||
|
{ chapterId = 1, title = "第 1 卷" },
|
||||||
|
{ chapterId = 2, title = "第 2 卷" },
|
||||||
|
{ chapterId = 3, title = "第 3 卷" },
|
||||||
|
}
|
||||||
|
|
||||||
|
--- 跑一条指定延迟的定时器:<1 是队列的变更拍,>=1 且 <60 是轮询拍(60 秒是防休眠的 InputEvent 补拍)。
|
||||||
|
---@param match fun(delay: number): boolean
|
||||||
|
---@return boolean
|
||||||
|
local function runTimer(match)
|
||||||
|
for index, item in ipairs(Kit.scheduled) do
|
||||||
|
if match(item.delay) then
|
||||||
|
table.remove(Kit.scheduled, index)
|
||||||
|
item.fn()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 结清队列的变更拍(pause_auto_suspend 之类)。
|
||||||
|
local function changes()
|
||||||
|
while runTimer(function(delay) return delay < 1 end) do end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 跑一拍轮询。
|
||||||
|
local function tick()
|
||||||
|
Assert.is_true(runTimer(function(delay) return delay >= 1 and delay < 60 end), "排了下一拍轮询")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function reset()
|
||||||
|
for _idx, item in ipairs(Tasks.tasks()) do
|
||||||
|
local live = Tasks.get(item.key)
|
||||||
|
if live then live.cancel() end
|
||||||
|
end
|
||||||
|
changes()
|
||||||
|
st.queue = { state = "idle", entries = {} }
|
||||||
|
st.statuses = {}
|
||||||
|
st.queue_ok = true
|
||||||
|
Themed.made = {}
|
||||||
|
Kit.scheduled, Kit.unscheduled = {}, {}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 缺 queue 能力:没有可轮询的队列,不登记(免得后台任务永远挂着)。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
st.queue_ok = false
|
||||||
|
Assert.is_nil(CacheTask.track{ series = series, entries = entries })
|
||||||
|
Assert.len(Tasks.tasks(), 0)
|
||||||
|
st.queue_ok = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 登记:一条 passive 的 cache 任务,顶栏读到「执行中 1/1」;缓存期间不自动休眠。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
local handle = CacheTask.track{ series = series, entries = entries }
|
||||||
|
Assert.not_nil(handle)
|
||||||
|
local list = Tasks.tasks()
|
||||||
|
Assert.len(list, 1, "只登记一条")
|
||||||
|
Assert.eq(list[1].kind, "cache")
|
||||||
|
Assert.eq(list[1].title, "测试系列")
|
||||||
|
Assert.eq(list[1].state, "running", "passive 任务立刻启动,不排队")
|
||||||
|
changes()
|
||||||
|
Assert.is_true(require("pluginshare").pause_auto_suspend, "缓存期间压住自动休眠")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 进度:只数本批的卷,当前卷名来自 queue.current_chapter_id。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
CacheTask.track{ series = series, entries = entries }
|
||||||
|
st.statuses["1"] = { state = "complete" }
|
||||||
|
st.queue = { state = "downloading", entries = { [2] = { state = "downloading" } },
|
||||||
|
current_chapter_id = 2 }
|
||||||
|
tick()
|
||||||
|
local task = Tasks.tasks()[1]
|
||||||
|
Assert.eq(task.count, 1, "已落地 1 卷")
|
||||||
|
Assert.eq(task.total, 3, "总数是本批卷数")
|
||||||
|
Assert.eq(task.text, "第 2 卷", "说明行写当前卷")
|
||||||
|
|
||||||
|
-- 不在本批的卷(别的系列)不计数。
|
||||||
|
st.queue.entries[99] = { state = "downloading" }
|
||||||
|
tick()
|
||||||
|
Assert.eq(Tasks.tasks()[1].count, 1, "别的系列不算进度")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 全部落地:任务结束、toast 一次、不再排下一拍。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
CacheTask.track{ series = series, entries = entries }
|
||||||
|
for index = 1, 3 do st.statuses[tostring(index)] = { state = "complete" } end
|
||||||
|
st.queue = { state = "idle", entries = {} }
|
||||||
|
local toasts = #Themed.all("toast")
|
||||||
|
tick()
|
||||||
|
Assert.len(Tasks.tasks(), 0, "结束后离开未结束列表")
|
||||||
|
local finished = Tasks.finished()[1]
|
||||||
|
Assert.is_true(finished.ok, "全成算成功")
|
||||||
|
Assert.eq(finished.total, 3)
|
||||||
|
Assert.eq(finished.count, 3, "收尾补报最终计数(不是上一拍的 2/3)")
|
||||||
|
Assert.is_nil(finished.text, "收尾后不再挂着上一卷的名字")
|
||||||
|
Assert.eq(#Themed.all("toast"), toasts + 1, "只 toast 一次")
|
||||||
|
Assert.eq(Themed.last("toast").text, "已缓存 3 卷")
|
||||||
|
Assert.is_false(runTimer(function(delay) return delay >= 1 end), "收尾后不再轮询")
|
||||||
|
changes()
|
||||||
|
Assert.is_false(require("pluginshare").pause_auto_suspend, "结束放行自动休眠")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 部分失败:失败项是终态(kamare 留在队列里等重试),收尾报成功 / 失败数。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
CacheTask.track{ series = series, entries = entries }
|
||||||
|
st.statuses["1"] = { state = "complete" }
|
||||||
|
st.statuses["2"] = { state = "complete" }
|
||||||
|
st.queue = { state = "idle", entries = { [3] = { state = "failed", last_error = "http 403" } } }
|
||||||
|
tick()
|
||||||
|
local finished = Tasks.finished()[1]
|
||||||
|
Assert.is_false(finished.ok)
|
||||||
|
Assert.eq(finished.total, 3)
|
||||||
|
Assert.eq(finished.count, 2, "失败的那卷不算成功")
|
||||||
|
Assert.eq(Themed.last("toast").text, "2 卷成功,1 卷失败")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 静音:页面自己的进度框负责提示时不出 toast。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
local handle = CacheTask.track{ series = series, entries = entries }
|
||||||
|
handle.mute(true)
|
||||||
|
for index = 1, 3 do st.statuses[tostring(index)] = { state = "complete" } end
|
||||||
|
st.queue = { state = "idle", entries = {} }
|
||||||
|
local toasts = #Themed.all("toast")
|
||||||
|
tick()
|
||||||
|
Assert.eq(#Themed.all("toast"), toasts, "静音时不提示")
|
||||||
|
Assert.is_true(Tasks.finished()[1].ok, "任务照常收尾")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 暂停:说明行给暂停原因,放行自动休眠,轮询放慢到 5 秒;恢复后继续。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
CacheTask.track{ series = series, entries = entries }
|
||||||
|
st.statuses["1"] = { state = "complete" }
|
||||||
|
st.queue = { state = "paused", pause_reason = "low_space",
|
||||||
|
entries = { [2] = { state = "queued" } } }
|
||||||
|
changes()
|
||||||
|
tick()
|
||||||
|
local task = Tasks.tasks()[1]
|
||||||
|
Assert.eq(task.state, "running", "暂停只是报状态,不结束任务")
|
||||||
|
Assert.eq(task.text, "空间不足,已暂停")
|
||||||
|
changes()
|
||||||
|
Assert.is_false(require("pluginshare").pause_auto_suspend, "暂停时不再撑着不睡")
|
||||||
|
Assert.is_true(runTimer(function(delay) return delay == 5 end), "暂停时 5 秒一拍")
|
||||||
|
|
||||||
|
-- 恢复:下一拍回到下载说明行,重新压住休眠。
|
||||||
|
st.queue = { state = "downloading", entries = { [2] = { state = "downloading" } },
|
||||||
|
current_chapter_id = 2 }
|
||||||
|
tick()
|
||||||
|
Assert.eq(Tasks.tasks()[1].text, "第 2 卷")
|
||||||
|
changes()
|
||||||
|
Assert.is_true(require("pluginshare").pause_auto_suspend, "恢复后继续撑住")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 队列丢了(kamare 重启 / 队列被清):连续几拍看不到本批的项就按中断收尾。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
CacheTask.track{ series = series, entries = entries }
|
||||||
|
local toasts = #Themed.all("toast")
|
||||||
|
for _idx = 1, 4 do
|
||||||
|
tick()
|
||||||
|
Assert.len(Tasks.tasks(), 1, "还没到上限,继续等")
|
||||||
|
end
|
||||||
|
tick()
|
||||||
|
Assert.len(Tasks.tasks(), 0, "超时后收尾")
|
||||||
|
local finished = Tasks.finished()[1]
|
||||||
|
Assert.is_false(finished.ok)
|
||||||
|
Assert.eq(#Themed.all("toast"), toasts + 1)
|
||||||
|
Assert.eq(Themed.last("toast").text, "缓存已中断")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 同一部再有卷入队 / 重试:并进同一条任务,失败项清掉终态重新观察。
|
||||||
|
do
|
||||||
|
reset()
|
||||||
|
local first = CacheTask.track{ series = series, entries = { entries[1] } }
|
||||||
|
Assert.eq(Tasks.tasks()[1].total, 1)
|
||||||
|
st.queue = { state = "downloading", entries = { [1] = { state = "downloading" } } }
|
||||||
|
tick()
|
||||||
|
Assert.eq(Tasks.tasks()[1].total, 1)
|
||||||
|
|
||||||
|
local merged = CacheTask.track{ series = series, entries = { entries[2], entries[3] } }
|
||||||
|
Assert.eq(merged, first, "同一部书复用同一条任务")
|
||||||
|
Assert.len(Tasks.tasks(), 1, "不新增任务")
|
||||||
|
Assert.eq(Tasks.tasks()[1].total, 3, "总数并进去")
|
||||||
|
|
||||||
|
-- 失败项重试:终态清掉,重新计入进度。
|
||||||
|
st.statuses["1"] = { state = "complete" }
|
||||||
|
st.queue = { state = "downloading", entries = { [2] = { state = "downloading" },
|
||||||
|
[3] = { state = "failed" } } }
|
||||||
|
tick()
|
||||||
|
Assert.eq(Tasks.tasks()[1].count, 1, "失败项不算成功")
|
||||||
|
merged.add({ entries[3] })
|
||||||
|
st.queue = { state = "downloading", entries = { [2] = { state = "downloading" },
|
||||||
|
[3] = { state = "downloading" } } }
|
||||||
|
tick()
|
||||||
|
Assert.eq(Tasks.tasks()[1].count, 1, "重试的卷回到未完成")
|
||||||
|
st.statuses["2"] = { state = "complete" }
|
||||||
|
st.statuses["3"] = { state = "complete" }
|
||||||
|
st.queue = { state = "idle", entries = {} }
|
||||||
|
tick()
|
||||||
|
Assert.is_true(Tasks.finished()[1].ok, "重试成功后收尾")
|
||||||
|
end
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
--[[--
|
||||||
|
book.koplugin/source/kavita/client.lua:请求超时可配置,
|
||||||
|
统计分页的 URL 形态与 `Pagination` 头解析。
|
||||||
|
|
||||||
|
慢设备 / 慢服务器上全量书架(all-v2)一次要几十秒,固定的 30s 上限会让整轮同步中断、
|
||||||
|
书架永远加载不出来;这里锁住「默认足够宽 + 可在设置里调大 + 透传到 HTTP 层」。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.client_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
local JsonStub = require("support.json_stub")
|
||||||
|
|
||||||
|
package.loaded["json"] = { encode = JsonStub.encode, decode = JsonStub.decode }
|
||||||
|
|
||||||
|
local captured
|
||||||
|
package.loaded["http.request"] = {
|
||||||
|
ok = function(code) return tonumber(code) == 200 end,
|
||||||
|
request = function(opts, cb)
|
||||||
|
captured = opts
|
||||||
|
cb({ code = 200, body = "{}" })
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
local PLUGIN = (debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita")
|
||||||
|
package.preload["moonsource_kavita.client"] = function()
|
||||||
|
return dofile(PLUGIN .. "/client.lua")
|
||||||
|
end
|
||||||
|
local Client = require("moonsource_kavita.client")
|
||||||
|
|
||||||
|
local function make(timeout)
|
||||||
|
return Client.new({ base_url = "http://kav/", api_key = "k", timeout = timeout })
|
||||||
|
end
|
||||||
|
|
||||||
|
Assert.eq(Client.DEFAULT_TIMEOUT, 60, "默认不再是 30s")
|
||||||
|
Assert.eq(Client.new({ base_url = "http://kav/", api_key = "k" }).timeout, 60, "未配置用默认超时")
|
||||||
|
Assert.eq(make("120").timeout, 120, "设置里的字符串数值也认")
|
||||||
|
Assert.eq(make(1).timeout, 5, "过小收敛到下限")
|
||||||
|
Assert.eq(make(0).timeout, 5, "0 收敛到下限")
|
||||||
|
Assert.eq(make(100000).timeout, 600, "过大收敛到上限")
|
||||||
|
|
||||||
|
local client = make(180)
|
||||||
|
Assert.eq(client:configured(), true)
|
||||||
|
client:request("GET", "/api/Series/all-v2", { pageNumber = 1 }, nil, function() end)
|
||||||
|
Assert.eq(captured.timeout, 180, "超时透传到 HTTP 请求,长拉书架不再被 30s 掐断")
|
||||||
|
Assert.matches(captured.url, "^http://kav/api/Series/all%-v2%?")
|
||||||
|
Assert.eq(captured.headers["x-api-key"], "k")
|
||||||
|
|
||||||
|
-- 统计拉取:`Libraries` 是重复键(逗号串会被服务端当成一个库,恒返回 0 条),
|
||||||
|
-- 其余参数按名排序,PageSize 用服务端接受的上限 200。
|
||||||
|
Assert.eq(
|
||||||
|
client:url("/api/Stats/reading-history", {
|
||||||
|
TimeZoneId = "Asia/Shanghai", Libraries = { 2, 1 }, PageNumber = 1, PageSize = 200,
|
||||||
|
}),
|
||||||
|
"http://kav/api/Stats/reading-history?Libraries=2&Libraries=1&PageNumber=1&PageSize=200&TimeZoneId=Asia%2FShanghai"
|
||||||
|
)
|
||||||
|
Assert.eq(client:url("/api/Image/series-cover", { seriesId = "10" }),
|
||||||
|
"http://kav/api/Image/series-cover?seriesId=10", "单值参数与 formEncode 同形")
|
||||||
|
|
||||||
|
-- 分页头(挂在响应上,不在 body 里):只认 totalPages。
|
||||||
|
Assert.eq(Client.totalPages('{"currentPage":1,"itemsPerPage":200,"totalItems":316,"totalPages":2}'), 2)
|
||||||
|
Assert.eq(Client.totalPages('{"totalPages":0}'), 0, "0 页 = 没有数据,读成 nil 会让调用方按「本页拉满」再拉一页")
|
||||||
|
Assert.is_nil(Client.totalPages('{"currentPage":1}'), "没有 totalPages 就当不可信,调用方走兜底")
|
||||||
|
Assert.is_nil(Client.totalPages('{"totalPages":-1}'), "负数不可信")
|
||||||
|
Assert.is_nil(Client.totalPages(nil))
|
||||||
|
Assert.is_nil(Client.totalPages(""))
|
||||||
|
Assert.is_nil(Client.totalPages("<html>oops</html>"), "反代错误页不能当分页头")
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
--[[--
|
||||||
|
卷列表 / 系列页共用的续读目标:主线 = 最远有进度的卷,回顾旧卷只标「上次翻阅」。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.continue_point_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
|
||||||
|
local CP = dofile((debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita") .. "/continue_point.lua")
|
||||||
|
|
||||||
|
local function vol(chapter_id, title, pages, pages_read)
|
||||||
|
return {
|
||||||
|
idx = chapter_id, chapterId = chapter_id, title = title,
|
||||||
|
pages = pages, pagesRead = pages_read or 0,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local toc = {
|
||||||
|
vol(101, "第 1 卷", 100, 100),
|
||||||
|
vol(102, "第 2 卷", 100, 40),
|
||||||
|
vol(103, "第 3 卷", 100, 0),
|
||||||
|
vol(104, "第 4 卷", 100, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 未开始
|
||||||
|
local fresh = CP.pick({
|
||||||
|
vol(101, "第 1 卷", 100, 0),
|
||||||
|
vol(102, "第 2 卷", 100, 0),
|
||||||
|
}, {})
|
||||||
|
Assert.eq(fresh.kind, "fresh")
|
||||||
|
Assert.eq(fresh.entry.chapterId, 101)
|
||||||
|
Assert.eq(fresh.page, 0)
|
||||||
|
local fresh_text, fresh_caption = CP.describe(fresh, "系列")
|
||||||
|
Assert.eq(fresh_text, "开始阅读 · 第 1 卷")
|
||||||
|
Assert.eq(fresh_caption, "共 100 页")
|
||||||
|
|
||||||
|
-- 读到第 2 卷一半:主线是第 2 卷
|
||||||
|
local mid = CP.pick(toc, {})
|
||||||
|
Assert.eq(mid.kind, "continue")
|
||||||
|
Assert.eq(mid.entry.chapterId, 102)
|
||||||
|
Assert.eq(mid.fraction, 0.4)
|
||||||
|
Assert.eq(mid.page, 40)
|
||||||
|
Assert.eq(mid.total_pages, 100)
|
||||||
|
local mid_text, mid_caption = CP.describe(mid, "系列")
|
||||||
|
Assert.eq(mid_text, "继续阅读 · 第 2 卷")
|
||||||
|
Assert.eq(mid_caption, "第 40/100 页 · 40%")
|
||||||
|
Assert.is_nil(mid.browsed)
|
||||||
|
|
||||||
|
-- 第 2 卷读完:顺延第 3 卷
|
||||||
|
local rolled = CP.pick({
|
||||||
|
vol(101, "第 1 卷", 100, 100),
|
||||||
|
vol(102, "第 2 卷", 100, 100),
|
||||||
|
vol(103, "第 3 卷", 100, 0),
|
||||||
|
}, {})
|
||||||
|
Assert.eq(rolled.entry.chapterId, 103)
|
||||||
|
Assert.eq(rolled.kind, "continue")
|
||||||
|
Assert.eq(rolled.page, 0)
|
||||||
|
|
||||||
|
-- 全部读完:回到第 1 卷,kind = done
|
||||||
|
local done = CP.pick({
|
||||||
|
vol(101, "第 1 卷", 100, 100),
|
||||||
|
vol(102, "第 2 卷", 100, 100),
|
||||||
|
}, {})
|
||||||
|
Assert.eq(done.kind, "done")
|
||||||
|
Assert.eq(done.entry.chapterId, 101)
|
||||||
|
|
||||||
|
-- 读到第 4 卷、回头翻第 1 卷:主线不动,第 1 卷只作「上次翻阅」
|
||||||
|
local updated = { [101] = 300, [104] = 200 }
|
||||||
|
local review = CP.pick({
|
||||||
|
vol(101, "第 1 卷", 100, 100),
|
||||||
|
vol(102, "第 2 卷", 100, 100),
|
||||||
|
vol(103, "第 3 卷", 100, 100),
|
||||||
|
vol(104, "第 4 卷", 100, 50),
|
||||||
|
}, {
|
||||||
|
updated_at = function(e) return updated[e.chapterId] end,
|
||||||
|
})
|
||||||
|
Assert.eq(review.entry.chapterId, 104, "主线仍是最远的第 4 卷")
|
||||||
|
Assert.eq(review.browsed.chapterId, 101, "上次翻阅单独返回")
|
||||||
|
|
||||||
|
-- 上次翻阅 == 主线:不返回标记
|
||||||
|
local same = CP.pick(toc, { updated_at = function(e) return e.chapterId == 102 and 500 or 0 end })
|
||||||
|
Assert.is_nil(same.browsed)
|
||||||
|
|
||||||
|
-- 注入 fraction / page(本地 ProgressDB 比 toc 快照新)
|
||||||
|
local local_better = CP.pick(toc, {
|
||||||
|
fraction = function(e) return e.chapterId == 102 and 0.9 or nil end,
|
||||||
|
page = function(e)
|
||||||
|
if e.chapterId == 102 then return { page = 90, total = 100 } end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
Assert.eq(local_better.fraction, 0.9)
|
||||||
|
Assert.eq(local_better.page, 90)
|
||||||
|
|
||||||
|
-- pages == 0 的卷不参与
|
||||||
|
local zero = CP.pick({
|
||||||
|
vol(101, "第 1 卷", 0, 0),
|
||||||
|
vol(102, "第 2 卷", 100, 10),
|
||||||
|
}, {})
|
||||||
|
Assert.eq(zero.entry.chapterId, 102)
|
||||||
|
|
||||||
|
-- 空目录
|
||||||
|
Assert.is_nil(CP.pick({}, {}))
|
||||||
|
Assert.is_nil(CP.pick(nil, nil))
|
||||||
|
|
||||||
|
-- 服务端已读完、本机重新打开留下 1%:仍按已读完处理,主线顺延下一卷。
|
||||||
|
local reread = CP.pick({
|
||||||
|
vol(101, "第 1 卷", 100, 100),
|
||||||
|
vol(102, "第 2 卷", 100, 100),
|
||||||
|
vol(103, "第 3 卷", 100, 0),
|
||||||
|
}, { fraction = function(e) return e.chapterId == 102 and 0.01 or nil end })
|
||||||
|
Assert.eq(reread.entry.chapterId, 103, "已读完的卷不会被本机低进度拖回主线")
|
||||||
|
Assert.eq(reread.kind, "continue")
|
||||||
|
|
||||||
|
|
||||||
|
-- 调用方说已读完(kamare 三源)时同样按 fraction 1,不再被本机低进度拖回。
|
||||||
|
local by_caller = CP.pick({
|
||||||
|
vol(101, "第 1 卷", 100, 0),
|
||||||
|
vol(102, "第 2 卷", 100, 0),
|
||||||
|
}, {
|
||||||
|
fraction = function(e) return e.chapterId == 101 and 0.01 or nil end,
|
||||||
|
complete = function(e) return e.chapterId == 101 end,
|
||||||
|
})
|
||||||
|
Assert.eq(by_caller.entry.chapterId, 102, "调用方标记已读完的卷不会成为主线")
|
||||||
|
|
||||||
|
|
||||||
|
-- 卷名:优先标题;空 / 退化成系列名时兜底第 N 卷
|
||||||
|
Assert.eq(CP.label({ idx = 3, title = "ONE PIECE (3)" }, "航海王"), "ONE PIECE (3)")
|
||||||
|
Assert.eq(CP.label({ idx = 3, title = "" }, "航海王"), "第 3 卷")
|
||||||
|
Assert.eq(CP.label({ idx = 3, title = "航海王" }, "航海王"), "第 3 卷")
|
||||||
|
Assert.eq(CP.label({ idx = 3 }, "航海王"), "第 3 卷")
|
||||||
|
Assert.eq(CP.label(nil, "航海王"), "?")
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
--[[--
|
||||||
|
样本 fixture:`GET /api/Stats/reading-history/series/7453` 实测响应(2026-10-16,Kavita 0.9.1.4)
|
||||||
|
的精简版,只留聚合用到的字段(seriesId / localDate / startTimeUtc / chapters[])。
|
||||||
|
|
||||||
|
对账基线(research-kavita-stats-pull.md §3):64 条会话 / 14,237s;逐日见 stats_spec 用例。
|
||||||
|
来源完整响应:/tmp/opencode/kavita/live/history-7453-all.json(提交时精简,数值逐条未改)。
|
||||||
|
|
||||||
|
@module tests.extensions.kavita.fixtures.history_7453
|
||||||
|
--]]
|
||||||
|
return {
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T13:49:02.6722926", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T13:49:02.6722926", durationSeconds = 845, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T11:51:10.7006183", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T11:51:10.7006183", durationSeconds = 638, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T11:14:33.5066159", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T11:14:33.5066159", durationSeconds = 436, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T08:01:09.6078347", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T08:01:09.6078347", durationSeconds = 33, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T07:20:02.0863122", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T07:20:02.0863122", durationSeconds = 156, pagesRead = 15 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T04:38:27.7268649", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T04:38:27.7268649", durationSeconds = 462, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T03:25:22.1307379", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T03:25:22.1307379", durationSeconds = 266, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T02:59:07.9600274", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T02:59:07.9600274", durationSeconds = 126, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T14:50:29.2326588", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T14:50:29.2326588", durationSeconds = 329, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T13:55:48.5704762", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T13:55:48.5704762", durationSeconds = 716, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T12:59:54.4012612", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T12:59:54.4012612", durationSeconds = 210, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T12:32:09.2873459", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T12:32:09.2873459", durationSeconds = 354, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T10:50:12.8325335", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T10:50:12.8325335", durationSeconds = 427, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T09:55:45.2531997", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T09:55:45.2531997", durationSeconds = 229, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T08:18:25.5482677", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T08:18:25.5482677", durationSeconds = 631, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T06:35:44.8950968", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T06:56:37.9521487", durationSeconds = 597, pagesRead = 5 },
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T06:35:44.8950968", durationSeconds = 529, pagesRead = -6 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T06:12:27.3026502", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T06:12:27.3026502", durationSeconds = 686, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T05:35:38.8926445", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T05:35:38.8926445", durationSeconds = 674, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T03:36:59.7411875", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T03:36:59.7411875", durationSeconds = 1352, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T01:39:31.4453653", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T01:39:31.4453653", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T14:56:50.7578846", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T14:56:50.7578846", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T12:50:13.6195947", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T12:50:13.6195947", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T10:49:24.2700176", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T10:49:24.2700176", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T09:19:44.4142404", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T09:19:44.4142404", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T07:17:51.0855549", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T07:17:51.0855549", durationSeconds = 31, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T06:23:56.2429684", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T06:23:56.2429684", durationSeconds = 948, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T04:44:11.1456271", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T04:44:11.1456271", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T04:04:52.1419963", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T04:04:52.1419963", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-12T00:00:00", startTimeUtc = "2026-10-12T03:52:47.3926019", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-12T03:52:47.3926019", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T15:16:45.9848037", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T15:16:45.9848037", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T14:54:13.613368", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T14:54:13.613368", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T14:35:43.0809755", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T14:35:43.0809755", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T12:58:29.291105", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T12:58:29.291105", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T11:00:42.6215043", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T11:00:42.6215043", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T04:17:28.3592015", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T04:17:28.3592015", durationSeconds = 512, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T04:44:42.7023417", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-10T04:44:42.7023417", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T03:55:35.74839", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-10T03:55:35.74839", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T03:39:55.2030981", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-10T03:39:55.2030981", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T14:45:39.0731175", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T14:45:39.0731175", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T07:44:06.636679", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T07:44:06.636679", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T07:13:20.7857153", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T07:13:20.7857153", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T04:40:28.7189645", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T04:40:28.7189645", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T04:05:17.6951039", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T04:05:17.6951039", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T14:34:05.7981443", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T14:34:05.7981443", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T13:12:53.6969824", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T13:12:53.6969824", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T11:48:06.6315963", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T11:48:06.6315963", durationSeconds = 544, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T11:02:33.6484158", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T11:02:33.6484158", durationSeconds = 611, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T10:31:08.475182", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T10:31:08.475182", durationSeconds = 3, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T09:03:45.5309711", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T09:03:45.5309711", durationSeconds = 86, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T07:59:09.2881628", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T07:59:09.2881628", durationSeconds = 263, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T07:20:18.0105615", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T07:20:18.0105615", durationSeconds = 233, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T06:48:51.312417", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T06:48:51.312417", durationSeconds = 296, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T04:05:45.0300961", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T04:05:45.0300961", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-07T00:00:00", startTimeUtc = "2026-10-07T13:44:15.125016", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-07T13:44:15.125016", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-07T00:00:00", startTimeUtc = "2026-10-07T09:45:01.0814021", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-07T09:45:01.0814021", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-07T00:00:00", startTimeUtc = "2026-10-07T05:19:38.9892914", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-07T05:19:38.9892914", durationSeconds = 503, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T12:01:31.4949015", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-06T12:01:31.4949015", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T11:37:48.0185472", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-06T11:37:48.0185472", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T03:21:10.9150125", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-06T03:21:10.9150125", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T02:50:29.5547188", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-06T02:50:29.5547188", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-05T00:00:00", startTimeUtc = "2026-10-05T14:10:59.8916334", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-05T14:10:59.8916334", durationSeconds = 195, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-05T00:00:00", startTimeUtc = "2026-10-05T12:18:33.1689018", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-05T12:18:33.1689018", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:25:25.4088288", chapters = {
|
||||||
|
{ chapterId = 11271, startTimeUtc = "2026-09-29T10:25:25.4088288", durationSeconds = 86, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:01:44.7835505", chapters = {
|
||||||
|
{ chapterId = 11271, startTimeUtc = "2026-09-29T10:01:44.7835505", durationSeconds = 230, pagesRead = 0 } } },
|
||||||
|
}
|
||||||
@@ -0,0 +1,657 @@
|
|||||||
|
--[[--
|
||||||
|
样本 fixture:`GET /api/Stats/reading-history` 全量实测响应(2026-10-16,Kavita 0.9.1.4)的
|
||||||
|
精简版,只留聚合用到的字段(seriesId / localDate / startTimeUtc / chapters[]),共 316 条会话 /
|
||||||
|
60 个系列 / 2 页。
|
||||||
|
|
||||||
|
数值逐条未改;对账基线 = research-kavita-stats-pull.md §2(逐日时长 / 页数)与 §4(Σ=60,238s /
|
||||||
|
1,406 页 / 起点 2026-09-18)。来源完整响应:/tmp/opencode/kavita/live/history-all-sep-oct.json。
|
||||||
|
|
||||||
|
@module tests.extensions.kavita.fixtures.history_all
|
||||||
|
--]]
|
||||||
|
return {
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-16T00:00:00", startTimeUtc = "2026-10-15T23:51:47.4527045", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-15T23:51:47.4527045", durationSeconds = 220, pagesRead = 6 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T13:49:02.6722926", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T13:49:02.6722926", durationSeconds = 845, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T13:41:03.9585123", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-15T13:41:03.9585123", durationSeconds = 469, pagesRead = 6 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T12:18:53.1535569", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-15T12:18:53.1535569", durationSeconds = 163, pagesRead = 7 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T11:51:10.7006183", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T11:51:10.7006183", durationSeconds = 638, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T11:40:49.4449693", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-15T11:40:49.4449693", durationSeconds = 335, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T11:35:04.1639136", chapters = {
|
||||||
|
{ chapterId = 17863, startTimeUtc = "2026-10-15T11:38:58.0370869", durationSeconds = 81, pagesRead = 15 },
|
||||||
|
{ chapterId = 17868, startTimeUtc = "2026-10-15T11:35:04.1639136", durationSeconds = 210, pagesRead = 29 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T11:14:33.5066159", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T11:14:33.5066159", durationSeconds = 436, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T11:04:40.7474367", chapters = {
|
||||||
|
{ chapterId = 17868, startTimeUtc = "2026-10-15T11:04:40.7474367", durationSeconds = 321, pagesRead = 44 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T08:01:09.6078347", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T08:01:09.6078347", durationSeconds = 33, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T07:20:02.0863122", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T07:20:02.0863122", durationSeconds = 156, pagesRead = 15 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T04:38:27.7268649", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T04:38:27.7268649", durationSeconds = 462, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T03:25:22.1307379", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T03:25:22.1307379", durationSeconds = 266, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-15T00:00:00", startTimeUtc = "2026-10-15T02:59:07.9600274", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-15T02:59:07.9600274", durationSeconds = 126, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T14:50:29.2326588", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T14:50:29.2326588", durationSeconds = 329, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T14:38:39.3797696", chapters = {
|
||||||
|
{ chapterId = 17868, startTimeUtc = "2026-10-14T14:38:39.3797696", durationSeconds = 481, pagesRead = 32 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T14:08:54.1661113", chapters = {
|
||||||
|
{ chapterId = 17868, startTimeUtc = "2026-10-14T14:08:54.1661113", durationSeconds = 309, pagesRead = 27 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T13:55:48.5704762", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T13:55:48.5704762", durationSeconds = 716, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T13:49:23.172248", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-14T13:49:23.172248", durationSeconds = 305, pagesRead = 6 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T13:03:43.5815681", chapters = {
|
||||||
|
{ chapterId = 17868, startTimeUtc = "2026-10-14T13:03:43.5815681", durationSeconds = 22, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T12:59:54.4012612", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T12:59:54.4012612", durationSeconds = 210, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T12:32:09.2873459", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T12:32:09.2873459", durationSeconds = 354, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T10:50:12.8325335", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T10:50:12.8325335", durationSeconds = 427, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T09:55:45.2531997", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T09:55:45.2531997", durationSeconds = 229, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T09:17:05.53145", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-14T09:17:05.53145", durationSeconds = 433, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T09:13:54.1770611", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-14T09:13:54.1770611", durationSeconds = 141, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T08:31:01.497007", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-14T08:31:01.497007", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T08:18:25.5482677", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T08:18:25.5482677", durationSeconds = 631, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T07:55:05.3240629", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-10-14T07:55:05.3240629", durationSeconds = 82, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10705, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T07:38:45.2095335", chapters = {
|
||||||
|
{ chapterId = 18930, startTimeUtc = "2026-10-14T07:38:45.2095335", durationSeconds = 206, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T07:34:26.9247375", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-10-14T07:34:26.9247375", durationSeconds = 83, pagesRead = 5 } } },
|
||||||
|
{ seriesId = 10720, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T07:16:16.0691328", chapters = {
|
||||||
|
{ chapterId = 18951, startTimeUtc = "2026-10-14T07:16:16.0691328", durationSeconds = 72, pagesRead = 10 } } },
|
||||||
|
{ seriesId = 8661, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T07:14:59.4980606", chapters = {
|
||||||
|
{ chapterId = 12763, startTimeUtc = "2026-10-14T07:14:59.4980606", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7805, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T07:14:45.0436933", chapters = {
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-10-14T07:14:45.0436933", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T07:14:08.0963104", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-10-14T07:14:08.0963104", durationSeconds = 71, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T06:46:46.3439122", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-14T07:07:38.102712", durationSeconds = 0, pagesRead = 0 },
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-14T06:46:46.3439122", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T06:54:53.1919748", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-14T07:06:44.0374852", durationSeconds = 21, pagesRead = 24 },
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-14T06:54:53.1919748", durationSeconds = 48, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T06:35:44.8950968", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T06:56:37.9521487", durationSeconds = 597, pagesRead = 5 },
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T06:35:44.8950968", durationSeconds = 529, pagesRead = -6 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T06:12:27.3026502", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T06:12:27.3026502", durationSeconds = 686, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T06:02:06.7713486", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-14T06:02:06.7713486", durationSeconds = 647, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T05:48:30.213286", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-14T05:48:30.213286", durationSeconds = 113, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T05:47:30.9663527", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-14T05:47:30.9663527", durationSeconds = 40, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T05:35:38.8926445", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T05:35:38.8926445", durationSeconds = 674, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T03:36:59.7411875", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T03:36:59.7411875", durationSeconds = 1352, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T03:28:46.1491425", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-14T03:28:46.1491425", durationSeconds = 794, pagesRead = -1 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T03:16:21.8058422", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-14T03:16:21.8058422", durationSeconds = 1063, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T01:55:37.5163534", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-14T01:55:37.5163534", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10004, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T01:49:18.2803981", chapters = {
|
||||||
|
{ chapterId = 14594, startTimeUtc = "2026-10-14T01:49:18.2803981", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-14T00:00:00", startTimeUtc = "2026-10-14T01:39:31.4453653", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-14T01:39:31.4453653", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T14:57:39.6850524", chapters = {
|
||||||
|
{ chapterId = 17868, startTimeUtc = "2026-10-13T14:57:39.6850524", durationSeconds = 296, pagesRead = 43 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T14:56:50.7578846", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T14:56:50.7578846", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T14:36:12.2101045", chapters = {
|
||||||
|
{ chapterId = 17868, startTimeUtc = "2026-10-13T14:42:41.461277", durationSeconds = 73, pagesRead = 17 },
|
||||||
|
{ chapterId = 17861, startTimeUtc = "2026-10-13T14:36:12.2101045", durationSeconds = 382, pagesRead = 50 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T13:30:56.9584871", chapters = {
|
||||||
|
{ chapterId = 17861, startTimeUtc = "2026-10-13T13:30:56.9584871", durationSeconds = 965, pagesRead = 35 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T12:50:13.6195947", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T12:50:13.6195947", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T11:07:48.1054905", chapters = {
|
||||||
|
{ chapterId = 17861, startTimeUtc = "2026-10-13T11:07:48.1054905", durationSeconds = 1557, pagesRead = 87 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T10:49:24.2700176", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T10:49:24.2700176", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T10:33:26.9620773", chapters = {
|
||||||
|
{ chapterId = 17861, startTimeUtc = "2026-10-13T10:33:26.9620773", durationSeconds = 85, pagesRead = 9 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T09:19:44.4142404", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T09:19:44.4142404", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T08:41:22.7503239", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-13T08:41:22.7503239", durationSeconds = 177, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T07:17:51.0855549", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T07:17:51.0855549", durationSeconds = 31, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T06:23:56.2429684", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T06:23:56.2429684", durationSeconds = 948, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T04:44:11.1456271", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T04:44:11.1456271", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-13T00:00:00", startTimeUtc = "2026-10-13T04:04:52.1419963", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-13T04:04:52.1419963", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-12T00:00:00", startTimeUtc = "2026-10-12T13:41:25.4902953", chapters = {
|
||||||
|
{ chapterId = 17861, startTimeUtc = "2026-10-12T13:41:25.4902953", durationSeconds = 77, pagesRead = 5 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-12T00:00:00", startTimeUtc = "2026-10-12T04:30:51.522376", chapters = {
|
||||||
|
{ chapterId = 17861, startTimeUtc = "2026-10-12T04:30:51.522376", durationSeconds = 26, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-12T00:00:00", startTimeUtc = "2026-10-12T03:52:47.3926019", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-12T03:52:47.3926019", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-12T00:00:00", startTimeUtc = "2026-10-12T02:50:17.2681685", chapters = {
|
||||||
|
{ chapterId = 17861, startTimeUtc = "2026-10-12T02:59:07.2940778", durationSeconds = 505, pagesRead = 5 },
|
||||||
|
{ chapterId = 17855, startTimeUtc = "2026-10-12T02:50:17.2681685", durationSeconds = 518, pagesRead = 12 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-12T00:00:00", startTimeUtc = "2026-10-12T02:26:17.4191481", chapters = {
|
||||||
|
{ chapterId = 17855, startTimeUtc = "2026-10-12T02:26:17.4191481", durationSeconds = 332, pagesRead = 27 } } },
|
||||||
|
{ seriesId = 10600, localDate = "2026-10-12T00:00:00", startTimeUtc = "2026-10-11T16:06:22.9336343", chapters = {
|
||||||
|
{ chapterId = 17139, startTimeUtc = "2026-10-11T16:06:22.9336343", durationSeconds = 34, pagesRead = 11 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-12T00:00:00", startTimeUtc = "2026-10-11T16:00:00.7226412", chapters = {
|
||||||
|
{ chapterId = 17855, startTimeUtc = "2026-10-11T16:00:00.7226412", durationSeconds = 311, pagesRead = 39 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T15:54:42.9913657", chapters = {
|
||||||
|
{ chapterId = 17855, startTimeUtc = "2026-10-11T15:54:42.9913657", durationSeconds = 137, pagesRead = 26 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T15:16:45.9848037", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T15:16:45.9848037", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T14:54:13.613368", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T14:54:13.613368", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T14:35:43.0809755", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T14:35:43.0809755", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T12:58:29.291105", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T12:58:29.291105", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T11:00:42.6215043", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T11:00:42.6215043", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T04:17:28.3592015", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-11T04:17:28.3592015", durationSeconds = 512, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-11T00:00:00", startTimeUtc = "2026-10-11T02:53:45.4676925", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-11T02:53:45.4676925", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T15:00:59.375396", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-10T15:00:59.375396", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T09:37:25.4148239", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-10T09:37:25.4148239", durationSeconds = 2, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T08:58:13.142957", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-10T08:58:13.142957", durationSeconds = 9, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T08:15:36.7468877", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-10T08:15:36.7468877", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T07:52:18.8289612", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-10T07:52:18.8289612", durationSeconds = 164, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T07:10:45.3655221", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-10T07:10:45.3655221", durationSeconds = 33, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T04:44:42.7023417", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-10T04:44:42.7023417", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T03:55:35.74839", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-10T03:55:35.74839", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T03:41:12.3904529", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-10T03:41:12.3904529", durationSeconds = 12, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T03:39:55.2030981", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-10T03:39:55.2030981", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T02:29:21.0392738", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-10T02:29:21.0392738", durationSeconds = 40, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T02:12:18.2048535", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-10T02:12:18.2048535", durationSeconds = 53, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-10T00:00:00", startTimeUtc = "2026-10-10T01:55:30.4051153", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-10T01:55:30.4051153", durationSeconds = 50, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T14:45:39.0731175", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T14:45:39.0731175", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T13:43:07.3149178", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-09T13:43:07.3149178", durationSeconds = 5, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10735, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T13:32:16.6705302", chapters = {
|
||||||
|
{ chapterId = 18969, startTimeUtc = "2026-10-09T13:32:16.6705302", durationSeconds = 163, pagesRead = 5 } } },
|
||||||
|
{ seriesId = 10698, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T13:30:11.0145349", chapters = {
|
||||||
|
{ chapterId = 18923, startTimeUtc = "2026-10-09T13:30:11.0145349", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T13:17:56.7622935", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-09T13:17:56.7622935", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T11:51:14.1858092", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-09T11:51:14.1858092", durationSeconds = 7, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10732, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T11:20:33.6944863", chapters = {
|
||||||
|
{ chapterId = 18966, startTimeUtc = "2026-10-09T11:20:33.6944863", durationSeconds = 29, pagesRead = 21 } } },
|
||||||
|
{ seriesId = 10735, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T11:15:31.2028337", chapters = {
|
||||||
|
{ chapterId = 18969, startTimeUtc = "2026-10-09T11:15:31.2028337", durationSeconds = 80, pagesRead = 33 } } },
|
||||||
|
{ seriesId = 10724, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T11:12:30.4622536", chapters = {
|
||||||
|
{ chapterId = 18957, startTimeUtc = "2026-10-09T11:12:30.4622536", durationSeconds = 4, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T11:04:22.6125371", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-09T11:04:22.6125371", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10724, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T10:29:16.8959018", chapters = {
|
||||||
|
{ chapterId = 18957, startTimeUtc = "2026-10-09T10:29:16.8959018", durationSeconds = 7, pagesRead = 16 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T09:51:43.6940126", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-09T09:51:43.6940126", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T09:34:29.5406473", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-09T09:34:29.5406473", durationSeconds = 3, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T09:34:17.5161863", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-09T09:34:17.5161863", durationSeconds = 5, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7606, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T09:10:02.1865718", chapters = {
|
||||||
|
{ chapterId = 11501, startTimeUtc = "2026-10-09T09:10:02.1865718", durationSeconds = 759, pagesRead = 11 } } },
|
||||||
|
{ seriesId = 10708, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T08:18:07.1620583", chapters = {
|
||||||
|
{ chapterId = 18933, startTimeUtc = "2026-10-09T08:18:07.1620583", durationSeconds = 15, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 10707, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T07:55:45.2365064", chapters = {
|
||||||
|
{ chapterId = 18932, startTimeUtc = "2026-10-09T07:55:45.2365064", durationSeconds = 7, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T07:44:06.636679", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T07:44:06.636679", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T07:13:20.7857153", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T07:13:20.7857153", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T04:40:28.7189645", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T04:40:28.7189645", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T04:05:17.6951039", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-09T04:05:17.6951039", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T03:03:56.2211648", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-09T03:03:56.2211648", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9292, localDate = "2026-10-09T00:00:00", startTimeUtc = "2026-10-09T01:10:42.7539032", chapters = {
|
||||||
|
{ chapterId = 13569, startTimeUtc = "2026-10-09T01:10:42.7539032", durationSeconds = 8, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9292, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T15:26:10.3634693", chapters = {
|
||||||
|
{ chapterId = 13569, startTimeUtc = "2026-10-08T15:26:10.3634693", durationSeconds = 15, pagesRead = 10 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T15:12:20.8270779", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-08T15:12:20.8270779", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T14:34:05.7981443", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T14:34:05.7981443", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T13:12:53.6969824", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T13:12:53.6969824", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T11:49:28.3986198", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-08T11:49:28.3986198", durationSeconds = 95, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T11:48:06.6315963", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T11:48:06.6315963", durationSeconds = 544, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T10:57:20.8373954", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-08T11:15:47.102", durationSeconds = 1111, pagesRead = 0 },
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-08T10:57:20.8373954", durationSeconds = 406, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T11:02:33.6484158", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T11:02:33.6484158", durationSeconds = 611, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T10:31:08.475182", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T10:31:08.475182", durationSeconds = 3, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T09:03:45.5309711", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T09:03:45.5309711", durationSeconds = 86, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T07:59:09.2881628", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T07:59:09.2881628", durationSeconds = 263, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T07:20:18.0105615", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T07:20:18.0105615", durationSeconds = 233, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T06:48:51.312417", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T06:48:51.312417", durationSeconds = 296, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T04:42:54.7579483", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-08T04:42:54.7579483", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T04:05:45.0300961", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-08T04:05:45.0300961", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T02:52:33.5236184", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-10-08T02:52:33.5236184", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-08T00:00:00", startTimeUtc = "2026-10-08T02:20:36.4169563", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-08T02:20:36.4169563", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-07T00:00:00", startTimeUtc = "2026-10-07T13:44:15.125016", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-07T13:44:15.125016", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-07T00:00:00", startTimeUtc = "2026-10-07T09:45:01.0814021", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-07T09:45:01.0814021", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-07T00:00:00", startTimeUtc = "2026-10-07T05:19:38.9892914", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-07T05:19:38.9892914", durationSeconds = 503, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T13:00:26.371751", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-06T13:00:26.371751", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T12:21:25.7149691", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-06T12:21:25.7149691", durationSeconds = 489, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T12:07:54.0702478", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-06T12:07:54.0702478", durationSeconds = 320, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T12:01:31.4949015", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-06T12:01:31.4949015", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T11:37:48.0185472", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-06T11:37:48.0185472", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T03:21:10.9150125", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-06T03:21:10.9150125", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-06T00:00:00", startTimeUtc = "2026-10-06T02:50:29.5547188", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-06T02:50:29.5547188", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-05T00:00:00", startTimeUtc = "2026-10-05T14:10:59.8916334", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-05T14:10:59.8916334", durationSeconds = 195, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-10-05T00:00:00", startTimeUtc = "2026-10-05T12:18:33.1689018", chapters = {
|
||||||
|
{ chapterId = 11273, startTimeUtc = "2026-10-05T12:18:33.1689018", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-05T00:00:00", startTimeUtc = "2026-10-05T11:54:12.1093305", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-05T11:54:12.1093305", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-05T00:00:00", startTimeUtc = "2026-10-05T11:34:55.3786363", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-05T11:34:55.3786363", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-05T00:00:00", startTimeUtc = "2026-10-05T09:15:25.8448735", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-05T09:15:25.8448735", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-04T00:00:00", startTimeUtc = "2026-10-04T09:36:48.7199331", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-04T09:36:48.7199331", durationSeconds = 226, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-04T00:00:00", startTimeUtc = "2026-10-04T06:13:00.6097898", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-04T06:13:00.6097898", durationSeconds = 412, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-10-03T00:00:00", startTimeUtc = "2026-10-03T14:24:26.495891", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-10-03T14:24:26.495891", durationSeconds = 337, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-03T00:00:00", startTimeUtc = "2026-10-03T13:00:16.6885142", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-03T13:00:16.6885142", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10588, localDate = "2026-10-03T00:00:00", startTimeUtc = "2026-10-03T12:25:37.0931958", chapters = {
|
||||||
|
{ chapterId = 16914, startTimeUtc = "2026-10-03T12:25:37.0931958", durationSeconds = 358, pagesRead = 24 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-03T00:00:00", startTimeUtc = "2026-10-03T12:09:12.6479717", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-03T12:09:12.6479717", durationSeconds = 409, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-10-03T00:00:00", startTimeUtc = "2026-10-03T02:10:46.4251132", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-10-03T02:10:46.4251132", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-10-02T00:00:00", startTimeUtc = "2026-10-02T04:04:43.6820861", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-10-02T04:04:43.6820861", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-02T00:00:00", startTimeUtc = "2026-10-02T01:31:26.0795951", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-02T01:31:26.0795951", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-02T00:00:00", startTimeUtc = "2026-10-02T01:19:47.6481957", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-02T01:19:47.6481957", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T14:01:45.997983", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-01T14:01:45.997983", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10585, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T13:36:40.8506172", chapters = {
|
||||||
|
{ chapterId = 16862, startTimeUtc = "2026-10-01T13:36:40.8506172", durationSeconds = 113, pagesRead = 8 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T13:35:51.0806955", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-01T13:35:51.0806955", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T11:55:01.4289659", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-01T11:55:01.4289659", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T11:41:02.5910426", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-01T11:41:02.5910426", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T11:28:36.4902671", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-01T11:28:36.4902671", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T11:10:02.1536935", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-10-01T11:10:02.1536935", durationSeconds = 289, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10585, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T11:04:28.7600787", chapters = {
|
||||||
|
{ chapterId = 16862, startTimeUtc = "2026-10-01T11:04:28.7600787", durationSeconds = 241, pagesRead = 15 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-10-01T00:00:00", startTimeUtc = "2026-10-01T10:32:28.7130273", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-10-01T10:32:28.7130273", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 8661, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T13:03:27.0677663", chapters = {
|
||||||
|
{ chapterId = 12763, startTimeUtc = "2026-09-30T13:03:27.0677663", durationSeconds = 1530, pagesRead = -3 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T13:02:32.9357375", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T13:02:32.9357375", durationSeconds = 22, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T12:28:33.282795", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T12:28:33.282795", durationSeconds = 189, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 8661, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T11:37:13.1197026", chapters = {
|
||||||
|
{ chapterId = 12763, startTimeUtc = "2026-09-30T11:37:13.1197026", durationSeconds = 25, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T11:33:44.6966312", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T11:33:44.6966312", durationSeconds = 130, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T09:14:25.3316858", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T09:14:25.3316858", durationSeconds = 37, pagesRead = -4 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T08:52:37.2436808", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T08:52:37.2436808", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T07:54:07.7610298", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T07:54:07.7610298", durationSeconds = 5, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7805, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T03:56:53.2380567", chapters = {
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-09-30T03:56:53.2380567", durationSeconds = 6, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T03:42:57.6124947", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T03:42:57.6124947", durationSeconds = 1749, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T03:23:47.6591832", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T03:23:47.6591832", durationSeconds = 548, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10684, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T03:12:37.6514083", chapters = {
|
||||||
|
{ chapterId = 18895, startTimeUtc = "2026-09-30T03:12:37.6514083", durationSeconds = 68, pagesRead = 15 } } },
|
||||||
|
{ seriesId = 10556, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T01:58:37.2644751", chapters = {
|
||||||
|
{ chapterId = 16398, startTimeUtc = "2026-09-30T01:58:37.2644751", durationSeconds = 5, pagesRead = 6 } } },
|
||||||
|
{ seriesId = 7805, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T00:43:20.1361231", chapters = {
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-09-30T01:16:48.8842393", durationSeconds = 387, pagesRead = 0 },
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-09-30T00:43:20.1361231", durationSeconds = 204, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 8661, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T00:46:55.2653707", chapters = {
|
||||||
|
{ chapterId = 12763, startTimeUtc = "2026-09-30T00:46:55.2653707", durationSeconds = 1330, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T00:25:09.4803818", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-30T00:37:14.7633119", durationSeconds = 43, pagesRead = 0 },
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-30T00:25:09.4803818", durationSeconds = 32, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T00:30:04.5325361", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-30T00:30:04.5325361", durationSeconds = 222, pagesRead = -1 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-30T00:00:00", startTimeUtc = "2026-09-30T00:27:17.7123717", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-30T00:27:17.7123717", durationSeconds = 108, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 10584, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T15:27:07.2391439", chapters = {
|
||||||
|
{ chapterId = 16853, startTimeUtc = "2026-09-29T15:27:07.2391439", durationSeconds = 6, pagesRead = 6 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T15:23:24.6913136", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-29T15:23:24.6913136", durationSeconds = 51, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 10584, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T15:11:40.8997791", chapters = {
|
||||||
|
{ chapterId = 16853, startTimeUtc = "2026-09-29T15:11:40.8997791", durationSeconds = 24, pagesRead = 14 } } },
|
||||||
|
{ seriesId = 8661, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T15:10:15.9077958", chapters = {
|
||||||
|
{ chapterId = 12763, startTimeUtc = "2026-09-29T15:10:15.9077958", durationSeconds = 23, pagesRead = 6 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T15:02:32.6735695", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-29T15:02:32.6735695", durationSeconds = 452, pagesRead = 7 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T14:58:04.6106466", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-29T14:58:04.6106466", durationSeconds = 82, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T14:38:04.1555096", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-29T14:38:04.1555096", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T14:12:48.9320003", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-29T14:12:48.9320003", durationSeconds = 86, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T14:07:43.3739949", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-29T14:07:43.3739949", durationSeconds = 439, pagesRead = 20 } } },
|
||||||
|
{ seriesId = 10560, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T13:55:37.9561391", chapters = {
|
||||||
|
{ chapterId = 16493, startTimeUtc = "2026-09-29T13:55:37.9561391", durationSeconds = 0, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T12:39:52.7733874", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-29T12:39:52.7733874", durationSeconds = 31, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 10559, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T12:33:10.2857117", chapters = {
|
||||||
|
{ chapterId = 16479, startTimeUtc = "2026-09-29T12:33:10.2857117", durationSeconds = 7, pagesRead = 15 } } },
|
||||||
|
{ seriesId = 10560, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T11:51:35.4694759", chapters = {
|
||||||
|
{ chapterId = 16493, startTimeUtc = "2026-09-29T12:22:43.7993875", durationSeconds = 936, pagesRead = 2 },
|
||||||
|
{ chapterId = 16493, startTimeUtc = "2026-09-29T11:51:35.4694759", durationSeconds = 1223, pagesRead = 12 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T11:58:50.1222492", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-29T12:21:19.3748615", durationSeconds = 909, pagesRead = -2 },
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-29T11:58:50.1222492", durationSeconds = 20, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10563, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T12:17:34.2571271", chapters = {
|
||||||
|
{ chapterId = 16505, startTimeUtc = "2026-09-29T12:17:34.2571271", durationSeconds = 36, pagesRead = 17 } } },
|
||||||
|
{ seriesId = 10562, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T12:07:43.0627869", chapters = {
|
||||||
|
{ chapterId = 16502, startTimeUtc = "2026-09-29T12:07:43.0627869", durationSeconds = 70, pagesRead = 17 } } },
|
||||||
|
{ seriesId = 7910, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T11:50:25.270629", chapters = {
|
||||||
|
{ chapterId = 11904, startTimeUtc = "2026-09-29T11:50:25.270629", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7910, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T11:25:02.6769601", chapters = {
|
||||||
|
{ chapterId = 11896, startTimeUtc = "2026-09-29T11:25:16.5490822", durationSeconds = 442, pagesRead = 6 },
|
||||||
|
{ chapterId = 11898, startTimeUtc = "2026-09-29T11:25:02.6769601", durationSeconds = 328, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T11:24:52.8021347", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-29T11:24:52.8021347", durationSeconds = 525, pagesRead = 15 } } },
|
||||||
|
{ seriesId = 10639, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T11:08:39.2618986", chapters = {
|
||||||
|
{ chapterId = 18031, startTimeUtc = "2026-09-29T11:08:39.2618986", durationSeconds = 0, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 10556, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:56:40.6001656", chapters = {
|
||||||
|
{ chapterId = 16398, startTimeUtc = "2026-09-29T10:56:40.6001656", durationSeconds = 11, pagesRead = 9 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:45:47.6455857", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-29T10:45:47.6455857", durationSeconds = 4, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7462, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:45:05.5896105", chapters = {
|
||||||
|
{ chapterId = 11290, startTimeUtc = "2026-09-29T10:45:05.5896105", durationSeconds = 3, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:35:52.0518521", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-29T10:35:52.0518521", durationSeconds = 39, pagesRead = 6 } } },
|
||||||
|
{ seriesId = 7805, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:34:39.8658599", chapters = {
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-09-29T10:34:39.8658599", durationSeconds = 12, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:25:25.4088288", chapters = {
|
||||||
|
{ chapterId = 11271, startTimeUtc = "2026-09-29T10:25:25.4088288", durationSeconds = 86, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 10004, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:22:33.7903381", chapters = {
|
||||||
|
{ chapterId = 14594, startTimeUtc = "2026-09-29T10:22:33.7903381", durationSeconds = 167, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7453, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T10:01:44.7835505", chapters = {
|
||||||
|
{ chapterId = 11271, startTimeUtc = "2026-09-29T10:01:44.7835505", durationSeconds = 230, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10001, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T09:57:30.1875022", chapters = {
|
||||||
|
{ chapterId = 14591, startTimeUtc = "2026-09-29T09:57:30.1875022", durationSeconds = 14, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T09:39:33.8232177", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-29T09:39:33.8232177", durationSeconds = 332, pagesRead = 19 } } },
|
||||||
|
{ seriesId = 7476, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T09:30:15.0902649", chapters = {
|
||||||
|
{ chapterId = 11317, startTimeUtc = "2026-09-29T09:30:15.0902649", durationSeconds = 27, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7476, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T09:02:28.8339509", chapters = {
|
||||||
|
{ chapterId = 11317, startTimeUtc = "2026-09-29T09:02:28.8339509", durationSeconds = 267, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10004, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T08:51:39.2655404", chapters = {
|
||||||
|
{ chapterId = 14594, startTimeUtc = "2026-09-29T08:51:39.2655404", durationSeconds = 39, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10004, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T08:33:15.8755207", chapters = {
|
||||||
|
{ chapterId = 14594, startTimeUtc = "2026-09-29T08:33:15.8755207", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10004, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T08:14:10.4993494", chapters = {
|
||||||
|
{ chapterId = 14594, startTimeUtc = "2026-09-29T08:14:10.4993494", durationSeconds = 106, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7476, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T07:47:38.8544242", chapters = {
|
||||||
|
{ chapterId = 11317, startTimeUtc = "2026-09-29T08:02:48.272453", durationSeconds = 461, pagesRead = -1 },
|
||||||
|
{ chapterId = 11317, startTimeUtc = "2026-09-29T07:47:38.8544242", durationSeconds = 39, pagesRead = 7 } } },
|
||||||
|
{ seriesId = 7452, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T07:51:52.786463", chapters = {
|
||||||
|
{ chapterId = 11269, startTimeUtc = "2026-09-29T07:51:52.786463", durationSeconds = 365, pagesRead = 115 } } },
|
||||||
|
{ seriesId = 10042, localDate = "2026-09-29T00:00:00", startTimeUtc = "2026-09-29T07:39:42.880422", chapters = {
|
||||||
|
{ chapterId = 14638, startTimeUtc = "2026-09-29T07:39:42.880422", durationSeconds = 50, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-28T00:00:00", startTimeUtc = "2026-09-28T09:16:47.6382365", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-28T09:16:47.6382365", durationSeconds = 59, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9158, localDate = "2026-09-28T00:00:00", startTimeUtc = "2026-09-27T17:16:38.7193514", chapters = {
|
||||||
|
{ chapterId = 13395, startTimeUtc = "2026-09-27T17:16:38.7193514", durationSeconds = 29, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 10683, localDate = "2026-09-28T00:00:00", startTimeUtc = "2026-09-27T17:13:53.8061535", chapters = {
|
||||||
|
{ chapterId = 18893, startTimeUtc = "2026-09-27T17:13:53.8061535", durationSeconds = 16, pagesRead = -1 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-27T00:00:00", startTimeUtc = "2026-09-27T15:13:47.085122", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-27T15:13:47.085122", durationSeconds = 746, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-27T00:00:00", startTimeUtc = "2026-09-27T13:34:49.3907937", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-27T13:34:49.3907937", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-27T00:00:00", startTimeUtc = "2026-09-27T13:03:53.8173515", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-27T13:03:53.8173515", durationSeconds = 9, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-27T00:00:00", startTimeUtc = "2026-09-27T09:21:25.6490847", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-27T09:21:25.6490847", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-27T00:00:00", startTimeUtc = "2026-09-27T09:03:41.6524393", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-27T09:03:41.6524393", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-27T00:00:00", startTimeUtc = "2026-09-27T01:38:10.6211012", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-27T01:38:10.6211012", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7540, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T15:13:21.9970834", chapters = {
|
||||||
|
{ chapterId = 13394, startTimeUtc = "2026-09-26T15:13:21.9970834", durationSeconds = 14, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 8110, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T14:58:04.4305334", chapters = {
|
||||||
|
{ chapterId = 12126, startTimeUtc = "2026-09-26T14:58:04.4305334", durationSeconds = 181, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 8110, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T14:37:55.4114027", chapters = {
|
||||||
|
{ chapterId = 12126, startTimeUtc = "2026-09-26T14:37:55.4114027", durationSeconds = 55, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T14:33:39.6298963", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-26T14:33:39.6298963", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T14:19:48.5269015", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-26T14:19:48.5269015", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10676, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T13:34:15.9269344", chapters = {
|
||||||
|
{ chapterId = 18818, startTimeUtc = "2026-09-26T13:34:15.9269344", durationSeconds = 1021, pagesRead = 54 } } },
|
||||||
|
{ seriesId = 10676, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T12:08:23.540117", chapters = {
|
||||||
|
{ chapterId = 18818, startTimeUtc = "2026-09-26T12:08:23.540117", durationSeconds = 107, pagesRead = 11 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T12:07:39.7719041", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-26T12:07:39.7719041", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T01:55:50.078051", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-26T01:55:50.078051", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T01:32:58.4149147", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-26T01:32:58.4149147", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-26T00:00:00", startTimeUtc = "2026-09-26T01:13:02.4223873", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-26T01:13:02.4223873", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9110, localDate = "2026-09-25T00:00:00", startTimeUtc = "2026-09-25T14:23:56.0117314", chapters = {
|
||||||
|
{ chapterId = 13318, startTimeUtc = "2026-09-25T14:23:56.0117314", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9110, localDate = "2026-09-25T00:00:00", startTimeUtc = "2026-09-25T13:59:56.4928672", chapters = {
|
||||||
|
{ chapterId = 13318, startTimeUtc = "2026-09-25T13:59:56.4928672", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9110, localDate = "2026-09-25T00:00:00", startTimeUtc = "2026-09-25T07:58:26.2227579", chapters = {
|
||||||
|
{ chapterId = 13318, startTimeUtc = "2026-09-25T07:58:26.2227579", durationSeconds = 3, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 8110, localDate = "2026-09-25T00:00:00", startTimeUtc = "2026-09-25T07:08:30.8014023", chapters = {
|
||||||
|
{ chapterId = 12126, startTimeUtc = "2026-09-25T07:08:30.8014023", durationSeconds = 7, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-25T00:00:00", startTimeUtc = "2026-09-25T01:28:12.7465578", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-25T01:28:12.7465578", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10663, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T14:34:51.9798262", chapters = {
|
||||||
|
{ chapterId = 18514, startTimeUtc = "2026-09-24T14:34:51.9798262", durationSeconds = 59, pagesRead = 10 } } },
|
||||||
|
{ seriesId = 10682, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T14:00:55.5695168", chapters = {
|
||||||
|
{ chapterId = 18889, startTimeUtc = "2026-09-24T14:00:55.5695168", durationSeconds = 65, pagesRead = 8 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T13:41:48.3170857", chapters = {
|
||||||
|
{ chapterId = 17855, startTimeUtc = "2026-09-24T13:41:48.3170857", durationSeconds = 328, pagesRead = 65 } } },
|
||||||
|
{ seriesId = 10663, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T12:55:37.0956115", chapters = {
|
||||||
|
{ chapterId = 18514, startTimeUtc = "2026-09-24T12:55:37.0956115", durationSeconds = 44, pagesRead = 8 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T12:54:21.9067307", chapters = {
|
||||||
|
{ chapterId = 17855, startTimeUtc = "2026-09-24T12:54:21.9067307", durationSeconds = 8, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 10634, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T11:36:17.6978208", chapters = {
|
||||||
|
{ chapterId = 17855, startTimeUtc = "2026-09-24T11:36:17.6978208", durationSeconds = 56, pagesRead = 14 } } },
|
||||||
|
{ seriesId = 10682, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T09:54:25.899822", chapters = {
|
||||||
|
{ chapterId = 18889, startTimeUtc = "2026-09-24T09:54:25.899822", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 10674, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T09:27:10.4132213", chapters = {
|
||||||
|
{ chapterId = 18789, startTimeUtc = "2026-09-24T09:27:10.4132213", durationSeconds = 8, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T07:47:32.97548", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-24T07:47:32.97548", durationSeconds = 461, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T07:26:01.1542479", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-24T07:26:01.1542479", durationSeconds = 146, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9095, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-24T06:46:54.4314754", chapters = {
|
||||||
|
{ chapterId = 13282, startTimeUtc = "2026-09-24T06:46:54.4314754", durationSeconds = 0, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 9649, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-23T16:09:03.1098014", chapters = {
|
||||||
|
{ chapterId = 14126, startTimeUtc = "2026-09-23T16:09:03.1098014", durationSeconds = 4, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-24T00:00:00", startTimeUtc = "2026-09-23T16:05:48.0362145", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-23T16:05:48.0362145", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-23T00:00:00", startTimeUtc = "2026-09-23T13:47:22.8458997", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-23T13:47:22.8458997", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 8137, localDate = "2026-09-23T00:00:00", startTimeUtc = "2026-09-23T05:52:39.9019755", chapters = {
|
||||||
|
{ chapterId = 12159, startTimeUtc = "2026-09-23T05:52:39.9019755", durationSeconds = 79, pagesRead = 18 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-23T00:00:00", startTimeUtc = "2026-09-23T03:51:46.3681335", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-23T03:51:46.3681335", durationSeconds = 327, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9262, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T13:38:38.3358566", chapters = {
|
||||||
|
{ chapterId = 13508, startTimeUtc = "2026-09-22T13:38:38.3358566", durationSeconds = 52, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T13:22:52.4340931", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-22T13:22:52.4340931", durationSeconds = 5, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T10:28:46.3070635", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-22T10:28:46.3070635", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T09:53:02.9688203", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-22T09:53:02.9688203", durationSeconds = 515, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 9257, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T09:45:09.829169", chapters = {
|
||||||
|
{ chapterId = 13503, startTimeUtc = "2026-09-22T09:45:09.829169", durationSeconds = 5, pagesRead = 11 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T08:59:44.2021935", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-22T08:59:44.2021935", durationSeconds = 85, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T08:57:31.3039746", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-22T08:57:31.3039746", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T08:34:21.7362395", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-22T08:34:21.7362395", durationSeconds = 697, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9249, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T08:00:48.3941463", chapters = {
|
||||||
|
{ chapterId = 13493, startTimeUtc = "2026-09-22T08:00:48.3941463", durationSeconds = 149, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 9180, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T03:13:37.560087", chapters = {
|
||||||
|
{ chapterId = 13420, startTimeUtc = "2026-09-22T03:13:37.560087", durationSeconds = 11, pagesRead = 7 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-22T00:00:00", startTimeUtc = "2026-09-22T02:24:02.4880326", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-22T02:24:02.4880326", durationSeconds = 163, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-21T00:00:00", startTimeUtc = "2026-09-21T13:24:04.9528675", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-21T13:24:04.9528675", durationSeconds = 307, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7805, localDate = "2026-09-21T00:00:00", startTimeUtc = "2026-09-21T13:07:31.7048466", chapters = {
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-09-21T13:07:31.7048466", durationSeconds = 8, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 8661, localDate = "2026-09-21T00:00:00", startTimeUtc = "2026-09-21T13:04:31.936106", chapters = {
|
||||||
|
{ chapterId = 12763, startTimeUtc = "2026-09-21T13:04:31.936106", durationSeconds = 84, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 8661, localDate = "2026-09-21T00:00:00", startTimeUtc = "2026-09-21T10:07:50.9423535", chapters = {
|
||||||
|
{ chapterId = 12763, startTimeUtc = "2026-09-21T10:07:50.9423535", durationSeconds = 563, pagesRead = 5 } } },
|
||||||
|
{ seriesId = 7805, localDate = "2026-09-21T00:00:00", startTimeUtc = "2026-09-21T09:56:54.7828239", chapters = {
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-09-21T09:56:54.7828239", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 9110, localDate = "2026-09-21T00:00:00", startTimeUtc = "2026-09-21T04:49:43.5918775", chapters = {
|
||||||
|
{ chapterId = 13318, startTimeUtc = "2026-09-21T04:49:43.5918775", durationSeconds = 207, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7603, localDate = "2026-09-21T00:00:00", startTimeUtc = "2026-09-21T04:49:04.8491169", chapters = {
|
||||||
|
{ chapterId = 11484, startTimeUtc = "2026-09-21T04:49:04.8491169", durationSeconds = 6, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7603, localDate = "2026-09-21T00:00:00", startTimeUtc = "2026-09-21T03:38:08.3558687", chapters = {
|
||||||
|
{ chapterId = 11484, startTimeUtc = "2026-09-21T03:38:08.3558687", durationSeconds = 8, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 8247, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T14:14:20.693305", chapters = {
|
||||||
|
{ chapterId = 12300, startTimeUtc = "2026-09-20T14:14:20.693305", durationSeconds = 86, pagesRead = 6 } } },
|
||||||
|
{ seriesId = 8281, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T14:11:24.8897015", chapters = {
|
||||||
|
{ chapterId = 12334, startTimeUtc = "2026-09-20T14:11:24.8897015", durationSeconds = 25, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7476, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T13:17:19.1246015", chapters = {
|
||||||
|
{ chapterId = 11317, startTimeUtc = "2026-09-20T13:17:19.1246015", durationSeconds = 34, pagesRead = 7 } } },
|
||||||
|
{ seriesId = 7805, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T13:07:24.1160188", chapters = {
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-09-20T13:07:24.1160188", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 8310, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T09:52:07.5117003", chapters = {
|
||||||
|
{ chapterId = 12363, startTimeUtc = "2026-09-20T09:52:07.5117003", durationSeconds = 671, pagesRead = 3 } } },
|
||||||
|
{ seriesId = 8310, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T09:32:51.5623005", chapters = {
|
||||||
|
{ chapterId = 12363, startTimeUtc = "2026-09-20T09:32:51.5623005", durationSeconds = 364, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 8106, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T08:11:17.3798059", chapters = {
|
||||||
|
{ chapterId = 12122, startTimeUtc = "2026-09-20T08:11:17.3798059", durationSeconds = 35, pagesRead = 5 } } },
|
||||||
|
{ seriesId = 7510, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T07:50:30.9737641", chapters = {
|
||||||
|
{ chapterId = 11360, startTimeUtc = "2026-09-20T07:50:30.9737641", durationSeconds = 19, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7805, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T07:47:25.7922257", chapters = {
|
||||||
|
{ chapterId = 11791, startTimeUtc = "2026-09-20T07:47:25.7922257", durationSeconds = 3, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T07:25:56.7820012", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-20T07:25:56.7820012", durationSeconds = 427, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T07:01:03.0337544", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-20T07:01:03.0337544", durationSeconds = 311, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T04:37:11.2011378", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-20T04:37:11.2011378", durationSeconds = 407, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7460, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T04:29:53.9882097", chapters = {
|
||||||
|
{ chapterId = 11285, startTimeUtc = "2026-09-20T04:29:53.9882097", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-20T00:00:00", startTimeUtc = "2026-09-20T03:23:39.822214", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-20T03:23:39.822214", durationSeconds = 431, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T14:37:14.3112506", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T14:37:14.3112506", durationSeconds = 460, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T14:16:12.9574126", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T14:16:12.9574126", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T13:33:23.8175739", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T13:33:23.8175739", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T13:01:57.6991072", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T13:01:57.6991072", durationSeconds = 102, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T10:51:52.8573558", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T10:51:52.8573558", durationSeconds = 445, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T09:58:37.3332857", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T09:58:37.3332857", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T06:19:27.9750172", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T06:19:27.9750172", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T05:44:36.041471", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T05:44:36.041471", durationSeconds = 500, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T05:08:30.2036102", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T05:08:30.2036102", durationSeconds = 263, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7560, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T04:47:13.2207635", chapters = {
|
||||||
|
{ chapterId = 11430, startTimeUtc = "2026-09-19T04:47:13.2207635", durationSeconds = 1, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7556, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T04:07:25.0646351", chapters = {
|
||||||
|
{ chapterId = 11426, startTimeUtc = "2026-09-19T04:07:25.0646351", durationSeconds = 0, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7561, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T03:29:58.6171005", chapters = {
|
||||||
|
{ chapterId = 11438, startTimeUtc = "2026-09-19T03:29:58.6171005", durationSeconds = 5, pagesRead = 4 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T02:37:58.1533148", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T02:37:58.1533148", durationSeconds = 524, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-19T00:00:00", startTimeUtc = "2026-09-19T02:00:00.8956888", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-19T02:00:00.8956888", durationSeconds = 524, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-18T00:00:00", startTimeUtc = "2026-09-18T13:54:08.9566107", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-18T13:54:08.9566107", durationSeconds = 174, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-18T00:00:00", startTimeUtc = "2026-09-18T12:53:09.8665339", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-18T12:53:09.8665339", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-18T00:00:00", startTimeUtc = "2026-09-18T09:50:06.0469366", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-18T09:50:06.0469366", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-18T00:00:00", startTimeUtc = "2026-09-18T09:25:33.4181389", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-18T09:25:33.4181389", durationSeconds = 738, pagesRead = 1 } } },
|
||||||
|
{ seriesId = 7490, localDate = "2026-09-18T00:00:00", startTimeUtc = "2026-09-18T07:52:05.2045118", chapters = {
|
||||||
|
{ chapterId = 11335, startTimeUtc = "2026-09-18T07:52:05.2045118", durationSeconds = 6, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7476, localDate = "2026-09-18T00:00:00", startTimeUtc = "2026-09-18T06:59:54.0156885", chapters = {
|
||||||
|
{ chapterId = 11317, startTimeUtc = "2026-09-18T06:59:54.0156885", durationSeconds = 2, pagesRead = 2 } } },
|
||||||
|
{ seriesId = 7461, localDate = "2026-09-18T00:00:00", startTimeUtc = "2026-09-18T06:47:37.6019707", chapters = {
|
||||||
|
{ chapterId = 11312, startTimeUtc = "2026-09-18T06:47:37.6019707", durationSeconds = 0, pagesRead = 0 } } },
|
||||||
|
}
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
--[[--
|
||||||
|
moonsource_kavita.kamare_update:kamare 目标描述(只问 api.github.com、探测已装版本、装到 kamare 目录)。流程本身由 features.update 的 spec 覆盖。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.kamare_update_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
|
||||||
|
local shown, closed, ticks = {}, {}, {}
|
||||||
|
local restarted = 0
|
||||||
|
package.preload["ui/uimanager"] = function()
|
||||||
|
return {
|
||||||
|
nextTick = function(_, fn) ticks[#ticks + 1] = fn end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
local function flush()
|
||||||
|
while #ticks > 0 do table.remove(ticks, 1)() end
|
||||||
|
end
|
||||||
|
local connected = true
|
||||||
|
package.preload["ui/network/manager"] = function()
|
||||||
|
return { isConnected = function() return connected end }
|
||||||
|
end
|
||||||
|
package.preload["json"] = function()
|
||||||
|
return { decode = function(value) return value end }
|
||||||
|
end
|
||||||
|
package.preload["utils.log"] = function()
|
||||||
|
return { warn = function() end, dbg = function() end, info = function() end }
|
||||||
|
end
|
||||||
|
package.preload["utils.paths"] = function()
|
||||||
|
return {
|
||||||
|
ensureDir = function() return true end,
|
||||||
|
root = function() return "/tmp" end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 探测结果与安装根目录由用例控制。
|
||||||
|
local probe_result = { ok = false, state = "missing" }
|
||||||
|
local plugins_dir = "/fake/plugins"
|
||||||
|
package.preload["moonsource_kavita.cache"] = function()
|
||||||
|
return {
|
||||||
|
probe = function() return probe_result end,
|
||||||
|
pluginsDir = function() return plugins_dir end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function dialogModule()
|
||||||
|
return {
|
||||||
|
new = function(_, opts)
|
||||||
|
function opts:show() shown[#shown + 1] = self end
|
||||||
|
function opts:close() closed[#closed + 1] = self end
|
||||||
|
return opts
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["ui.themes.widgets.text_viewer"] = dialogModule
|
||||||
|
package.preload["ui.themes.widgets.toast"] = dialogModule
|
||||||
|
package.preload["ui.themes.widgets.progress_dialog"] = function()
|
||||||
|
return {
|
||||||
|
new = function(_, opts)
|
||||||
|
function opts:show() shown[#shown + 1] = self end
|
||||||
|
function opts:close() closed[#closed + 1] = self end
|
||||||
|
function opts:bytes(done, total)
|
||||||
|
self.progress, self.progress_max = done, total
|
||||||
|
end
|
||||||
|
function opts:set(text, percent)
|
||||||
|
self.status, self.percent = text, percent
|
||||||
|
end
|
||||||
|
return opts
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local check_cbs, gets = {}, 0
|
||||||
|
local download_cb, download_opts
|
||||||
|
package.preload["http.request"] = function()
|
||||||
|
return {
|
||||||
|
get = function(url, _, cb)
|
||||||
|
gets = gets + 1
|
||||||
|
check_cbs[#check_cbs + 1] = { url = url, cb = cb }
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
download = function(opts, _, cb)
|
||||||
|
download_opts, download_cb = opts, cb
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
local pick_calls = 0
|
||||||
|
package.preload["http.github"] = function()
|
||||||
|
return {
|
||||||
|
pickRelease = function(release, cb)
|
||||||
|
pick_calls = pick_calls + 1
|
||||||
|
cb(release.url)
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local job_opts, job_worker
|
||||||
|
package.preload["workers.job"] = function()
|
||||||
|
return {
|
||||||
|
run = function(worker, opts)
|
||||||
|
job_worker, job_opts = worker, opts
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
local install_args
|
||||||
|
package.preload["utils.plugin_install"] = function()
|
||||||
|
return {
|
||||||
|
run = function(archive, parent, sha, opts)
|
||||||
|
install_args = { archive = archive, parent = parent, sha = sha, opts = opts }
|
||||||
|
return true, "kamare.koplugin"
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["utils.restart"] = function()
|
||||||
|
return { now = function() restarted = restarted + 1 end }
|
||||||
|
end
|
||||||
|
|
||||||
|
local Kamare = require("moonsource_kavita.kamare_update")
|
||||||
|
|
||||||
|
local hash = string.rep("a", 64)
|
||||||
|
local direct = "https://github.com/backtracker/kamare.koplugin/releases/download/v0.10.4/kamare.koplugin.zip"
|
||||||
|
local function release(tag, digest)
|
||||||
|
local asset = {
|
||||||
|
name = "kamare.koplugin.zip",
|
||||||
|
browser_download_url = "https://github.com/backtracker/kamare.koplugin/releases/download/"
|
||||||
|
.. tag .. "/kamare.koplugin.zip",
|
||||||
|
size = 2048,
|
||||||
|
}
|
||||||
|
if digest ~= false then asset.digest = "sha256:" .. hash end
|
||||||
|
return { tag_name = tag, body = "## 新增\n\n- **蓝牙翻页器**\n", assets = { asset } }
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return table|nil, any
|
||||||
|
local function check(response)
|
||||||
|
local got, got_err
|
||||||
|
check_cbs = {}
|
||||||
|
Kamare:check(function(r, e) got, got_err = r, e end)
|
||||||
|
for _idx, entry in ipairs(check_cbs) do entry.cb(response) end
|
||||||
|
flush()
|
||||||
|
return got, got_err
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 版本和 digest 先问 api.ankio.net 的转发。
|
||||||
|
check_cbs = {}
|
||||||
|
Kamare:check(function() end)
|
||||||
|
Assert.eq(#check_cbs, 1)
|
||||||
|
Assert.eq(check_cbs[1].url, "https://api.ankio.net/gh/repos/backtracker/kamare.koplugin/releases/latest")
|
||||||
|
check_cbs[1].cb(release("v0.10.4"))
|
||||||
|
flush()
|
||||||
|
|
||||||
|
-- 已装版本来自探测;没装 / 官方版同版本也要提示安装。
|
||||||
|
probe_result = { ok = true, state = "enhanced", version = "0.10.4-dev" }
|
||||||
|
local parsed = check(release("v0.10.4"))
|
||||||
|
Assert.eq(parsed.installed, "0.10.4-dev")
|
||||||
|
Assert.eq(parsed.sha256, hash)
|
||||||
|
Assert.is_true(parsed.available, "开发版低于同号正式版")
|
||||||
|
probe_result = { ok = true, state = "enhanced", version = "0.10.4" }
|
||||||
|
Assert.is_false(check(release("v0.10.4")).available)
|
||||||
|
probe_result = { ok = false, state = "official", version = "0.10.4" }
|
||||||
|
Assert.is_true(check(release("v0.10.4")).available)
|
||||||
|
Assert.is_nil(check(release("v0.10.4", false)).sha256, "kamare 的 digest 可选")
|
||||||
|
|
||||||
|
-- 已是最新:toast 带 kamare 前缀;没装:安装提示。
|
||||||
|
local function startCheck(response)
|
||||||
|
shown, closed = {}, {}
|
||||||
|
check_cbs = {}
|
||||||
|
Kamare:manualCheck(nil)
|
||||||
|
for _idx, entry in ipairs(check_cbs) do entry.cb(response) end
|
||||||
|
flush()
|
||||||
|
end
|
||||||
|
probe_result = { ok = true, state = "enhanced", version = "0.10.4" }
|
||||||
|
startCheck(release("v0.10.4"))
|
||||||
|
Assert.matches(shown[#shown].text, "已是最新版本(kamare 0%.10%.4)")
|
||||||
|
probe_result = { ok = false, state = "missing" }
|
||||||
|
startCheck(release("v0.10.4"))
|
||||||
|
local prompt = shown[#shown]
|
||||||
|
Assert.eq(prompt.title, "更新 kamare")
|
||||||
|
Assert.matches(prompt.text, "当前未安装可用的 kamare 增强版")
|
||||||
|
|
||||||
|
-- 装到 kamare 当前所在目录,带目录名;没有 digest 只直连。
|
||||||
|
plugins_dir = "/mnt/us/koreader/plugins"
|
||||||
|
prompt.buttons[2].callback()
|
||||||
|
Assert.eq(download_opts.url, direct)
|
||||||
|
download_cb(true)
|
||||||
|
job_worker()
|
||||||
|
Assert.eq(install_args.sha, hash)
|
||||||
|
Assert.eq(install_args.opts.name, "kamare.koplugin")
|
||||||
|
Assert.eq(install_args.parent, plugins_dir)
|
||||||
|
job_opts.on_done()
|
||||||
|
flush()
|
||||||
|
Assert.eq(restarted, 1)
|
||||||
|
|
||||||
|
local nosha = check(release("v0.10.4", false))
|
||||||
|
pick_calls = 0
|
||||||
|
Kamare:install(nosha, nil, function() end)
|
||||||
|
Assert.eq(pick_calls, 0, "没有 digest 不走镜像")
|
||||||
|
|
||||||
|
return true
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita 一次性迁移:卷行继承容器元数据并退出书架。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.migration_spec
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
|
||||||
|
local db_path = Config.dir() .. "/kavita_migration_spec.sqlite3"
|
||||||
|
local state_path = Config.dir() .. "/settings/moonsource_kavita_meta.lua"
|
||||||
|
for _idx, suffix in ipairs({ "", "-wal", "-shm" }) do os.remove(db_path .. suffix) end
|
||||||
|
for _idx, suffix in ipairs({ "", ".old" }) do os.remove(state_path .. suffix) end
|
||||||
|
|
||||||
|
package.loaded["utils.paths"] = nil
|
||||||
|
package.preload["utils.paths"] = function()
|
||||||
|
return { dbPath = function() return db_path end, ensureSettings = function() end,
|
||||||
|
sanitizeSourceId = function(id) return id end }
|
||||||
|
end
|
||||||
|
|
||||||
|
local DB = require("utils.db")
|
||||||
|
require("book.books_db")
|
||||||
|
Assert.not_nil(DB.open())
|
||||||
|
|
||||||
|
local function insert(source_id, stable_id, authors, intro, deleted, sync_status, path)
|
||||||
|
Assert.is_true(DB.exec([[
|
||||||
|
INSERT INTO books (source_id, stable_id, title, authors, intro, deleted, sync_status, path)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
||||||
|
]], source_id, stable_id, "书 " .. stable_id, authors, intro, deleted, sync_status, path))
|
||||||
|
end
|
||||||
|
|
||||||
|
insert("kavita", "10", "容器作者", "容器简介", 0, 1, nil)
|
||||||
|
insert("kavita", "10:100", nil, "", 0, 0, "/books/volume.epub")
|
||||||
|
insert("kavita", "10:101", "卷作者", "卷简介", 0, 0, nil)
|
||||||
|
insert("kavita", "10:102", nil, nil, 1, 0, nil)
|
||||||
|
insert("other", "10:100", nil, "", 0, 0, nil)
|
||||||
|
|
||||||
|
local cfg = { base_url = "http://kavita/", api_key = "key" }
|
||||||
|
package.loaded["utils.settings"] = {
|
||||||
|
getSource = function() return cfg end,
|
||||||
|
saveSource = function() end,
|
||||||
|
}
|
||||||
|
package.loaded["source.base"] = {
|
||||||
|
loadMeta = function(id) return { id = id, name = "Kavita", type = "book" } end,
|
||||||
|
capabilities = function() return {} end,
|
||||||
|
defer = function(_self, cb, ...)
|
||||||
|
local args = { ... }
|
||||||
|
cb(unpack(args))
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
package.loaded["moonsource_kavita.client"] = { new = function(options) return options end }
|
||||||
|
package.loaded["moonsource_kavita.annotation"] = {}
|
||||||
|
package.loaded["moonsource_kavita.position"] = {}
|
||||||
|
package.loaded["moonsource_kavita.stats"] = {}
|
||||||
|
package.loaded["moonsource_kavita.cache"] = { resetShelf = function() end }
|
||||||
|
package.loaded["moonsource_kavita.volume_list"] = {}
|
||||||
|
package.loaded["book.note.normalize"] = {}
|
||||||
|
|
||||||
|
local Source = dofile((debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita") .. "/source.lua")
|
||||||
|
Source.new()
|
||||||
|
|
||||||
|
local function row(source_id, stable_id)
|
||||||
|
local authors, intro, deleted, sync_status, path = DB.rowexec([[
|
||||||
|
SELECT authors, intro, deleted, sync_status, path FROM books
|
||||||
|
WHERE source_id=? AND stable_id=?;
|
||||||
|
]], source_id, stable_id)
|
||||||
|
return authors, intro, tonumber(deleted), tonumber(sync_status), path
|
||||||
|
end
|
||||||
|
|
||||||
|
local authors, intro, deleted, sync_status, path = row("kavita", "10:100")
|
||||||
|
Assert.eq(authors, "容器作者")
|
||||||
|
Assert.eq(intro, "容器简介")
|
||||||
|
Assert.eq(deleted, 1, "卷行从书架隐藏")
|
||||||
|
Assert.eq(sync_status, 1, "迁移后的远端卷行标为已同步")
|
||||||
|
Assert.eq(path, "/books/volume.epub", "保留已下载文件路径")
|
||||||
|
|
||||||
|
authors, intro, deleted, sync_status = row("kavita", "10:101")
|
||||||
|
Assert.eq(authors, "卷作者", "保留已有作者")
|
||||||
|
Assert.eq(intro, "卷简介", "保留已有简介")
|
||||||
|
Assert.eq(deleted, 1, "所有旧卷行都从书架隐藏")
|
||||||
|
Assert.eq(sync_status, 1)
|
||||||
|
|
||||||
|
authors, intro, deleted, sync_status = row("kavita", "10:102")
|
||||||
|
Assert.eq(authors, "容器作者", "已隐藏卷行也补齐元数据")
|
||||||
|
Assert.eq(intro, "容器简介")
|
||||||
|
Assert.eq(deleted, 1)
|
||||||
|
Assert.eq(sync_status, 0, "不改原本已隐藏行的脏状态")
|
||||||
|
|
||||||
|
authors, intro, deleted = row("other", "10:100")
|
||||||
|
Assert.is_nil(authors, "迁移只影响 Kavita")
|
||||||
|
Assert.eq(intro, "")
|
||||||
|
Assert.eq(deleted, 0)
|
||||||
|
|
||||||
|
local state = require("luasettings"):open(
|
||||||
|
require("datastorage"):getSettingsDir() .. "/moonsource_kavita_meta.lua")
|
||||||
|
Assert.eq(tonumber(state:readSetting("schema_version")), 1)
|
||||||
|
|
||||||
|
insert("kavita", "10:103", nil, nil, 0, 0, nil)
|
||||||
|
Source.new()
|
||||||
|
local _, _, still_visible = row("kavita", "10:103")
|
||||||
|
Assert.eq(still_visible, 0, "schema_version 阻止重复迁移")
|
||||||
|
|
||||||
|
DB.close()
|
||||||
|
for _idx, suffix in ipairs({ "", "-wal", "-shm" }) do os.remove(db_path .. suffix) end
|
||||||
|
for _idx, suffix in ipairs({ "", ".old" }) do os.remove(state_path .. suffix) end
|
||||||
|
|
||||||
|
return true
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
--[[--
|
||||||
|
extensions/moonsource-kavita.koplugin 首页组件 On Deck:在线且已配置才拉,5 分钟内复用;
|
||||||
|
两行 × 5 列封面网格(网格尺寸走 CoverCell.denseCoverMetrics / Book.widget,同首页最近阅读),
|
||||||
|
点开走月读开书;失败 / 空列表 / 离线给提示。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.on_deck_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
local Kit = require("support.widget_stubs")
|
||||||
|
Kit.install("paper")
|
||||||
|
local Themed = require("support.theme_stubs")
|
||||||
|
Themed.install()
|
||||||
|
local Widget = require("ui/widget/widget")
|
||||||
|
|
||||||
|
local TITLE_EXTRA = 26
|
||||||
|
local covers = {}
|
||||||
|
package.preload["ui.widgets.book"] = function()
|
||||||
|
return {
|
||||||
|
captionExtra = function(show_title) return show_title ~= false and TITLE_EXTRA or 0 end,
|
||||||
|
widget = function(_plugin, _source, book, cw, ch, opts)
|
||||||
|
local slot_w = (opts and opts.slot_w) or cw
|
||||||
|
covers[#covers + 1] = { book = book, w = cw, h = ch, slot_w = slot_w, home = opts and opts.home }
|
||||||
|
return Widget:new{ dimen = { w = slot_w, h = ch + TITLE_EXTRA } }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["ui.widgets.cover"] = function()
|
||||||
|
return {
|
||||||
|
gridCoverMaxH = function() return 320 end,
|
||||||
|
denseCoverMetrics = function(w, _budget, opts)
|
||||||
|
local cols = opts.min_cols or 5
|
||||||
|
local gap, row_gap = 8, 10
|
||||||
|
local slot_w = math.max(1, math.floor((w - gap * (cols - 1)) / cols))
|
||||||
|
local cw = slot_w
|
||||||
|
local ch = math.min(math.floor(cw * 3 / 2), opts.max_h or 320)
|
||||||
|
return slot_w, cw, ch, cols, gap, row_gap, ch + opts.title_extra
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
local opened = {}
|
||||||
|
package.preload["desktop.open"] = function()
|
||||||
|
return { book = function(_plugin, book) opened[#opened + 1] = book end }
|
||||||
|
end
|
||||||
|
|
||||||
|
local online, configured = true, true
|
||||||
|
package.loaded["ui/network/manager"] = { isConnected = function() return online end }
|
||||||
|
local calls, reply = {}, nil
|
||||||
|
local source = {
|
||||||
|
configured = function() return configured end,
|
||||||
|
client = {
|
||||||
|
json = function(_self, method, path, query, body, cb)
|
||||||
|
calls[#calls + 1] = { method = method, path = path, query = query, body = body }
|
||||||
|
reply = cb
|
||||||
|
return { cancel = function() reply = nil end }
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
package.loaded["source.registry"] = { resolve = function(id) return id == "kavita" and source or nil end }
|
||||||
|
|
||||||
|
local Deck = dofile((debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita") .. "/on_deck.lua")
|
||||||
|
Assert.eq(Deck.id, "kavita.on_deck")
|
||||||
|
|
||||||
|
local desktop = { plugin = {} }
|
||||||
|
local deck = Deck:new{}
|
||||||
|
deck:build({ desktop = desktop, plugin = desktop.plugin },
|
||||||
|
{ width = 300, height = deck:heightRange(nil, { width = 300 }).height })
|
||||||
|
Assert.contains(Kit.texts(deck.slot), "联网后显示 Kavita 上在读的书")
|
||||||
|
|
||||||
|
-- 激活拉一次:POST on-deck,进度按 pagesRead / pages。
|
||||||
|
deck:activate()
|
||||||
|
Assert.len(calls, 1)
|
||||||
|
Assert.eq(calls[1].method, "POST")
|
||||||
|
Assert.eq(calls[1].path, "/api/Series/on-deck")
|
||||||
|
Assert.eq(calls[1].query.pageSize, 10)
|
||||||
|
local list = {}
|
||||||
|
for i = 1, 12 do list[i] = { id = i, name = "S" .. i, pages = 10, pagesRead = i } end
|
||||||
|
reply(list)
|
||||||
|
Assert.eq(deck.data[3].stable_id, "3")
|
||||||
|
Assert.eq(deck.data[3].source_id, "kavita")
|
||||||
|
Assert.eq(deck.data[3].percent, 30)
|
||||||
|
-- 一页 4 本(跟首页最近阅读一样),12 本分 3 页。
|
||||||
|
Assert.eq(#covers, 4, "一页 4 本")
|
||||||
|
Assert.is_true(covers[1].home, "On Deck 走首页封面策略")
|
||||||
|
Assert.eq(covers[1].book.title, "S1")
|
||||||
|
Assert.contains(Kit.texts(deck.slot), "1 / 3")
|
||||||
|
|
||||||
|
-- 一页 4 本、多的分页:翻到后面不该重画前面的书。
|
||||||
|
covers = {}
|
||||||
|
deck.page = 2
|
||||||
|
deck:refresh()
|
||||||
|
Assert.eq(#covers, 4)
|
||||||
|
Assert.eq(covers[1].book.title, "S5", "第二页从第 5 本开始")
|
||||||
|
Assert.contains(Kit.texts(deck.slot), "2 / 3")
|
||||||
|
deck.page = 3
|
||||||
|
covers = {}
|
||||||
|
deck:refresh()
|
||||||
|
Assert.eq(#covers, 4, "最后一页 4 本")
|
||||||
|
Assert.eq(covers[1].book.title, "S9")
|
||||||
|
deck.page = 1
|
||||||
|
covers = {}
|
||||||
|
deck:refresh()
|
||||||
|
|
||||||
|
-- 5 分钟内重新激活不再请求;过期再拉。
|
||||||
|
deck:deactivate()
|
||||||
|
deck:activate()
|
||||||
|
Assert.len(calls, 1)
|
||||||
|
deck.loaded_at = os.time() - 301
|
||||||
|
deck:deactivate()
|
||||||
|
deck:activate()
|
||||||
|
Assert.len(calls, 2)
|
||||||
|
|
||||||
|
-- 离开首页取消在飞请求;失败显示原因;空列表给提示。
|
||||||
|
deck:deactivate()
|
||||||
|
Assert.is_nil(reply)
|
||||||
|
deck.loaded_at = nil
|
||||||
|
deck:activate()
|
||||||
|
reply(nil, "API Key 无效")
|
||||||
|
Assert.eq(covers[1].book.title, "S1", "失败保留上次的列表")
|
||||||
|
deck.data, deck.loaded_at = nil, nil
|
||||||
|
deck:deactivate()
|
||||||
|
deck:activate()
|
||||||
|
reply(nil, "API Key 无效")
|
||||||
|
Assert.contains(Kit.texts(deck.slot), "API Key 无效")
|
||||||
|
deck.loaded_at = nil
|
||||||
|
deck:deactivate()
|
||||||
|
deck:activate()
|
||||||
|
reply({})
|
||||||
|
Assert.contains(Kit.texts(deck.slot), "Kavita 上没有在读的书")
|
||||||
|
|
||||||
|
-- 离线 / 未配置不请求。
|
||||||
|
local before = #calls
|
||||||
|
deck.loaded_at = nil
|
||||||
|
deck:deactivate()
|
||||||
|
online = false
|
||||||
|
deck:activate()
|
||||||
|
deck:deactivate()
|
||||||
|
online, configured = true, false
|
||||||
|
deck:activate()
|
||||||
|
Assert.len(calls, before)
|
||||||
|
|
||||||
|
-- 点封面走月读开书。
|
||||||
|
deck.data = { { source_id = "kavita", stable_id = "9", title = "九" } }
|
||||||
|
deck:refresh()
|
||||||
|
local taps = Kit.taps(deck.slot)
|
||||||
|
Assert.len(taps, 1)
|
||||||
|
taps[1]:onTapThemeArea()
|
||||||
|
Assert.eq(opened[1].stable_id, "9")
|
||||||
|
|
||||||
|
-- 一页 4 本,封面按宽度分满,槽宽/封面宽一致,10 本分 3 页。
|
||||||
|
covers = {}
|
||||||
|
online, configured = true, true
|
||||||
|
local wide = Deck:new{}
|
||||||
|
local nat = wide:heightRange(nil, { width = 568 }).height
|
||||||
|
wide:build({ desktop = desktop, plugin = desktop.plugin }, { width = 568, height = nat })
|
||||||
|
wide:activate()
|
||||||
|
local ten = {}
|
||||||
|
for i = 1, 10 do ten[i] = { id = i, name = "S" .. i, pages = 10, pagesRead = i } end
|
||||||
|
reply(ten)
|
||||||
|
Assert.len(wide.data, 10)
|
||||||
|
Assert.eq(#covers, 4, "每页 4 本")
|
||||||
|
Assert.contains(Kit.texts(wide.slot), "1 / 3")
|
||||||
|
-- 内容高不能超过 heightRange(超了 widget 会掉出槽位)。
|
||||||
|
Assert.is_true(wide.slot[1]:getSize().h <= nat, "内容高不超过 heightRange")
|
||||||
|
-- 每格用同一个槽宽(Book.widget 把封面居中到 slot_w),不会有一本看着变小 / 错位。
|
||||||
|
for _i, c in ipairs(covers) do
|
||||||
|
Assert.eq(c.slot_w, covers[1].slot_w, "每格槽宽一致")
|
||||||
|
Assert.eq(c.w, covers[1].w, "每格封面宽一致")
|
||||||
|
end
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
--[[--
|
||||||
|
extensions/moonsource-kavita.koplugin:xpointer ↔ Kavita pageNum / bookScrollId 换算。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.position_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
|
||||||
|
local Position = dofile((debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita") .. "/position.lua")
|
||||||
|
|
||||||
|
-- spine:DocFragment[D] = spine D-1;单 spine 书没有下标。
|
||||||
|
Assert.eq(Position.spine("/body/DocFragment[8]/body/p[2]/text().0"), 7)
|
||||||
|
Assert.eq(Position.spine("/body[1]/DocFragment[1]/body[1]/p"), 0)
|
||||||
|
Assert.eq(Position.spine("/body/DocFragment/body/p"), 0)
|
||||||
|
Assert.is_nil(Position.spine(nil))
|
||||||
|
Assert.is_nil(Position.spine("#_doc_fragment_3"))
|
||||||
|
|
||||||
|
-- 上报:补全 [1]、丢文本偏移;两种 crengine 写法都认。
|
||||||
|
Assert.eq(Position.toScrollId("/body/DocFragment[8]/body/section/p[3]/text().0"), "//body/section[1]/p[3]")
|
||||||
|
Assert.eq(Position.toScrollId("/body[1]/DocFragment[8]/body[1]/div[2]/p/text()[1].5"), "//body/div[2]/p[1]")
|
||||||
|
Assert.eq(Position.toScrollId("/body/DocFragment/body/p[4]"), "//body/p[4]")
|
||||||
|
Assert.is_nil(Position.toScrollId("/body/DocFragment[2]/body"), "body 本身没有章内位置")
|
||||||
|
Assert.is_nil(Position.toScrollId(nil))
|
||||||
|
|
||||||
|
-- 下行:[1] 省略;读完(pageNum == pages)落回最后一个 spine;单 spine 书不带下标。
|
||||||
|
Assert.eq(Position.toXPointer(7, "//body/section[1]/p[3]", 10), "/body/DocFragment[8]/body/section/p[3]")
|
||||||
|
Assert.eq(Position.toXPointer(10, nil, 10), "/body/DocFragment[10]/body")
|
||||||
|
Assert.eq(Position.toXPointer(0, "//body/p[2]", 1), "/body/DocFragment/body/p[2]")
|
||||||
|
Assert.eq(Position.toXPointer(3, "id(\"x\")", 10), "/body/DocFragment[4]/body", "未解析的锚点只按 spine 定位")
|
||||||
|
|
||||||
|
-- 往返:上报出去的锚点拉回来落在同一段。
|
||||||
|
local here = "/body/DocFragment[5]/body/div[2]/p[7]/text().12"
|
||||||
|
Assert.eq(Position.toXPointer(Position.spine(here), Position.toScrollId(here), 9), "/body/DocFragment[5]/body/div[2]/p[7]")
|
||||||
|
|
||||||
|
-- 网页端的 id("X"):读本地 epub 第 spine 个文档找元素路径。
|
||||||
|
local files = {
|
||||||
|
["META-INF/container.xml"] = [[<container><rootfiles><rootfile full-path="OEBPS/content.opf"/></rootfiles></container>]],
|
||||||
|
["OEBPS/content.opf"] = [[<package><manifest>
|
||||||
|
<item id="c1" href="text/one.xhtml" media-type="application/xhtml+xml"/>
|
||||||
|
<item href="text/two.xhtml" id="c2" media-type="application/xhtml+xml"/>
|
||||||
|
</manifest><spine><itemref idref="c1"/><itemref idref="c2"/></spine></package>]],
|
||||||
|
["OEBPS/text/two.xhtml"] = [[<?xml version="1.0"?><html><body>
|
||||||
|
<section><p>a</p><br/><p>b<img src="x"/></p><div><p id="target">c</p></div></section></body></html>]],
|
||||||
|
}
|
||||||
|
local opened, closed = nil, false
|
||||||
|
package.loaded["ffi/archiver"] = {
|
||||||
|
Reader = {
|
||||||
|
new = function()
|
||||||
|
return {
|
||||||
|
open = function(_self, path) opened = path; return path == "/book.epub" end,
|
||||||
|
iterate = function() return function() end end,
|
||||||
|
extractToMemory = function(_self, name) return files[name] end,
|
||||||
|
close = function() closed = true end,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Assert.eq(Position.resolveScrollId("/book.epub", 1, 'id("target")'), "//body/section[1]/div[1]/p[1]")
|
||||||
|
Assert.eq(opened, "/book.epub")
|
||||||
|
Assert.is_true(closed)
|
||||||
|
Assert.eq(Position.resolveScrollId(nil, 1, "//body/p[2]"), "//body/p[2]", "自己上报的路径原样用")
|
||||||
|
Assert.is_nil(Position.resolveScrollId("/book.epub", 1, 'id("missing")'))
|
||||||
|
Assert.is_nil(Position.resolveScrollId("/book.epub", 5, 'id("target")'), "spine 越界")
|
||||||
|
Assert.is_nil(Position.resolveScrollId(nil, 1, 'id("target")'), "没下载过的书没法解析")
|
||||||
|
Assert.is_nil(Position.resolveScrollId("/other.epub", 1, 'id("target")'), "打不开的文件")
|
||||||
|
-- 划线锚点:按段落文本找路径,忽略空白、实体、脚注标记;跨段用首末行各定一段。
|
||||||
|
files["OEBPS/text/one.xhtml"] = [[<html><body><p>前言</p>
|
||||||
|
<p>甲乙丙&丁 戊己<sup>¹</sup>[3]庚辛壬癸</p><div><p>子丑寅卯辰巳</p></div></body></html>]]
|
||||||
|
local anchor = Position.anchor("丙&丁\n戊己", "/body/DocFragment[1]/body/p[2]/text().2", "/book.epub")
|
||||||
|
Assert.eq(anchor.pageNumber, 0)
|
||||||
|
Assert.eq(anchor.xPath, "//body/p[2]")
|
||||||
|
Assert.eq(anchor.endingXPath, "//body/p[2]")
|
||||||
|
anchor = Position.anchor("戊己庚辛壬癸\n子丑寅", "/body/DocFragment[1]/body/p[2]/text().6", "/book.epub")
|
||||||
|
Assert.eq(anchor.xPath, "//body/p[2]")
|
||||||
|
Assert.eq(anchor.endingXPath, "//body/div[1]/p[1]", "跨段")
|
||||||
|
anchor = Position.anchor("c", "/body/DocFragment[1]/body/p", "/book.epub")
|
||||||
|
Assert.is_nil(anchor, "单字太短,不猜")
|
||||||
|
anchor = Position.anchor("b", "/body/DocFragment[1]/body/p", "/book.epub")
|
||||||
|
Assert.is_nil(anchor)
|
||||||
|
files["OEBPS/text/two.xhtml"] = files["OEBPS/text/two.xhtml"]:gsub("<p>b", "<p>挪到第二章")
|
||||||
|
anchor = Position.anchor("挪到第二章", "/body/DocFragment[1]/body/p[2]", "/book.epub")
|
||||||
|
Assert.eq(anchor.pageNumber, 1, "pos0 所在 spine 没有就去邻近 spine 找")
|
||||||
|
Assert.eq(anchor.xPath, "//body/section[1]/p[2]")
|
||||||
|
Assert.is_nil(Position.anchor("不存在的文字", "/body/DocFragment[1]/body/p", "/book.epub"))
|
||||||
|
Assert.is_nil(Position.anchor("甲乙丙", "/body/DocFragment[1]/body/p", nil), "没下载过")
|
||||||
|
|
||||||
|
files["META-INF/container.xml"] = nil
|
||||||
|
Assert.is_nil(Position.resolveScrollId("/book.epub", 1, 'id("target")'), "坏 epub 降级成只按 spine")
|
||||||
@@ -0,0 +1,385 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita 统计对账:真实响应 fixture 走「拉取钩子 → replaceSynced 入库 → 展示查询」全链,
|
||||||
|
逐项对 spec 的验收基线。HTTP 与目录缓存打桩,其余全真:源(分页 / 身份判定 / 物化)、
|
||||||
|
统计纯核心、真实 sqlite 的 reading_stats 与 books 库。
|
||||||
|
|
||||||
|
对账基线(research-kavita-stats-pull.md):
|
||||||
|
§2 全量逐日(29 天 / Σ=60,238s)、§3 样本 7453 逐日(13,921 + 316)、§4 系列累计。
|
||||||
|
数字都来自实测响应(fixture 数值逐条未改),不是照实现倒推的。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.reconcile_spec
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
local Json = require("support.json_stub")
|
||||||
|
local Stubs = require("support.stubs")
|
||||||
|
|
||||||
|
-- 日 / 时归属按进程时区(POSIX TZ)计算:钉死 CST-8,与 fixture 拉取时用的 Asia/Shanghai 对齐,
|
||||||
|
-- 断言就不会随宿主机时区漂移。
|
||||||
|
local ffi = require("ffi")
|
||||||
|
ffi.cdef[[ int setenv(const char*, const char*, int); void tzset(void); ]]
|
||||||
|
ffi.C.setenv("TZ", "CST-8", 1)
|
||||||
|
ffi.C.tzset()
|
||||||
|
|
||||||
|
local sqlite_ok = pcall(require, "lua-ljsqlite3/init")
|
||||||
|
if not sqlite_ok then
|
||||||
|
Assert.skip("当前离线环境没有 ljsqlite3 Lua 模块")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 沙箱库:books 与 reading_stats 同库,物化行和统计行一起对账。
|
||||||
|
local db_path = Config.dir() .. "/kavita_reconcile_spec.sqlite3"
|
||||||
|
for _idx, suffix in ipairs({ "", "-wal", "-shm" }) do os.remove(db_path .. suffix) end
|
||||||
|
package.loaded["utils.paths"] = nil
|
||||||
|
package.preload["utils.paths"] = function()
|
||||||
|
return {
|
||||||
|
dbPath = function() return db_path end,
|
||||||
|
ensureSettings = function() end,
|
||||||
|
sanitizeSourceId = function(id) return id end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 响应体 / 分页头走真实编解码(source_spec 的往返桩同形);books 的 meta 列也用它。
|
||||||
|
package.loaded["json"] = nil
|
||||||
|
package.preload["json"] = function()
|
||||||
|
return { encode = Json.encode, decode = Json.decode }
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 设备时钟(POSIX → IANA 映射)与扩展配置;stats_db 也会问 merge_local_stats(本用例默认关)。
|
||||||
|
local clock = { timezone = "CST-8" }
|
||||||
|
local cfg = { base_url = "http://kav/", api_key = " k ", libraries = { ["8"] = true, ["10"] = true } }
|
||||||
|
package.loaded["utils.settings"] = nil
|
||||||
|
package.preload["utils.settings"] = function()
|
||||||
|
local common = { active_source = "local" }
|
||||||
|
return {
|
||||||
|
get = function(key) return key == "features.clock" and clock or common end,
|
||||||
|
getSource = function() return cfg end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 插件模块走 preload:不把插件根塞进 package.path(main.lua 会顶掉月读的 main)。
|
||||||
|
local PLUGIN = (debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita")
|
||||||
|
for _idx, name in ipairs({ "client", "position", "annotation", "cache", "volume_list", "source", "stats" }) do
|
||||||
|
package.preload["moonsource_kavita" .. (name == "source" and ".source" or "." .. name)] = function()
|
||||||
|
return dofile(PLUGIN .. "/" .. (name == "source" and "source" or name) .. ".lua")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- HTTP:只服务阅读历史;目录全部命中缓存,物化与身份判定不发请求。
|
||||||
|
-- 分页头与 body 同一套编解码(同真服务端:PageSize=200、总页数在响应头里)。
|
||||||
|
local pagination_calls = {}
|
||||||
|
local sample = dofile((debug.getinfo(1, "S").source:match("^@(.*)/")) .. "/fixtures/history_all.lua")
|
||||||
|
local history = sample
|
||||||
|
local function history_pages()
|
||||||
|
local pages = { {}, {} }
|
||||||
|
for _idx, entry in ipairs(history) do
|
||||||
|
local page = #pages[1] < 200 and 1 or 2
|
||||||
|
pages[page][#pages[page] + 1] = entry
|
||||||
|
end
|
||||||
|
return pages
|
||||||
|
end
|
||||||
|
local function query(opts, key) return opts.url:match("[?&]" .. key .. "=([^&]*)") end
|
||||||
|
package.loaded["http.request"] = {
|
||||||
|
ok = function(code)
|
||||||
|
code = tonumber(code)
|
||||||
|
return code ~= nil and code >= 200 and code < 300
|
||||||
|
end,
|
||||||
|
header = function(res, name)
|
||||||
|
for key, value in pairs(res and res.headers or {}) do
|
||||||
|
if type(key) == "string" and key:lower() == name:lower() then return value end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
request = function(opts, cb)
|
||||||
|
local page = tonumber(query(opts, "PageNumber")) or 1
|
||||||
|
pagination_calls[#pagination_calls + 1] = opts.url
|
||||||
|
-- 只认阅读历史:目录 / 其它接口意外被请求时返回 404(身份判定该走目录缓存,
|
||||||
|
-- 真机也是:判定结果记在状态文件里,不该为身份反复请求目录)。
|
||||||
|
local history_call = opts.url:find("/api/Stats/reading%-history", 1) ~= nil
|
||||||
|
require("ui/uimanager"):nextTick(function()
|
||||||
|
if not history_call then
|
||||||
|
cb({ code = 404, body = "" })
|
||||||
|
return
|
||||||
|
end
|
||||||
|
cb({
|
||||||
|
code = 200,
|
||||||
|
body = Json.encode(history_pages()[page]),
|
||||||
|
headers = { Pagination = Json.encode({
|
||||||
|
currentPage = page,
|
||||||
|
itemsPerPage = 200,
|
||||||
|
totalItems = #history,
|
||||||
|
totalPages = math.max(1, math.ceil(#history / 200)),
|
||||||
|
}) },
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 目录缓存(source.toc)替身:身份判定只关心「1 章还是多章」,物化只用条目 title。
|
||||||
|
-- 7453 用实测目录(4 卷含卷名,research §5 / series-detail);已知实测章数的系列对齐 §5;
|
||||||
|
-- 其余按云端读到的章构造 —— 判定结果只影响单书身份粒度,不影响账户日桶。
|
||||||
|
local CLOUD_TITLES = {
|
||||||
|
["7453"] = {
|
||||||
|
{ chapterId = 11271, title = "2001:太空漫游" },
|
||||||
|
{ chapterId = 11273, title = "2010:太空漫游" },
|
||||||
|
{ chapterId = 11270, title = "2061:太空漫游" },
|
||||||
|
{ chapterId = 11272, title = "3001:太空漫游" },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
local TOC_COUNTS = { ["7453"] = 4, ["10634"] = 27, ["7460"] = 2, ["10720"] = 5, ["8661"] = 1, ["7606"] = 1 }
|
||||||
|
local tocs = {}
|
||||||
|
for _idx, entry in ipairs(sample) do
|
||||||
|
local series_id = tostring(entry.seriesId)
|
||||||
|
local toc = tocs[series_id]
|
||||||
|
if not toc then toc = {}; tocs[series_id] = toc end
|
||||||
|
-- 全量取并:同一系列各条会话可能各读不同章,真目录里这些章都在。
|
||||||
|
for _i, chapter in ipairs(entry.chapters) do
|
||||||
|
if chapter.chapterId then
|
||||||
|
local known = false
|
||||||
|
for _k, item in ipairs(toc) do
|
||||||
|
if item.chapterId == chapter.chapterId then known = true end
|
||||||
|
end
|
||||||
|
if not known then toc[#toc + 1] = { chapterId = chapter.chapterId } end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for series_id, entries in pairs(CLOUD_TITLES) do tocs[series_id] = entries end
|
||||||
|
for series_id, count in pairs(TOC_COUNTS) do
|
||||||
|
-- 补齐到实测章数:补齐条目不带 chapterId,只有 #toc 参与单卷 / 多卷判定。
|
||||||
|
while #tocs[series_id] < count do tocs[series_id][#tocs[series_id] + 1] = {} end
|
||||||
|
end
|
||||||
|
package.loaded["source.toc"] = {
|
||||||
|
read = function(_sid, series_id) return tocs[tostring(series_id)] end,
|
||||||
|
put = function(_sid, series_id, list) tocs[tostring(series_id)] = list; return true end,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 统计状态文件(上次身份 + 章数判定)是上一轮的残留:连 .old 备份一起清,
|
||||||
|
-- 清了才是「首次拉取」(LuaSettings 读不到主文件会回落 .old)。
|
||||||
|
local STATS_STATE = require("datastorage"):getSettingsDir() .. "/moonsource_kavita_stats.lua"
|
||||||
|
local function clearStatsState()
|
||||||
|
for _idx, suffix in ipairs({ "", ".old" }) do os.remove(STATS_STATE .. suffix) end
|
||||||
|
end
|
||||||
|
clearStatsState()
|
||||||
|
|
||||||
|
local Base = require("utils.db")
|
||||||
|
local StatsDB = require("book.stats_db")
|
||||||
|
local BookDB = require("book.books_db")
|
||||||
|
local ProgressDB = require("book.progress_db")
|
||||||
|
local Kavita = require("moonsource_kavita.source")
|
||||||
|
Assert.not_nil(Base.open())
|
||||||
|
|
||||||
|
-- 书架容器行(书架同步的产物):统计侧只当物化标题 / 元数据来源。作者只给断言用到的那本。
|
||||||
|
local function container(id, title, authors)
|
||||||
|
Assert.is_true(BookDB.upsertRemote({ source_id = "kavita", stable_id = id, title = title,
|
||||||
|
authors = authors, deleted = 0 }, false, true))
|
||||||
|
end
|
||||||
|
container("7453", "太空漫游", "阿瑟·克拉克")
|
||||||
|
container("8661", "人类简史")
|
||||||
|
container("7460", "三国演义")
|
||||||
|
container("10634", "大剑")
|
||||||
|
|
||||||
|
-- 本机逐页记录:10-14 已上报(云端会话已含,不能再算一遍);10-17 拉取后才读(未上报)。
|
||||||
|
local L1_T = os.time({ year = 2026, month = 10, day = 14, hour = 21 })
|
||||||
|
Assert.is_true(StatsDB.add({
|
||||||
|
source_id = "kavita", stable_id = "7453:11273", record_type = "page",
|
||||||
|
page = 30, start_time = L1_T, duration = 900, total_pages = 150,
|
||||||
|
}, StatsDB.SYNCED))
|
||||||
|
|
||||||
|
-- 固定拉取时刻(2026-10-16 20:00 本地,晚于全量最后一天):只看 nil 参数的 os.time。
|
||||||
|
local FETCHED = 1792152000
|
||||||
|
local real_time = os.time
|
||||||
|
os.time = function(t)
|
||||||
|
if t == nil then return FETCHED end
|
||||||
|
return real_time(t)
|
||||||
|
end
|
||||||
|
local source = Kavita.new()
|
||||||
|
|
||||||
|
--- 一次完整的统计同步:拉取 → 入库 → commit(状态文件只在入库成功后前进)。
|
||||||
|
---@return BookStatsPullResult
|
||||||
|
local function pull()
|
||||||
|
local result, err
|
||||||
|
source:pullStatsAsync(function(res, pull_err) result, err = res, pull_err end)
|
||||||
|
Stubs.flush()
|
||||||
|
Assert.not_nil(result, err)
|
||||||
|
Assert.not_nil(StatsDB.replaceSynced("kavita", result.replace, result.rows), "入库必须成功")
|
||||||
|
result.commit()
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local pulled = pull()
|
||||||
|
|
||||||
|
--- 逐日聚合(dailyBySource):ymd → { seconds, pages }。
|
||||||
|
local function calendar()
|
||||||
|
local rows = {}
|
||||||
|
for _idx, row in ipairs(StatsDB.dailyBySource("kavita")) do rows[row.ymd] = row end
|
||||||
|
return rows
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ① 单书累计:与云端 Σ 一致(§3 的 7453 两卷 / §4 的系列累计)。
|
||||||
|
-- 10-14 的本地 900s 已含在云端快照里(sync_status=1 且早于拉取时刻):不加第二遍。
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "7453:11273").total_seconds, 13921, "样本卷累计 = 云端 Σ")
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "7453:11271").total_seconds, 316, "同系列另一卷(只在其它设备读过)")
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "7453").total_seconds, 0, "多卷系列不读在容器行上")
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "8661").total_seconds, 3555, "单卷系列读在 series 行(§4)")
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "7460:11285").total_seconds, 9517, "多章目录 → 逐卷身份(§4)")
|
||||||
|
-- 页数:云端会话的 pagesRead + 未被会话覆盖的本地页(18 号票)。10-14 的本地 1 页已上报、
|
||||||
|
-- 当天有会话覆盖,不再加;22 是该卷各云端会话 pagesRead 之和。
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "7453:11273").pages, 22, "单书页数 = 云端会话 pagesRead 之和")
|
||||||
|
|
||||||
|
-- ② 日历逐日与 §2 一致;合计 = __kv:total。
|
||||||
|
-- 页数口径与 §2 的 hist_p 在 9-19 / 9-24 / 9-29 差 1 / 1 / 2 页:那 4 页来自零时长条目,
|
||||||
|
-- 设计上整条丢弃(§4 已记「零时长条目 100 条,其中带页数 4 条合计 4 页」)。
|
||||||
|
local CLOUD_DAYS = {
|
||||||
|
{ "2026-09-18", 920, 5 }, { "2026-09-19", 2824, 10 }, { "2026-09-20", 2813, 25 },
|
||||||
|
{ "2026-09-21", 1183, 18 }, { "2026-09-22", 1682, 25 }, { "2026-09-23", 406, 18 },
|
||||||
|
{ "2026-09-24", 1179, 114 }, { "2026-09-25", 10, 3 }, { "2026-09-26", 1378, 71 },
|
||||||
|
{ "2026-09-27", 755, 0 }, { "2026-09-28", 104, 0 }, { "2026-09-29", 7942, 312 },
|
||||||
|
{ "2026-09-30", 6640, 22 }, { "2026-10-01", 643, 23 }, { "2026-10-03", 1104, 25 },
|
||||||
|
{ "2026-10-04", 638, 1 }, { "2026-10-05", 195, 0 }, { "2026-10-06", 809, 0 },
|
||||||
|
{ "2026-10-07", 503, 0 }, { "2026-10-08", 3663, 10 }, { "2026-10-09", 1092, 93 },
|
||||||
|
{ "2026-10-10", 363, 10 }, { "2026-10-11", 649, 26 }, { "2026-10-12", 1803, 103 },
|
||||||
|
{ "2026-10-13", 4514, 244 }, { "2026-10-14", 11665, 120 }, { "2026-10-15", 4541, 118 },
|
||||||
|
{ "2026-10-16", 220, 6 },
|
||||||
|
}
|
||||||
|
local days = calendar()
|
||||||
|
local day_count = 0
|
||||||
|
for _ymd in pairs(days) do day_count = day_count + 1 end
|
||||||
|
Assert.eq(day_count, #CLOUD_DAYS, "只有有有效时长的日子落桶(10-02 三条会话全零时长)")
|
||||||
|
Assert.is_nil(days["2026-10-02"], "零时长日不留桶")
|
||||||
|
-- 本地逐页记录按条累加;云端日桶显式 0 页不能被补成 1 页。
|
||||||
|
local ZERO_PAGE_DAYS = 0
|
||||||
|
for _idx, expected in ipairs(CLOUD_DAYS) do
|
||||||
|
local row = days[expected[1]]
|
||||||
|
Assert.not_nil(row, "缺日桶 " .. expected[1])
|
||||||
|
Assert.eq(row.seconds, expected[2], "日时长 " .. expected[1])
|
||||||
|
local stored_pages = expected[3] + (expected[1] == "2026-10-14" and 1 or 0)
|
||||||
|
if expected[3] == 0 then ZERO_PAGE_DAYS = ZERO_PAGE_DAYS + 1 end
|
||||||
|
Assert.eq(row.pages, stored_pages, "日页数增量 " .. expected[1])
|
||||||
|
end
|
||||||
|
Assert.eq(ZERO_PAGE_DAYS, 5, "云端 0 页日就 5 天(09-27 / 09-28 / 10-05~10-07)")
|
||||||
|
local calendar_sum, calendar_pages = 0, 0
|
||||||
|
for _ymd, row in pairs(days) do
|
||||||
|
calendar_sum = calendar_sum + row.seconds
|
||||||
|
calendar_pages = calendar_pages + row.pages
|
||||||
|
end
|
||||||
|
Assert.eq(StatsDB.summaryBySource("kavita").total_pages, calendar_pages, "总页数 = 日历逐日之和")
|
||||||
|
Assert.eq(calendar_sum, 60238, "各日之和 = 云端全量 Σ(§2)")
|
||||||
|
local total_row
|
||||||
|
for _idx, row in ipairs(pulled.rows) do
|
||||||
|
if row.record_type == "total" then total_row = row end
|
||||||
|
end
|
||||||
|
Assert.eq(total_row.duration, calendar_sum, "总时长 = __kv:total")
|
||||||
|
Assert.eq(StatsDB.summaryBySource("kavita").total_seconds, calendar_sum, "总览合计 = 日历合计")
|
||||||
|
|
||||||
|
-- 分页:分页头说 2 页就拉 2 页,参数形态同真服务端。
|
||||||
|
Assert.len(pagination_calls, 2)
|
||||||
|
Assert.matches(pagination_calls[1], "Libraries=8")
|
||||||
|
Assert.matches(pagination_calls[1], "Libraries=10")
|
||||||
|
Assert.matches(pagination_calls[1], "PageNumber=1&PageSize=200")
|
||||||
|
Assert.matches(pagination_calls[1], "TimeZoneId=Asia%%2FShanghai")
|
||||||
|
Assert.matches(pagination_calls[2], "PageNumber=2&")
|
||||||
|
|
||||||
|
-- ③ 当日书单:云端读过、本机从没打开过的书也在;单书逐日与云端一致。
|
||||||
|
local by_day_book = {}
|
||||||
|
for _idx, row in ipairs(StatsDB.dailyBooksBySource("kavita")) do
|
||||||
|
by_day_book[row.ymd] = by_day_book[row.ymd] or {}
|
||||||
|
by_day_book[row.ymd][row.stable_id] = row
|
||||||
|
end
|
||||||
|
Assert.eq(by_day_book["2026-09-29"]["7453:11271"].seconds, 316, "只在其它设备读过的卷进当日书单")
|
||||||
|
Assert.eq(by_day_book["2026-09-29"]["7453:11271"].max_total_pages, 0, "只有云端时长的那天没有页坐标")
|
||||||
|
Assert.eq(by_day_book["2026-09-30"]["8661"].seconds, 2885, "单卷系列按 series 身份进当日书单")
|
||||||
|
Assert.eq(by_day_book["2026-10-15"]["10634:17868"].seconds, 531, "多卷按章拆到各卷(210 + 321)")
|
||||||
|
|
||||||
|
-- 12 号票物化的隐藏身份行:书单里的云端书能显示书名(不是裸 ID),且不上架 / 不标脏 / 不写进度。
|
||||||
|
local cloud_only = BookDB.get("kavita", "7453:11271")
|
||||||
|
Assert.eq(cloud_only.title, "太空漫游 · 2001:太空漫游", "标题 = 系列 · 卷名")
|
||||||
|
Assert.eq(cloud_only.authors, "阿瑟·克拉克", "作者继承容器行")
|
||||||
|
Assert.eq(cloud_only.deleted, 1, "隐藏身份行:不进书架")
|
||||||
|
Assert.eq(cloud_only.sync_status, 1, "隐藏身份行:不标脏、不推云端")
|
||||||
|
Assert.is_nil(ProgressDB.get("kavita", "7453:11271"), "统计拉取不写进度:不会因此冒进「最近阅读」")
|
||||||
|
local shelf_ids = BookDB.libraryStableIdsBySource("kavita")
|
||||||
|
local materialized_on_shelf = false
|
||||||
|
for _idx, id in ipairs(shelf_ids) do
|
||||||
|
if id == "7453:11271" or id == "7453:11273" then materialized_on_shelf = true end
|
||||||
|
end
|
||||||
|
Assert.is_false(materialized_on_shelf, "物化行不是书架成员")
|
||||||
|
-- 容器行缺失的系列:物化跳过(12 号票语义),统计行照写。
|
||||||
|
Assert.is_nil(BookDB.get("kavita", "7910:11896"), "没有容器行就不物化")
|
||||||
|
Assert.eq(by_day_book["2026-09-29"]["7910:11896"] ~= nil, true, "不物化不影响统计行")
|
||||||
|
|
||||||
|
-- 单书逐日(详情页「最近几天」)与云端 §3 一致;10-14 = 云端 6734(本地 900 已含,不再加)。
|
||||||
|
local function book_days(stable_id)
|
||||||
|
local rows, count = {}, 0
|
||||||
|
for _idx, row in ipairs(StatsDB.dailyByBook("kavita", stable_id, 40)) do
|
||||||
|
rows[row.ymd] = row.seconds
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
return rows, count
|
||||||
|
end
|
||||||
|
local sample_days = {
|
||||||
|
["2026-10-05"] = 195, ["2026-10-07"] = 503, ["2026-10-08"] = 2036, ["2026-10-11"] = 512,
|
||||||
|
["2026-10-13"] = 979, ["2026-10-14"] = 6734, ["2026-10-15"] = 2962,
|
||||||
|
}
|
||||||
|
local sample_rows, sample_day_count = book_days("7453:11273")
|
||||||
|
Assert.eq(sample_rows["2026-10-14"], 6734, "云+本地同一天不双计")
|
||||||
|
Assert.eq(sample_day_count, 7, "只列有数据的日子(零时长日不出现)")
|
||||||
|
for ymd, seconds in pairs(sample_days) do Assert.eq(sample_rows[ymd], seconds, "单书逐日 " .. ymd) end
|
||||||
|
Assert.eq(book_days("7453:11271")["2026-09-29"], 316)
|
||||||
|
|
||||||
|
-- ④ 时段:云端时段桶 + 本机逐页记录,合并口径与按天一致。
|
||||||
|
local hourly = StatsDB.hourlyBySource("kavita")
|
||||||
|
local hourly_days = 0
|
||||||
|
for _ymd in pairs(hourly) do hourly_days = hourly_days + 1 end
|
||||||
|
Assert.eq(hourly["2026-10-14"][22], 1043, "10-14 21 点:云端该格 1043s(本机同格已上报,不叠加)")
|
||||||
|
Assert.eq(hourly_days, 28, "有云端时长的每天都有时段分布")
|
||||||
|
Assert.eq(hourly["2026-09-18"][18], 738, "纯云端的日子也有时段(21 点 174 + 17 点 738 …)")
|
||||||
|
-- 日页面「标题时长 = 时段图逐格之和」:逐日必须对得上
|
||||||
|
for _idx, row in ipairs(StatsDB.dailyBySource("kavita")) do
|
||||||
|
local sum = 0
|
||||||
|
for h = 1, 24 do sum = sum + (hourly[row.ymd] and hourly[row.ymd][h] or 0) end
|
||||||
|
Assert.eq(sum, row.seconds, "时段逐日之和 = 日历 " .. row.ymd)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- ⑤ 拉取后本地新读:云端快照 + 增量,两边都不双计。
|
||||||
|
local L2_T = FETCHED + 5 * 3600
|
||||||
|
Assert.is_true(StatsDB.add({
|
||||||
|
source_id = "kavita", stable_id = "7453:11273", record_type = "page",
|
||||||
|
page = 31, start_time = L2_T, duration = 90, total_pages = 150,
|
||||||
|
}, StatsDB.PENDING))
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "7453:11273").total_seconds, 13921 + 90, "快照 + 拉取后新读")
|
||||||
|
Assert.eq(book_days("7453:11273")["2026-10-17"], 90, "增量单落到它自己的日子")
|
||||||
|
Assert.eq(calendar()["2026-10-17"].seconds, 90, "日历同样叠加增量")
|
||||||
|
Assert.eq(StatsDB.summaryBySource("kavita").total_seconds, 60238 + 90, "总览 = __kv:total + 拉取后新读")
|
||||||
|
Assert.eq(StatsDB.hourlyBySource("kavita")["2026-10-17"][2], 90, "增量进时段(1 点 = 第 2 格)")
|
||||||
|
|
||||||
|
-- 再拉一次(本次只回样本 7453):整本替换不累加,云端消失的日桶清掉,本地逐页记录不动。
|
||||||
|
history = dofile((debug.getinfo(1, "S").source:match("^@(.*)/")) .. "/fixtures/history_7453.lua")
|
||||||
|
pulled = pull()
|
||||||
|
Assert.not_nil(pulled.rows[1])
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "7453:11273").total_seconds, 13921 + 90, "重拉不累加,增量仍在")
|
||||||
|
Assert.eq(StatsDB.summaryByBook("kavita", "8661").total_seconds, 0, "云端消失的书回落本地(没有本地记录 = 0)")
|
||||||
|
local again = calendar()
|
||||||
|
Assert.is_nil(again["2026-09-18"], "上一轮的云端日桶被全量重拉清掉")
|
||||||
|
Assert.eq(again["2026-10-14"].seconds, 6734, "样本日重写为本次回包值")
|
||||||
|
Assert.eq(again["2026-10-17"].seconds, 90, "本地逐页记录不受替换影响")
|
||||||
|
Assert.eq(StatsDB.hourlyBySource("kavita")["2026-10-14"][22], 716, "时段格重写为本次回包值(本机同格已上报,不叠加)")
|
||||||
|
Assert.is_nil(StatsDB.hourlyBySource("kavita")["2026-09-18"], "回包里消失的时段格清掉")
|
||||||
|
|
||||||
|
-- 12 号票物化标题的第二轮回归:二次拉取时章数已判定(不再读目录),卷名必须取自状态文件里的
|
||||||
|
-- 持久化卷名 —— 不能退容器名,更不能把上一轮物化出的好标题改写成「太空漫游 · 太空漫游」。
|
||||||
|
Assert.eq(BookDB.get("kavita", "7453:11271").title, "太空漫游 · 2001:太空漫游", "二次拉取后标题不回退")
|
||||||
|
Assert.eq(BookDB.get("kavita", "7453:11273").title, "太空漫游 · 2010:太空漫游")
|
||||||
|
|
||||||
|
-- 升级路径:老状态文件只有章数、没有卷名(本机第一轮物化时还没有持久化)。此时兜底标题
|
||||||
|
-- 只能用于新行,不得覆盖既有行的真实标题。
|
||||||
|
local stats_state = require("luasettings"):open(STATS_STATE)
|
||||||
|
stats_state:saveSetting("titles", {})
|
||||||
|
stats_state:flush()
|
||||||
|
pulled = pull()
|
||||||
|
Assert.eq(BookDB.get("kavita", "7453:11271").title, "太空漫游 · 2001:太空漫游",
|
||||||
|
"没有持久化卷名时,兜底标题不覆盖既有标题")
|
||||||
|
|
||||||
|
os.time = real_time
|
||||||
|
Base.close()
|
||||||
|
for _idx, suffix in ipairs({ "", "-wal", "-shm" }) do os.remove(db_path .. suffix) end
|
||||||
|
clearStatsState()
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
--[[-- Kavita 系列书评:章节过滤、归属校验与卷共用缓存。 @module tests.moonsource_kavita.reviews_spec --]]
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Stubs = require("support.stubs")
|
||||||
|
package.loaded.json = require("support.json_stub")
|
||||||
|
local Mapper = require("moonsource_kavita.mapper")
|
||||||
|
local wire = { reviews = {
|
||||||
|
{ body = "<p>Book review</p>", tagline = "Title", chapterId = 0, seriesId = 5,
|
||||||
|
username = "Reader", rating = 4, totalVotes = 3, isExternal = false },
|
||||||
|
{ body = "Chapter review", chapterId = 8, seriesId = 5, username = "Reader" },
|
||||||
|
{ body = "External book review", chapterId = 0, seriesId = 0,
|
||||||
|
username = "External", isExternal = true },
|
||||||
|
} }
|
||||||
|
local page, err = Mapper.bookReviewPage(wire, "5")
|
||||||
|
Assert.is_nil(err)
|
||||||
|
Assert.len(page.items, 2)
|
||||||
|
Assert.eq(page.items[1].text, "Title\nBook review")
|
||||||
|
Assert.eq(page.items[1].grade, 4)
|
||||||
|
Assert.eq(page.items[1].likes, 3)
|
||||||
|
Assert.eq(page.items[1].time, "", "协议无日期,不编造日期")
|
||||||
|
Assert.eq(page.items[2].text, "External book review")
|
||||||
|
Assert.len(Mapper.bookReviewPage({ reviews = {} }, "5").items, 0)
|
||||||
|
for _idx, bad in ipairs({
|
||||||
|
{}, { reviews = { { body = "Bad", username = "Reader", chapterId = 0, seriesId = 99 } } },
|
||||||
|
{ reviews = { { body = false } } },
|
||||||
|
}) do
|
||||||
|
local value, reason = Mapper.bookReviewPage(bad, "5")
|
||||||
|
Assert.is_nil(value)
|
||||||
|
Assert.eq(reason, "响应无效")
|
||||||
|
end
|
||||||
|
local source = require("moonsource_kavita.source").new()
|
||||||
|
local connected, requests, failed = true, 0, false
|
||||||
|
package.loaded["ui/network/manager"] = { isConnected = function() return connected end }
|
||||||
|
source.client.json = function(_self, method, path, query, _body, cb)
|
||||||
|
requests = requests + 1
|
||||||
|
Assert.eq(method, "GET")
|
||||||
|
Assert.eq(path, "/api/Metadata/series-detail-plus")
|
||||||
|
Assert.eq(query.seriesId, 5)
|
||||||
|
if failed then cb(nil, "server failed") else cb(wire) end
|
||||||
|
return { cancel = function() end }
|
||||||
|
end
|
||||||
|
source:bookReviewsAsync({ source_id = "kavita", stable_id = "5:8" }, function(value, reason)
|
||||||
|
page, err = value, reason
|
||||||
|
end)
|
||||||
|
Assert.is_nil(err)
|
||||||
|
Assert.len(page.items, 2)
|
||||||
|
connected = false
|
||||||
|
source:bookReviewsAsync({ source_id = "kavita", stable_id = "5:9" }, function(value, reason)
|
||||||
|
page, err = value, reason
|
||||||
|
end)
|
||||||
|
Stubs.flush()
|
||||||
|
Assert.is_nil(err)
|
||||||
|
Assert.len(page.items, 2)
|
||||||
|
Assert.eq(requests, 1, "两个卷使用所属系列的整书缓存")
|
||||||
|
connected, failed = true, true
|
||||||
|
source:bookReviewsAsync({ source_id = "kavita", stable_id = "5" }, function(value, reason)
|
||||||
|
page, err = value, reason
|
||||||
|
end)
|
||||||
|
Assert.is_nil(page)
|
||||||
|
Assert.eq(err, "server failed")
|
||||||
@@ -0,0 +1,644 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita 设置页:服务器 / API Key / 书库 / 漫画缓存 / 进度心跳 / 请求超时 / 连接测试。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.setting_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
|
||||||
|
local cfg = {}
|
||||||
|
local saved = 0
|
||||||
|
local invalidated = 0
|
||||||
|
local events = {}
|
||||||
|
package.preload["utils.settings"] = function()
|
||||||
|
return {
|
||||||
|
getSource = function() return cfg end,
|
||||||
|
saveSource = function(_, value)
|
||||||
|
cfg = value
|
||||||
|
saved = saved + 1
|
||||||
|
events[#events + 1] = "save"
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["source.registry"] = function()
|
||||||
|
return { invalidate = function() invalidated = invalidated + 1 end }
|
||||||
|
end
|
||||||
|
-- 源模块只在设置行里读两个默认值;真常量由 client_spec / source_spec 钉住。
|
||||||
|
-- 「测试连接」还要走 client:request,返回内容由 request_reply 控制。
|
||||||
|
local request_reply = { version = "0.9.0" }
|
||||||
|
package.preload["moonsource_kavita.client"] = function()
|
||||||
|
return {
|
||||||
|
DEFAULT_TIMEOUT = 60,
|
||||||
|
new = function()
|
||||||
|
return {
|
||||||
|
api_key = "k",
|
||||||
|
configured = function() return true end,
|
||||||
|
request = function(_, _method, _path, _query, _body, callback)
|
||||||
|
callback(request_reply.version, request_reply.err)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["ui/network/manager"] = function()
|
||||||
|
return { isConnected = function() return true end }
|
||||||
|
end
|
||||||
|
-- 同步删除的忙碌窗会先强制重绘再动手;占用统计在下一拍算(03 E),测试里手动 flush。
|
||||||
|
local repaints = 0
|
||||||
|
local pending_ticks = {}
|
||||||
|
local function flush()
|
||||||
|
while #pending_ticks > 0 do
|
||||||
|
local tick = table.remove(pending_ticks, 1)
|
||||||
|
tick()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
package.preload["ui/uimanager"] = function()
|
||||||
|
return {
|
||||||
|
forceRePaint = function() repaints = repaints + 1 end,
|
||||||
|
nextTick = function(_, fn) pending_ticks[#pending_ticks + 1] = fn end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["moonsource_kavita.source"] = function()
|
||||||
|
return { DEFAULT_HEARTBEAT_INTERVAL = 30 }
|
||||||
|
end
|
||||||
|
package.preload["ui.themes.widgets.row"] = function()
|
||||||
|
return { widget = function(opts) return opts end, note = function(_width, text) return { text = text } end }
|
||||||
|
end
|
||||||
|
package.loaded["ui.themes"] = nil
|
||||||
|
package.preload["ui.themes"] = function()
|
||||||
|
return {
|
||||||
|
current = function()
|
||||||
|
return { space = { md = 8 }, color = { muted = 1, page = 2 } }
|
||||||
|
end,
|
||||||
|
px = function(n) return n end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.loaded["ui/geometry"] = nil
|
||||||
|
package.preload["ui/geometry"] = function()
|
||||||
|
return { new = function(_, opts) return opts end }
|
||||||
|
end
|
||||||
|
package.loaded["ui/widget/container/centercontainer"] = nil
|
||||||
|
package.preload["ui/widget/container/centercontainer"] = function()
|
||||||
|
return { new = function(_, opts) return opts end }
|
||||||
|
end
|
||||||
|
package.loaded["ui.themes.widgets.text"] = nil
|
||||||
|
package.preload["ui.themes.widgets.text"] = function()
|
||||||
|
return {
|
||||||
|
box = function(_, text, _width, _opts)
|
||||||
|
return { text = text, getSize = function() return { h = 10 } end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 缓存适配层:探测 / 详情 / 保存后镜像;真实现由 cache_spec 钉住。
|
||||||
|
local probe_result = { ok = false, state = "missing" }
|
||||||
|
local feature_text = "缓存(离线阅读与清理) · 双页拆分 · 裁切边框"
|
||||||
|
local mirror_failed = false
|
||||||
|
local register_calls, register_ok = {}, true
|
||||||
|
local available = {}
|
||||||
|
local summary_result
|
||||||
|
local summary_all_result
|
||||||
|
local chapters_result = {}
|
||||||
|
local delete_calls, delete_all_calls = {}, 0
|
||||||
|
local delete_ok, delete_code = true, nil
|
||||||
|
local delete_all_ok, delete_all_code, delete_all_detail = true, nil, nil
|
||||||
|
-- 占用 / 计划只在详情页各取一次(06 B 的「占用只算一次」)。
|
||||||
|
local summary_calls, summary_all_calls, chapters_calls = 0, 0, 0
|
||||||
|
package.preload["moonsource_kavita.cache"] = function()
|
||||||
|
return {
|
||||||
|
probe = function() return probe_result end,
|
||||||
|
featureText = function() return feature_text end,
|
||||||
|
pluginsDir = function() return "/fake/plugins" end,
|
||||||
|
reprobe = function() return probe_result end,
|
||||||
|
mirrorFailed = function() return mirror_failed end,
|
||||||
|
registerServer = function(base_url, api_key)
|
||||||
|
register_calls[#register_calls + 1] = { base_url = base_url, api_key = api_key }
|
||||||
|
events[#events + 1] = "register"
|
||||||
|
if register_ok then return "srv-1" end
|
||||||
|
return nil, "settings_write_failed"
|
||||||
|
end,
|
||||||
|
available = function(cap) return available[cap] == true end,
|
||||||
|
summary = function()
|
||||||
|
summary_calls = summary_calls + 1
|
||||||
|
return summary_result
|
||||||
|
end,
|
||||||
|
summaryAll = function()
|
||||||
|
summary_all_calls = summary_all_calls + 1
|
||||||
|
return summary_all_result
|
||||||
|
end,
|
||||||
|
chapters = function()
|
||||||
|
chapters_calls = chapters_calls + 1
|
||||||
|
return chapters_result
|
||||||
|
end,
|
||||||
|
plan = function(entries, filter, toc_read)
|
||||||
|
local out = { chapters = 0, bytes = 0, ids = {}, queued = 0, open = false }
|
||||||
|
for __, entry in ipairs(entries or {}) do
|
||||||
|
local pages = tonumber(entry.pages) or 0
|
||||||
|
local server = toc_read and (tonumber(toc_read[tostring(entry.chapterId)]) or 0) or 0
|
||||||
|
local read = entry.read == true or (pages > 0 and server >= pages)
|
||||||
|
if filter ~= "read" or read then
|
||||||
|
out.chapters = out.chapters + 1
|
||||||
|
out.bytes = out.bytes + (tonumber(entry.bytes) or 0)
|
||||||
|
out.ids[#out.ids + 1] = entry.chapterId
|
||||||
|
if entry.queued then out.queued = out.queued + 1 end
|
||||||
|
if entry.open then out.open = true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end,
|
||||||
|
delete = function(ids)
|
||||||
|
delete_calls[#delete_calls + 1] = ids
|
||||||
|
if not delete_ok then return nil, delete_code, "nope" end
|
||||||
|
local wanted = {}
|
||||||
|
for __, id in ipairs(ids or {}) do wanted[tostring(id)] = true end
|
||||||
|
local kept = {}
|
||||||
|
for __, entry in ipairs(chapters_result) do
|
||||||
|
if not wanted[tostring(entry.chapterId)] then kept[#kept + 1] = entry end
|
||||||
|
end
|
||||||
|
chapters_result = kept
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
deleteAll = function()
|
||||||
|
delete_all_calls = delete_all_calls + 1
|
||||||
|
if delete_all_ok then return true, nil, nil, delete_all_detail end
|
||||||
|
return nil, delete_all_code, "nope"
|
||||||
|
end,
|
||||||
|
resetShelf = function() end,
|
||||||
|
capabilityNames = function(caps, separator)
|
||||||
|
local names = {}
|
||||||
|
for name, on in pairs(caps or {}) do
|
||||||
|
if on == true then names[#names + 1] = tostring(name) end
|
||||||
|
end
|
||||||
|
table.sort(names)
|
||||||
|
return #names > 0 and table.concat(names, separator or ",") or "none"
|
||||||
|
end,
|
||||||
|
sizeText = function(bytes)
|
||||||
|
local value = tonumber(bytes)
|
||||||
|
if not value then return "未知" end
|
||||||
|
return string.format("%.1f MB", value / (1024 * 1024))
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
local Themed = require("support.theme_stubs")
|
||||||
|
Themed.install()
|
||||||
|
|
||||||
|
-- kamare 在线更新:设置页只负责把行接上,网络 / 安装流程由 kamare_update_spec 钉住。
|
||||||
|
local kamare_started = 0
|
||||||
|
package.preload["moonsource_kavita.kamare_update"] = function()
|
||||||
|
return {
|
||||||
|
manualCheck = function() kamare_started = kamare_started + 1 end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local Config = require("support.config")
|
||||||
|
local PLUGIN = (debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita")
|
||||||
|
package.preload["moonsource_kavita.setting"] = function()
|
||||||
|
return dofile(PLUGIN .. "/setting.lua")
|
||||||
|
end
|
||||||
|
package.preload["moonsource_kavita.busy"] = function()
|
||||||
|
return dofile(PLUGIN .. "/busy.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
local overlays, shelf_events, overlay_updates = {}, {}, 0
|
||||||
|
local fake_desktop = {
|
||||||
|
settings_overlay = nil,
|
||||||
|
onEvent = function(_, event) shelf_events[#shelf_events + 1] = event end,
|
||||||
|
}
|
||||||
|
package.preload["desktop.pages.setting.overlay"] = function()
|
||||||
|
return {
|
||||||
|
push = function(desktop, spec)
|
||||||
|
overlays[#overlays + 1] = spec
|
||||||
|
desktop.settings_overlay = {
|
||||||
|
updateView = function() overlay_updates = overlay_updates + 1 end,
|
||||||
|
}
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local Setting = require("moonsource_kavita.setting")
|
||||||
|
|
||||||
|
local rows = Setting.rows({ path = PLUGIN, desktop = fake_desktop })
|
||||||
|
-- 顺序用文案钉住(索引不再稳定),「漫画缓存」插在「书库」之后。
|
||||||
|
local titles = {}
|
||||||
|
for _idx, make in ipairs(rows) do titles[#titles + 1] = make(600).title end
|
||||||
|
Assert.eq(#rows, 7, "服务器 / API Key / 书库 / 漫画缓存 / 进度心跳 / 请求超时 / 连接测试")
|
||||||
|
Assert.eq(table.concat(titles, "|"),
|
||||||
|
"服务器地址|API Key|书库|漫画缓存|进度心跳间隔|请求超时|测试连接",
|
||||||
|
"「漫画缓存」紧跟「书库」")
|
||||||
|
|
||||||
|
-- 03 原型的三块分组:连接 / 缓存与同步 / 诊断。
|
||||||
|
local sections = Setting.sections({ path = PLUGIN, desktop = fake_desktop })
|
||||||
|
Assert.eq(#sections, 3, "设置页分三块")
|
||||||
|
local grouped = {}
|
||||||
|
for _idx, section in ipairs(sections) do
|
||||||
|
local names = {}
|
||||||
|
for _row_idx, make in ipairs(section.rows) do names[#names + 1] = make(600).title end
|
||||||
|
grouped[#grouped + 1] = section.title .. ":" .. table.concat(names, ",")
|
||||||
|
end
|
||||||
|
Assert.eq(table.concat(grouped, "|"),
|
||||||
|
"连接:服务器地址,API Key,书库|缓存与同步:漫画缓存,进度心跳间隔,请求超时|诊断:测试连接",
|
||||||
|
"分组与原型一致,扁平的 rows 顺序不变")
|
||||||
|
|
||||||
|
--- 按标题找行(索引会随增删漂移)。
|
||||||
|
---@param title string
|
||||||
|
---@return table
|
||||||
|
local function rowAt(title)
|
||||||
|
for _idx, make in ipairs(rows) do
|
||||||
|
local row = make(600)
|
||||||
|
if row.title == title then return row end
|
||||||
|
end
|
||||||
|
error("没有这一行: " .. title)
|
||||||
|
end
|
||||||
|
|
||||||
|
Assert.eq(Setting.remote[1].key, "base_url")
|
||||||
|
Assert.eq(Setting.remote[2].key, "api_key")
|
||||||
|
Assert.is_true(Setting.remote[2].secret)
|
||||||
|
-- 远程管理网页表单只含连接配置;开关要在设备上调。
|
||||||
|
Assert.len(Setting.remote, 2, "远程管理表单只有服务器地址与 API Key")
|
||||||
|
|
||||||
|
-- 进度心跳:默认 30 秒,可调;0 = 关闭阅读期心跳。
|
||||||
|
local hb = rowAt("进度心跳间隔")
|
||||||
|
Assert.eq(hb.kind, "nav")
|
||||||
|
Assert.eq(hb.status, "30 秒")
|
||||||
|
Assert.is_true(hb.status_on)
|
||||||
|
-- 副标题单行截断(行里有状态 + 箭头,文字位很窄),必须短到放得下;「为什么」在输入框提示里。
|
||||||
|
Assert.eq(hb.subtitle, "阅读时补推进度,0 关闭")
|
||||||
|
hb.callback()
|
||||||
|
local spin = Themed.last("spin")
|
||||||
|
Assert.eq(spin.fields[1].value, 30)
|
||||||
|
Assert.eq(spin.fields[1].step, 10, "10 秒一档")
|
||||||
|
Assert.eq(spin.fields[1].min, 0)
|
||||||
|
Assert.eq(spin.fields[1].max, 600)
|
||||||
|
Assert.eq(spin.fields[1].label, "秒")
|
||||||
|
spin.callback(120)
|
||||||
|
Assert.eq(cfg.heartbeat_interval, 120)
|
||||||
|
Assert.eq(rowAt("进度心跳间隔").status, "120 秒")
|
||||||
|
Assert.eq(spin.shown and saved, 1, "保存一次")
|
||||||
|
|
||||||
|
spin.callback(0)
|
||||||
|
Assert.eq(cfg.heartbeat_interval, 0, "0 落盘成关闭")
|
||||||
|
local off = rowAt("进度心跳间隔")
|
||||||
|
Assert.eq(off.status, "已关闭")
|
||||||
|
Assert.is_false(off.status_on)
|
||||||
|
|
||||||
|
spin.callback(30)
|
||||||
|
Assert.is_nil(cfg.heartbeat_interval, "回到默认值不落盘")
|
||||||
|
|
||||||
|
-- 请求超时:默认 60 秒,10 秒一档。
|
||||||
|
local to = rowAt("请求超时")
|
||||||
|
Assert.eq(to.status, "60 秒")
|
||||||
|
Assert.is_false(to.status_on, "默认值不高亮")
|
||||||
|
to.callback()
|
||||||
|
spin = Themed.last("spin")
|
||||||
|
Assert.eq(spin.fields[1].value, 60)
|
||||||
|
Assert.eq(spin.fields[1].step, 10, "10 秒一档")
|
||||||
|
Assert.eq(spin.fields[1].min, 10)
|
||||||
|
spin.callback(180)
|
||||||
|
Assert.eq(cfg.timeout, 180)
|
||||||
|
Assert.eq(rowAt("请求超时").status, "180 秒")
|
||||||
|
Assert.is_true(rowAt("请求超时").status_on)
|
||||||
|
spin.callback(60)
|
||||||
|
Assert.is_nil(cfg.timeout, "回到默认值不落盘")
|
||||||
|
|
||||||
|
Assert.eq(saved, 5)
|
||||||
|
Assert.eq(invalidated, 5, "每次保存都作废源实例,新配置立即生效,但不广播 SourceChanged")
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 漫画缓存:七态(含旧接口/镜像失败)+ 只读详情 + 09 手动安装说明。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
local function checkStatus(probe, expected, on, mirror)
|
||||||
|
probe_result = probe
|
||||||
|
mirror_failed = mirror == true
|
||||||
|
local row = rowAt("漫画缓存")
|
||||||
|
Assert.eq(row.kind, "nav")
|
||||||
|
Assert.eq(row.status, expected)
|
||||||
|
Assert.eq(row.status_on, on, expected)
|
||||||
|
end
|
||||||
|
|
||||||
|
checkStatus({ ok = false, state = "missing" }, "未安装 / 未启用", false)
|
||||||
|
checkStatus({ ok = false, state = "official" }, "官方版(无缓存接口)", false)
|
||||||
|
checkStatus({ ok = false, state = "incompatible", api_version = 2 }, "版本不兼容", false)
|
||||||
|
checkStatus({ ok = true, state = "enhanced", api_version = 1, version = "0.10.0-dev",
|
||||||
|
capabilities = { chapters = true, delete = true, delete_all = true } },
|
||||||
|
"增强版 v0.10.0-dev", true)
|
||||||
|
-- 旧接口:有 kamarecache 但没有 chapters / delete,清理不可用,不高亮。
|
||||||
|
checkStatus({ ok = true, state = "enhanced", api_version = 1, version = "0.9.22",
|
||||||
|
capabilities = { status = true, summary = true } },
|
||||||
|
"增强版 v0.9.22(旧接口)", false)
|
||||||
|
checkStatus({ ok = true, state = "enhanced", api_version = 1 }, "增强版(旧接口)", false)
|
||||||
|
checkStatus({ ok = true, state = "enhanced", api_version = 1, version = "0.10.0-dev" },
|
||||||
|
"配置同步失败", false, true)
|
||||||
|
|
||||||
|
-- 详情页:状态 → 清理;增强态不显示安装说明。
|
||||||
|
local MB = 1024 * 1024
|
||||||
|
cfg.base_url, cfg.api_key = "http://kav", "k"
|
||||||
|
local cache_path = "/fake/plugins/kamare.koplugin/src/kamarecache.lua"
|
||||||
|
probe_result = {
|
||||||
|
ok = true, state = "enhanced", api_version = 1, version = "0.10.0-dev",
|
||||||
|
capabilities = { open = true, index = true, status = true, summary = true,
|
||||||
|
chapters = true, delete = true, delete_all = true },
|
||||||
|
path = cache_path,
|
||||||
|
}
|
||||||
|
mirror_failed = false
|
||||||
|
available = { summary = true }
|
||||||
|
summary_result = { used = 3 * MB, available = 9 * MB, chapters = 12 }
|
||||||
|
summary_all_result = { used = 4 * MB, available = 9 * MB, chapters = 15 }
|
||||||
|
chapters_result = {
|
||||||
|
{ chapterId = 1, pages = 10, bytes = 1 * MB, read = false, queued = false, open = false },
|
||||||
|
{ chapterId = 2, pages = 10, bytes = 2 * MB, read = true, queued = false, open = false },
|
||||||
|
}
|
||||||
|
|
||||||
|
local function findSection(sections, title)
|
||||||
|
for __, section in ipairs(sections or {}) do
|
||||||
|
if section.title == title then return section end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function sectionRows(sections, title)
|
||||||
|
local section = findSection(sections, title)
|
||||||
|
local out = {}
|
||||||
|
for i, make in ipairs(section and section.rows or {}) do out[i] = make(600) end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
local function statusOf(rows_list, title)
|
||||||
|
for __, row in ipairs(rows_list) do
|
||||||
|
if row.title == title then return row end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 最近一次详情页的最终 sections:先取一拍(触发占用统计),flush 后再取一次。
|
||||||
|
---@return BookThemeSection[]
|
||||||
|
local function currentSections()
|
||||||
|
overlays[#overlays].sections()
|
||||||
|
flush()
|
||||||
|
return overlays[#overlays].sections()
|
||||||
|
end
|
||||||
|
|
||||||
|
rowAt("漫画缓存").callback()
|
||||||
|
local page = overlays[#overlays]
|
||||||
|
Assert.not_nil(page, "详情走叠层,不再用 ConfirmBox")
|
||||||
|
Assert.eq(page.title, "漫画缓存")
|
||||||
|
summary_calls, summary_all_calls, chapters_calls = 0, 0, 0
|
||||||
|
overlay_updates = 0
|
||||||
|
local pending_sections = page.sections()
|
||||||
|
Assert.eq(summary_calls + summary_all_calls, 0, "先画「正在统计…」,不在这一拍走盘")
|
||||||
|
Assert.eq(statusOf(sectionRows(pending_sections, "状态"), "缓存占用").subtitle, "正在统计…")
|
||||||
|
Assert.eq(chapters_calls, 1, "清理计划一次 chapters() 取全")
|
||||||
|
flush()
|
||||||
|
Assert.eq(summary_calls, 1, "下一拍算本服务器占用")
|
||||||
|
Assert.eq(summary_all_calls, 1, "「清理全部」的合计也算出来")
|
||||||
|
Assert.eq(overlay_updates, 1, "算完刷新叠层")
|
||||||
|
local sections = page.sections()
|
||||||
|
Assert.eq(chapters_calls, 2, "重画不重算占用,只重取计划")
|
||||||
|
local status_rows = sectionRows(sections, "状态")
|
||||||
|
local version_row = statusOf(status_rows, "kamare 增强版")
|
||||||
|
Assert.eq(version_row.status, "0.10.0-dev")
|
||||||
|
Assert.is_true(version_row.chevron, "版本行可点")
|
||||||
|
Assert.eq(version_row.subtitle, "点按检查 kamare 增强版更新")
|
||||||
|
version_row.callback()
|
||||||
|
Assert.eq(kamare_started, 1, "版本行交给 kamare 在线更新模块")
|
||||||
|
Assert.eq(statusOf(status_rows, "增强版功能").subtitle, feature_text, "功能清单原样显示")
|
||||||
|
|
||||||
|
-- 清单缺失 / 不合法:不显示整行,版本行不受影响。
|
||||||
|
feature_text = nil
|
||||||
|
local without_features = sectionRows(page.sections(), "状态")
|
||||||
|
Assert.is_nil(statusOf(without_features, "增强版功能"), "没有清单隐藏功能行")
|
||||||
|
Assert.not_nil(statusOf(without_features, "kamare 增强版"), "版本行仍在")
|
||||||
|
Assert.eq(statusOf(status_rows, "加载路径").subtitle, cache_path)
|
||||||
|
Assert.eq(statusOf(status_rows, "缓存占用").status, "12 章")
|
||||||
|
Assert.matches(statusOf(status_rows, "缓存占用").subtitle, "已用 3.0 MB,可用 9.0 MB")
|
||||||
|
|
||||||
|
local cleanup_rows = sectionRows(sections, "清理")
|
||||||
|
Assert.eq(cleanup_rows[1].title, "清理已读")
|
||||||
|
Assert.matches(cleanup_rows[1].subtitle, "1 章")
|
||||||
|
Assert.eq(cleanup_rows[2].title, "清理本服务器")
|
||||||
|
Assert.matches(cleanup_rows[2].subtitle, "2 章")
|
||||||
|
Assert.eq(cleanup_rows[3].title, "清理全部")
|
||||||
|
Assert.matches(cleanup_rows[3].subtitle, "含未关联服务器 · 15 章", "全部清理用合计,不用本服务器")
|
||||||
|
Assert.is_nil(findSection(sections, "获取增强版"), "增强态不显示安装说明")
|
||||||
|
|
||||||
|
-- 维护组已移除:更新入口只在诊断页。
|
||||||
|
Assert.is_nil(findSection(sections, "维护"))
|
||||||
|
|
||||||
|
-- 清理已读:确认 → 忙碌窗 → 删除 → 复查 → 刷新。
|
||||||
|
delete_calls = {}
|
||||||
|
cleanup_rows[1].callback()
|
||||||
|
local read_confirm = Themed.last("confirm")
|
||||||
|
Assert.not_nil(read_confirm)
|
||||||
|
Assert.matches(read_confirm.text, "将删除 1 章")
|
||||||
|
local repaints_before = repaints
|
||||||
|
read_confirm.ok_callback()
|
||||||
|
local busy = Themed.last("progress_dialog")
|
||||||
|
Assert.not_nil(busy, "同步删除先弹忙碌窗")
|
||||||
|
Assert.eq(busy.title, "清理已读")
|
||||||
|
Assert.eq(busy.text, "正在清理…")
|
||||||
|
Assert.is_true(busy.dismissable == false, "忙碌窗不可关")
|
||||||
|
Assert.is_true(busy.shown, "先显示再删除")
|
||||||
|
Assert.is_true(busy.closed, "删完关闭")
|
||||||
|
Assert.eq(repaints, repaints_before + 1, "删除前强制重绘一次")
|
||||||
|
Assert.eq(#delete_calls, 1, "清理已读调用一次批量删除")
|
||||||
|
Assert.eq(#delete_calls[1], 1, "只删已读完的那一章")
|
||||||
|
Assert.matches(Themed.last("toast").text, "已清理 1 章")
|
||||||
|
Assert.eq(shelf_events[#shelf_events], "shelf_changed", "删除后刷新书架")
|
||||||
|
|
||||||
|
-- 删除后占用必须重算(03 E):只 updateView 会留下删前的数字。
|
||||||
|
summary_result = { used = 2 * MB, available = 9 * MB, chapters = 11 }
|
||||||
|
summary_all_result = { used = 3 * MB, available = 9 * MB, chapters = 14 }
|
||||||
|
local usage_calls_before = summary_calls + summary_all_calls
|
||||||
|
local after_cleanup = page.sections()
|
||||||
|
Assert.eq(statusOf(sectionRows(after_cleanup, "状态"), "缓存占用").subtitle,
|
||||||
|
"正在统计…", "删除后先画「正在统计…」")
|
||||||
|
flush()
|
||||||
|
Assert.eq(summary_calls + summary_all_calls, usage_calls_before + 2, "删除后重算本服务器与合计")
|
||||||
|
Assert.eq(statusOf(sectionRows(page.sections(), "状态"), "缓存占用").status,
|
||||||
|
"11 章", "占用数字跟着删除刷新")
|
||||||
|
Assert.matches(sectionRows(page.sections(), "清理")[3].subtitle,
|
||||||
|
"含未关联服务器 · 14 章", "清理全部的数字也刷新")
|
||||||
|
|
||||||
|
-- 空缓存:三项都置灰(03 待确认 3),清理全部不再可点。
|
||||||
|
cfg.base_url, cfg.api_key = "http://kav", "k"
|
||||||
|
probe_result = {
|
||||||
|
ok = true, state = "enhanced", api_version = 1, version = "0.10.0-dev",
|
||||||
|
capabilities = { summary = true, chapters = true, delete = true, delete_all = true },
|
||||||
|
path = cache_path,
|
||||||
|
}
|
||||||
|
available = { summary = true }
|
||||||
|
local saved_chapters = chapters_result
|
||||||
|
chapters_result = {}
|
||||||
|
summary_result = { used = 0, available = 9 * MB, chapters = 0 }
|
||||||
|
summary_all_result = { used = 0, available = 9 * MB, chapters = 0 }
|
||||||
|
rowAt("漫画缓存").callback()
|
||||||
|
local empty_rows = sectionRows(currentSections(), "清理")
|
||||||
|
for idx = 1, 3 do
|
||||||
|
Assert.is_false(empty_rows[idx].enabled, "空缓存置灰:" .. empty_rows[idx].title)
|
||||||
|
Assert.is_false(empty_rows[idx].chevron, "空缓存不显示箭头:" .. empty_rows[idx].title)
|
||||||
|
Assert.eq(empty_rows[idx].subtitle, "没有可清理的缓存", "空缓存文案:" .. empty_rows[idx].title)
|
||||||
|
end
|
||||||
|
chapters_result = saved_chapters
|
||||||
|
summary_result = { used = 3 * MB, available = 9 * MB, chapters = 12 }
|
||||||
|
summary_all_result = { used = 4 * MB, available = 9 * MB, chapters = 15 }
|
||||||
|
|
||||||
|
-- 旧接口:不出清理项,只写升级说明;设置行也不承诺清理。
|
||||||
|
probe_result = {
|
||||||
|
ok = true, state = "enhanced", api_version = 1, version = "0.9.22",
|
||||||
|
capabilities = { status = true, summary = true }, path = cache_path,
|
||||||
|
}
|
||||||
|
Assert.eq(rowAt("漫画缓存").subtitle, "状态与获取增强版", "旧接口不承诺清理")
|
||||||
|
Assert.eq(rowAt("漫画缓存").status, "增强版 v0.9.22(旧接口)")
|
||||||
|
rowAt("漫画缓存").callback()
|
||||||
|
local old_rows = sectionRows(currentSections(), "清理")
|
||||||
|
Assert.eq(#old_rows, 1, "旧接口只有一段说明")
|
||||||
|
Assert.eq(old_rows[1].title, "当前 kamare 没有清理接口")
|
||||||
|
Assert.matches(old_rows[1].subtitle, "chapters / delete_all", "说明要升级到什么")
|
||||||
|
probe_result = {
|
||||||
|
ok = true, state = "enhanced", api_version = 1, version = "0.10.0-dev",
|
||||||
|
capabilities = { open = true, index = true, status = true, summary = true,
|
||||||
|
chapters = true, delete = true, delete_all = true },
|
||||||
|
path = cache_path,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 清理全部:没有服务器也能用,确认文案含未关联。
|
||||||
|
cfg.base_url, cfg.api_key = "", ""
|
||||||
|
probe_result = {
|
||||||
|
ok = true, state = "enhanced", api_version = 1, version = "0.10.0-dev",
|
||||||
|
capabilities = { summary = true, chapters = true, delete = true, delete_all = true },
|
||||||
|
path = cache_path,
|
||||||
|
}
|
||||||
|
available = { summary = true }
|
||||||
|
rowAt("漫画缓存").callback()
|
||||||
|
summary_all_calls, summary_calls = 0, 0
|
||||||
|
local unconfigured = currentSections()
|
||||||
|
Assert.eq(sectionRows(unconfigured, "清理")[1].title, "未配置服务器")
|
||||||
|
Assert.eq(summary_all_calls, 1, "没有服务器时占用取合计")
|
||||||
|
Assert.eq(summary_calls, 0, "没有服务器时不查单服务器")
|
||||||
|
Assert.matches(statusOf(sectionRows(unconfigured, "状态"), "缓存占用").subtitle, "含未关联服务器")
|
||||||
|
sectionRows(unconfigured, "清理")[2].callback()
|
||||||
|
local all_confirm = Themed.last("confirm")
|
||||||
|
Assert.matches(all_confirm.text, "含未关联服务器")
|
||||||
|
Assert.matches(all_confirm.text, "共 15 章", "确认框用所有服务器的合计,不用本服务器")
|
||||||
|
all_confirm.ok_callback()
|
||||||
|
Assert.eq(Themed.last("progress_dialog").title, "清理全部缓存", "全部清理同样有忙碌窗")
|
||||||
|
Assert.eq(delete_all_calls, 1, "清理全部走 deleteAll")
|
||||||
|
|
||||||
|
-- 未安装:安装说明;路径归一;不显示占用。
|
||||||
|
probe_result = { ok = false, state = "missing" }
|
||||||
|
available = {}
|
||||||
|
cfg.base_url = ""
|
||||||
|
rowAt("漫画缓存").callback()
|
||||||
|
local missing = currentSections()
|
||||||
|
local missing_version = statusOf(sectionRows(missing, "状态"), "kamare 增强版")
|
||||||
|
Assert.eq(missing_version.status, "未安装")
|
||||||
|
Assert.eq(missing_version.subtitle, "点按检查并安装 kamare 增强版", "没有 kamare 时引导点版本行")
|
||||||
|
local install = findSection(missing, "获取增强版")
|
||||||
|
Assert.not_nil(install, "非增强态显示安装说明")
|
||||||
|
local install_text = install.rows[1](600).text or ""
|
||||||
|
Assert.matches(install_text, "releases/latest")
|
||||||
|
Assert.matches(install_text, "kamarecache.lua")
|
||||||
|
Assert.matches(install_text, "增强版功能随版本不同")
|
||||||
|
Assert.matches(install_text, "上方「kamare 增强版」")
|
||||||
|
Assert.matches(install_text, "koreader/plugins", "手动安装路径带 koreader/ 前缀")
|
||||||
|
Assert.is_nil(findSection(missing, "清理"), "未安装不显示清理")
|
||||||
|
|
||||||
|
-- 版本不兼容:安装说明前先讲清 API 不兼容(03 原型)。
|
||||||
|
probe_result = { ok = false, state = "incompatible", api_version = 2 }
|
||||||
|
rowAt("漫画缓存").callback()
|
||||||
|
local incompatible = sectionRows(currentSections(), "版本与获取")
|
||||||
|
Assert.eq(incompatible[1].title, "版本不兼容")
|
||||||
|
Assert.matches(incompatible[1].subtitle, "API v2")
|
||||||
|
Assert.not_nil(incompatible[2].text, "后面仍是安装说明")
|
||||||
|
|
||||||
|
-- 镜像失败:状态区给出警告 + 重试同步。
|
||||||
|
probe_result = {
|
||||||
|
ok = true, state = "enhanced", api_version = 1, version = "0.10.0-dev",
|
||||||
|
capabilities = { summary = true, chapters = true, delete = true, delete_all = true },
|
||||||
|
path = "/fake/plugins//kamare.koplugin/kamarecache.lua",
|
||||||
|
}
|
||||||
|
mirror_failed = true
|
||||||
|
available = { summary = true }
|
||||||
|
rowAt("漫画缓存").callback()
|
||||||
|
local mirrored = currentSections()
|
||||||
|
local mirror_row = statusOf(sectionRows(mirrored, "状态"), "配置同步失败")
|
||||||
|
Assert.not_nil(mirror_row, "镜像失败在状态区")
|
||||||
|
Assert.eq(mirror_row.status, "重试同步")
|
||||||
|
Assert.is_nil(statusOf(sectionRows(mirrored, "状态"), "加载路径").subtitle:find("//", 1, true),
|
||||||
|
"加载路径归一成单斜杠")
|
||||||
|
mirror_failed = false
|
||||||
|
|
||||||
|
-- 保存后镜像:先落 moon 自己的配置,再 register_server;失败 toast 但不阻断。
|
||||||
|
cfg.base_url, cfg.api_key = "http://kav", "k"
|
||||||
|
probe_result = { ok = true, state = "enhanced", api_version = 1, version = "0.10.0" }
|
||||||
|
register_calls, register_ok, events = {}, true, {}
|
||||||
|
local before = saved
|
||||||
|
rowAt("进度心跳间隔").callback()
|
||||||
|
Themed.last("spin").callback(70)
|
||||||
|
Assert.eq(saved, before + 1)
|
||||||
|
Assert.eq(register_calls[1].base_url, "http://kav")
|
||||||
|
Assert.eq(register_calls[1].api_key, "k")
|
||||||
|
Assert.eq(events[#events - 1], "save", "先存 moon 自己的配置")
|
||||||
|
Assert.eq(events[#events], "register", "镜像失败也不影响 moon 保存")
|
||||||
|
|
||||||
|
register_ok = false
|
||||||
|
before = saved
|
||||||
|
rowAt("进度心跳间隔").callback()
|
||||||
|
Themed.last("spin").callback(60)
|
||||||
|
Assert.eq(Themed.last("toast").text, "无法同步配置到 kamare", "用户主动保存失败要提示")
|
||||||
|
Assert.eq(saved, before + 1, "toast 不阻断 moon 自己的保存")
|
||||||
|
|
||||||
|
-- 未安装:不假装能镜像。
|
||||||
|
probe_result = { ok = false, state = "missing" }
|
||||||
|
register_calls = {}
|
||||||
|
rowAt("进度心跳间隔").callback()
|
||||||
|
Themed.last("spin").callback(30)
|
||||||
|
Assert.len(register_calls, 0, "没有缓存接口时跳过镜像")
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
-- 测试连接:只测 Kavita,不碰 kamare。
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
Assert.eq(rowAt("测试连接").kind, "action")
|
||||||
|
Assert.eq(rowAt("测试连接").subtitle, "检查 Kavita 服务器连接与版本")
|
||||||
|
|
||||||
|
---@param probe table
|
||||||
|
---@param mirror boolean|nil
|
||||||
|
---@param version string|nil
|
||||||
|
---@param err string|nil
|
||||||
|
---@return string
|
||||||
|
local function connectToast(probe, mirror, version, err)
|
||||||
|
probe_result = probe
|
||||||
|
mirror_failed = mirror == true
|
||||||
|
request_reply = { version = version, err = err }
|
||||||
|
rowAt("测试连接").callback()
|
||||||
|
return Themed.last("toast").text
|
||||||
|
end
|
||||||
|
|
||||||
|
local enhanced = { ok = true, state = "enhanced", api_version = 1, version = "0.10.0-dev",
|
||||||
|
capabilities = { chapters = true, delete = true, delete_all = true } }
|
||||||
|
Assert.eq(connectToast(enhanced, false, "0.9.0"), "连接正常\nKavita 0.9.0")
|
||||||
|
Assert.eq(connectToast(enhanced, true, "0.9.0"), "连接正常\nKavita 0.9.0",
|
||||||
|
"kamare 镜像失败不影响 Kavita 连接结果")
|
||||||
|
Assert.eq(connectToast({ ok = false, state = "missing" }, false, "0.9.0"),
|
||||||
|
"连接正常\nKavita 0.9.0", "测试连接不碰 kamare")
|
||||||
|
Assert.eq(connectToast({ ok = false, state = "incompatible", api_version = 2 }, false, "0.9.0"),
|
||||||
|
"连接正常\nKavita 0.9.0")
|
||||||
|
-- 版本过旧 / 请求失败仍报真正原因,不能让缓存状态盖过去。
|
||||||
|
Assert.eq(connectToast(enhanced, false, "0.8.9"),
|
||||||
|
"连接正常\nKavita 0.8.9 过旧,需要 0.9 及以上")
|
||||||
|
Assert.eq(connectToast(enhanced, false, nil, "HTTP 401"), "连接失败\nHTTP 401")
|
||||||
|
Assert.eq(connectToast(enhanced, false, nil, nil), "连接正常\n无法识别 Kavita 版本")
|
||||||
|
|
||||||
|
-- 换服务器清理失败:共享配置、磁盘、kamare 镜像都必须保持旧值。
|
||||||
|
do
|
||||||
|
cfg.base_url, cfg.api_key = "http://old", "old-key"
|
||||||
|
local saved_before, mirrored_before = saved, #register_calls
|
||||||
|
package.loaded["source.logout"] = {
|
||||||
|
replaceLibrary = function() return false end,
|
||||||
|
}
|
||||||
|
rowAt("服务器地址").callback()
|
||||||
|
Themed.last("input").callback("http://new")
|
||||||
|
Assert.eq(cfg.base_url, "http://old")
|
||||||
|
Assert.eq(cfg.api_key, "old-key")
|
||||||
|
Assert.eq(saved, saved_before)
|
||||||
|
Assert.eq(#register_calls, mirrored_before)
|
||||||
|
Assert.eq(Themed.last("toast").text, "准备本地同步失败")
|
||||||
|
end
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
--[[--
|
||||||
|
Kavita 源的书架缓存钩子:shelf_cache 能力、shelfCache 同步返回投影、
|
||||||
|
syncBooksAsync 同步后预热(05 A1)、coverRequest 优先本地封面(05 A8)。
|
||||||
|
|
||||||
|
不复用 source_spec 的整套书架夹具:这里只碰钩子本身,HTTP / 书库 / 目录都最小打桩。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.shelf_cache_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
local Stubs = require("support.stubs")
|
||||||
|
Stubs.install()
|
||||||
|
|
||||||
|
-- 日志:pcall 的失败必须被检查并记录,不能静默吞掉(项目审计口径)。
|
||||||
|
local warns = {}
|
||||||
|
package.loaded["utils.log"] = {
|
||||||
|
dbg = function() end,
|
||||||
|
info = function() end,
|
||||||
|
error = function() end,
|
||||||
|
warn = function(...)
|
||||||
|
local parts = {}
|
||||||
|
for index = 1, select("#", ...) do
|
||||||
|
parts[#parts + 1] = tostring(select(index, ...))
|
||||||
|
end
|
||||||
|
warns[#warns + 1] = table.concat(parts, " ")
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
local PLUGIN = (debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita")
|
||||||
|
-- 走 preload 不改 package.path:插件根上的 main.lua 会顶掉月读的 main。
|
||||||
|
for _idx, name in ipairs({ "client", "position", "annotation", "source", "cache", "volume_list", "stats" }) do
|
||||||
|
package.preload["moonsource_kavita" .. (name == "source" and ".source" or "." .. name)] = function()
|
||||||
|
return dofile(PLUGIN .. "/" .. (name == "source" and "source" or name) .. ".lua")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 往返桩:encode 登记表并发令牌,decode 凭令牌取回(不是令牌就报错,同真解析器)。
|
||||||
|
local encoded = {}
|
||||||
|
package.preload["json"] = function()
|
||||||
|
return {
|
||||||
|
encode = function(value)
|
||||||
|
encoded[#encoded + 1] = value
|
||||||
|
return "\0json" .. #encoded
|
||||||
|
end,
|
||||||
|
decode = function(text)
|
||||||
|
return encoded[tonumber(text:match("^%z?json(%d+)$"))] or error("not json: " .. text)
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local cfg = { base_url = "http://kav/", api_key = "k", libraries = { ["1"] = true } }
|
||||||
|
package.preload["utils.settings"] = function()
|
||||||
|
return {
|
||||||
|
get = function() return { active_source = "local" } end,
|
||||||
|
save = function() end,
|
||||||
|
getSource = function() return cfg end,
|
||||||
|
saveSource = function() end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- HTTP:只有书架快照这一个路由。
|
||||||
|
local routes, requested = {}, {}
|
||||||
|
package.preload["http.request"] = function()
|
||||||
|
return {
|
||||||
|
ok = function(code)
|
||||||
|
code = tonumber(code)
|
||||||
|
return code ~= nil and code >= 200 and code < 300
|
||||||
|
end,
|
||||||
|
header = function() end,
|
||||||
|
request = function(opts, cb)
|
||||||
|
requested[#requested + 1] = opts
|
||||||
|
local route = routes[opts.method .. " " .. opts.url:match("^http://kav(/[^?]*)")]
|
||||||
|
require("ui/uimanager"):nextTick(function()
|
||||||
|
cb(route and route(opts) or { code = 404, body = "" })
|
||||||
|
end)
|
||||||
|
return { cancel = function() end }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 本地库:钩子只需要「取一本书」与「已同步身份」。
|
||||||
|
local books = {}
|
||||||
|
package.loaded["book.books_db"] = {
|
||||||
|
get = function(_source_id, stable_id) return books[stable_id] end,
|
||||||
|
libraryStableIdsBySource = function() return {} end,
|
||||||
|
}
|
||||||
|
package.loaded["book.progress_db"] = {
|
||||||
|
get = function() return nil end,
|
||||||
|
}
|
||||||
|
package.loaded["book.store"] = { rememberMany = function() end }
|
||||||
|
|
||||||
|
local sequence = {}
|
||||||
|
package.loaded["source.shelf"] = {
|
||||||
|
reconcile = function(_source_id, list)
|
||||||
|
sequence[#sequence + 1] = "reconcile"
|
||||||
|
return { pulled = #list, pushed = 0, hidden = 0, conflicts = 0, skipped = false }
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 封面路径只关心「本地缓存 / 在线地址」的分支:目录查不到卷时退回系列封面(卷封面见 source_spec)。
|
||||||
|
package.loaded["source.toc"] = { read = function() return nil end }
|
||||||
|
local SourceMod = require("moonsource_kavita.source")
|
||||||
|
local Cache = require("moonsource_kavita.cache")
|
||||||
|
local source = SourceMod.new()
|
||||||
|
|
||||||
|
-- 能力:声明 shelf_cache,UI 据此决定断网时是否收窄书架(05 A2)。
|
||||||
|
local caps = source:capabilities()
|
||||||
|
Assert.is_true(caps.shelf_cache, "Kavita 声明书架缓存能力")
|
||||||
|
Assert.is_true(caps.stats_pull, "原有能力不受影响")
|
||||||
|
|
||||||
|
-- shelfCache:同步返回适配层记忆的投影;未配置不触盘。
|
||||||
|
local projection = { series_ids = { ["700"] = true }, mark = { ["700"] = true }, cover = {} }
|
||||||
|
local shelf_calls = 0
|
||||||
|
local real_shelf = Cache.shelf
|
||||||
|
Cache.shelf = function()
|
||||||
|
shelf_calls = shelf_calls + 1
|
||||||
|
return projection
|
||||||
|
end
|
||||||
|
Assert.eq(source:shelfCache(), projection, "shelfCache 原样交回适配层投影")
|
||||||
|
Assert.eq(shelf_calls, 1)
|
||||||
|
cfg.base_url = ""
|
||||||
|
Assert.is_nil(SourceMod.new():shelfCache(), "未配置返回 nil")
|
||||||
|
Assert.eq(shelf_calls, 1, "未配置不读投影")
|
||||||
|
cfg.base_url = "http://kav/"
|
||||||
|
|
||||||
|
-- coverRequest:投影里有本地封面且文件存在 → 本地路径,不再走鉴权 URL(05 A8)。
|
||||||
|
local cover_path = Config.dir() .. "/shelf_cover_700.jpg"
|
||||||
|
local file = assert(io.open(cover_path, "wb"))
|
||||||
|
file:write("jpg")
|
||||||
|
file:close()
|
||||||
|
Cache.shelf = function() return { series_ids = {}, mark = {}, cover = { ["700"] = cover_path } } end
|
||||||
|
local req = select(1, source:coverRequest({ source_id = "kavita", stable_id = "700" }))
|
||||||
|
Assert.eq(req.url, cover_path, "已缓存系列用本地封面")
|
||||||
|
Assert.is_nil(req.headers, "本地文件不需要鉴权头")
|
||||||
|
Assert.eq(req.authoritative, true, "源封面压过本地抽页缓存")
|
||||||
|
-- 卷身份同样借系列封面(chapter-cover 是扫描页,不能当封面)。
|
||||||
|
req = select(1, source:coverRequest({ source_id = "kavita", stable_id = "700:7001" }))
|
||||||
|
Assert.eq(req.url, cover_path, "卷身份也用已缓存系列封面")
|
||||||
|
-- 投影给了路径但文件没了 → 维持在线系列封面。
|
||||||
|
Cache.shelf = function() return { series_ids = {}, mark = {}, cover = { ["700"] = cover_path .. ".gone" } } end
|
||||||
|
req = select(1, source:coverRequest({ source_id = "kavita", stable_id = "700" }))
|
||||||
|
Assert.is_true(req.url:find("series-cover", 1, true) ~= nil, "文件不存在退回在线封面")
|
||||||
|
Assert.not_nil(req.headers)
|
||||||
|
req = select(1, source:coverRequest({ source_id = "kavita", stable_id = "700:7001" }))
|
||||||
|
Assert.is_true(req.url:find("series-cover", 1, true) ~= nil, "卷身份也走系列封面")
|
||||||
|
-- 适配层没给投影(无 index):照旧在线封面。
|
||||||
|
Cache.shelf = function() return nil end
|
||||||
|
req = select(1, source:coverRequest({ source_id = "kavita", stable_id = "700" }))
|
||||||
|
Assert.is_true(req.url:find("series-cover", 1, true) ~= nil)
|
||||||
|
Cache.shelf = real_shelf
|
||||||
|
|
||||||
|
-- syncBooksAsync 预热:对账后、回调前把投影建好,进书架时 O(1)(05 A1)。
|
||||||
|
sequence, requested = {}, {}
|
||||||
|
Cache.shelf = function()
|
||||||
|
sequence[#sequence + 1] = "shelf"
|
||||||
|
return projection
|
||||||
|
end
|
||||||
|
routes["POST /api/Series/all-v2"] = function()
|
||||||
|
return { code = 200, body = require("json").encode({
|
||||||
|
{ id = 700, name = "漫画一", libraryName = "漫画", wordCount = 10 },
|
||||||
|
}) }
|
||||||
|
end
|
||||||
|
source.backfillMeta = function() end
|
||||||
|
local synced
|
||||||
|
source:syncBooksAsync(nil, function(result, err)
|
||||||
|
sequence[#sequence + 1] = "cb"
|
||||||
|
synced = { result = result, err = err }
|
||||||
|
end)
|
||||||
|
Stubs.flush()
|
||||||
|
Assert.not_nil(synced)
|
||||||
|
Assert.is_nil(synced.err)
|
||||||
|
Assert.eq(synced.result.pulled, 1, "对账结果照旧回调")
|
||||||
|
Assert.eq(table.concat(sequence, ","), "reconcile,shelf,cb", "预热排在回调之前")
|
||||||
|
|
||||||
|
-- 手动刷新 / 书库重扫(force)必须让投影失效并重建;后台同步沿用记忆(05 A1)。
|
||||||
|
-- 拉回的新缓存状态看不见 = 用户点了刷新但书架标记不更新。
|
||||||
|
sequence, requested = {}, {}
|
||||||
|
local resets = 0
|
||||||
|
local real_reset = Cache.resetShelf
|
||||||
|
Cache.resetShelf = function()
|
||||||
|
resets = resets + 1
|
||||||
|
sequence[#sequence + 1] = "reset"
|
||||||
|
end
|
||||||
|
Cache.shelf = function()
|
||||||
|
sequence[#sequence + 1] = "shelf"
|
||||||
|
return projection
|
||||||
|
end
|
||||||
|
local background
|
||||||
|
source:syncBooksAsync(nil, function(result, err) background = { result = result, err = err } end)
|
||||||
|
Stubs.flush()
|
||||||
|
Assert.not_nil(background and background.result)
|
||||||
|
Assert.eq(resets, 0, "后台同步不丢投影")
|
||||||
|
Assert.eq(table.concat(sequence, ","), "reconcile,shelf", "后台同步只预热现有记忆")
|
||||||
|
sequence = {}
|
||||||
|
local forced
|
||||||
|
source:syncBooksAsync({ force = true }, function(result, err) forced = { result = result, err = err } end)
|
||||||
|
Stubs.flush()
|
||||||
|
Assert.not_nil(forced and forced.result)
|
||||||
|
Assert.eq(resets, 1, "手动刷新让投影失效")
|
||||||
|
Assert.eq(table.concat(sequence, ","), "reset,reconcile,shelf", "重扫先失效再重建,回调前投影已就绪")
|
||||||
|
sequence = {}
|
||||||
|
Cache.resetShelf = real_reset
|
||||||
|
|
||||||
|
-- 预热失败不拖垮同步:投影只是书架标记,缓存模块异常照样要回调对账结果。
|
||||||
|
sequence, requested = {}, {}
|
||||||
|
warns = {}
|
||||||
|
local broken_sequence = sequence
|
||||||
|
Cache.shelf = function()
|
||||||
|
broken_sequence[#broken_sequence + 1] = "shelf"
|
||||||
|
error("kamare index broken")
|
||||||
|
end
|
||||||
|
local second
|
||||||
|
source:syncBooksAsync(nil, function(result, err) second = { result = result, err = err } end)
|
||||||
|
Stubs.flush()
|
||||||
|
Assert.not_nil(second and second.result, "预热异常不影响同步结果")
|
||||||
|
Assert.eq(table.concat(sequence, ","), "reconcile,shelf")
|
||||||
|
-- 第二次仍失败:不能每次同步都刷一行日志(一次性),但也不能静默。
|
||||||
|
source:syncBooksAsync(nil, function(result, err) second = { result = result, err = err } end)
|
||||||
|
Stubs.flush()
|
||||||
|
Assert.eq(#warns, 1, "投影预热失败检查并只记一次")
|
||||||
|
Assert.matches(warns[1] or "", "shelf")
|
||||||
|
Cache.shelf = real_shelf
|
||||||
|
|
||||||
|
-- Registry.reload() 会重建源实例:新实例顺手丢掉旧服务器的投影(05 A1 的第三类失效点)。
|
||||||
|
local resets = 0
|
||||||
|
local real_reset = Cache.resetShelf
|
||||||
|
Cache.resetShelf = function()
|
||||||
|
resets = resets + 1
|
||||||
|
return real_reset()
|
||||||
|
end
|
||||||
|
SourceMod.new()
|
||||||
|
Assert.eq(resets, 1, "重建源实例即失效书架投影")
|
||||||
|
Cache.resetShelf = real_reset
|
||||||
|
|
||||||
|
return true
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,664 @@
|
|||||||
|
--[[--
|
||||||
|
moonsource_kavita.stats:reading-history 条目 → reading_stats 行 / 替换指令 / 身份与时区映射。
|
||||||
|
|
||||||
|
对账基线 = research-kavita-stats-pull.md §3(样本 series 7453:64 条会话 / 14,237s)。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.stats_spec
|
||||||
|
--]]
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
|
||||||
|
-- 日 / 时归属按进程时区(POSIX TZ)计算:钉死 CST-8,与 fixture 拉取时用的 Asia/Shanghai 对齐,
|
||||||
|
-- 断言就不会随宿主机时区漂移。
|
||||||
|
local ffi = require("ffi")
|
||||||
|
ffi.cdef[[ int setenv(const char*, const char*, int); void tzset(void); ]]
|
||||||
|
ffi.C.setenv("TZ", "CST-8", 1)
|
||||||
|
ffi.C.tzset()
|
||||||
|
|
||||||
|
local warnings = {}
|
||||||
|
package.preload["utils.log"] = function()
|
||||||
|
return {
|
||||||
|
dbg = function() end,
|
||||||
|
info = function() end,
|
||||||
|
warn = function(...) warnings[#warnings + 1] = table.concat({ ... }, " ") end,
|
||||||
|
error = function() end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local PLUGIN = (debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita")
|
||||||
|
package.preload["moonsource_kavita.stats"] = function()
|
||||||
|
return dofile(PLUGIN .. "/stats.lua")
|
||||||
|
end
|
||||||
|
local Stats = require("moonsource_kavita.stats")
|
||||||
|
|
||||||
|
-- 固定拉取时刻(2026-10-16T12:00:00Z,晚于样本最后一天):last_time / book_total.start_time 都对它断言
|
||||||
|
local FETCHED = 1792152000
|
||||||
|
|
||||||
|
--- 当天设备本地零点。日期本身来自服务端;期望时差另有 research §3 表兜底。
|
||||||
|
local function dayTs(y, m, d)
|
||||||
|
return os.time({ year = y, month = m, day = d, hour = 0 })
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 当天设备本地整点(时段桶键)。
|
||||||
|
local function hourTs(y, m, d, h)
|
||||||
|
return os.time({ year = y, month = m, day = d, hour = h })
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 按记录身份找行(不依赖 rows 顺序)。
|
||||||
|
local function find(rows, record_type, stable_id, start_time)
|
||||||
|
for _idx, row in ipairs(rows) do
|
||||||
|
if row.record_type == record_type and row.stable_id == stable_id
|
||||||
|
and (start_time == nil or row.start_time == start_time) then
|
||||||
|
return row
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 需要跨日断言时看日归属是否真是「服务端那一天」。
|
||||||
|
local function ymd(ts)
|
||||||
|
return os.date("%Y-%m-%d", ts)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 对账:样本《太空漫游 · 2010》64 条会话。逐日时长 / 页数为 research §3 的已知值。
|
||||||
|
local history = dofile((debug.getinfo(1, "S").source:match("^@(.*)/")) .. "/fixtures/history_7453.lua")
|
||||||
|
local result = Stats.fromHistory(history, {
|
||||||
|
source_id = "kavita",
|
||||||
|
fetched_at = FETCHED,
|
||||||
|
volumes = { [7453] = 4 },
|
||||||
|
seen = { "7453:11270" },
|
||||||
|
})
|
||||||
|
|
||||||
|
local total = find(result.rows, "total", "__kv:total", 0)
|
||||||
|
Assert.not_nil(total, "账户累计行必须存在")
|
||||||
|
Assert.eq(total.duration, 14237, "样本全量时长")
|
||||||
|
Assert.eq(total.last_time, FETCHED, "累计行 last_time = 拉取时刻")
|
||||||
|
|
||||||
|
local days = {
|
||||||
|
{ 2026, 9, 29, 316, 2 },
|
||||||
|
{ 2026, 10, 5, 195, 0 },
|
||||||
|
{ 2026, 10, 7, 503, 0 },
|
||||||
|
{ 2026, 10, 8, 2036, 0 },
|
||||||
|
{ 2026, 10, 11, 512, 0 },
|
||||||
|
{ 2026, 10, 13, 979, 0 },
|
||||||
|
{ 2026, 10, 14, 6734, 0 }, -- 当天 +1 / -1 分属两条会话:先求和再钳制,相抵为净 0 页
|
||||||
|
{ 2026, 10, 15, 2962, 16 },
|
||||||
|
}
|
||||||
|
local day_rows = 0
|
||||||
|
local day_sum = 0
|
||||||
|
local day_ts = {}
|
||||||
|
for _idx, d in ipairs(days) do
|
||||||
|
local ts = dayTs(d[1], d[2], d[3])
|
||||||
|
day_ts[ts] = true
|
||||||
|
local row = find(result.rows, "day", "__kv:day:" .. ts, ts)
|
||||||
|
Assert.not_nil(row, "缺少日桶 " .. d[1] .. "-" .. d[2] .. "-" .. d[3])
|
||||||
|
Assert.eq(row.duration, d[4], "日桶时长 " .. ymd(ts))
|
||||||
|
Assert.eq(row.event_count, d[5], "日桶页数增量 " .. ymd(ts))
|
||||||
|
Assert.eq(row.last_time, FETCHED, "日桶 last_time = 拉取时刻")
|
||||||
|
day_rows = day_rows + 1
|
||||||
|
day_sum = day_sum + row.duration
|
||||||
|
end
|
||||||
|
Assert.eq(day_rows, 8, "只有有有效时长的日子落桶")
|
||||||
|
Assert.eq(day_sum, 14237, "账户累计 = 各日之和")
|
||||||
|
|
||||||
|
-- 时段桶:每条活动行按自己的本地起始小时归档(跨零点的活动行取小时、仍记在条目那天)。
|
||||||
|
local hour_rows, hour_total = 0, 0
|
||||||
|
local hour_by_day = {}
|
||||||
|
for _idx, row in ipairs(result.rows) do
|
||||||
|
if row.record_type == "hour" then
|
||||||
|
hour_rows = hour_rows + 1
|
||||||
|
hour_total = hour_total + row.duration
|
||||||
|
Assert.eq(row.stable_id, "__kv:hour:" .. row.start_time, "时段桶按整点做身份")
|
||||||
|
Assert.eq(row.last_time, FETCHED, "时段桶 last_time = 拉取时刻")
|
||||||
|
local d = os.date("%Y-%m-%d", row.start_time)
|
||||||
|
hour_by_day[d] = (hour_by_day[d] or 0) + row.duration
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Assert.eq(hour_rows, 27, "样本 27 个整点有阅读")
|
||||||
|
Assert.eq(hour_total, 14237, "时段之和 = 账户累计")
|
||||||
|
Assert.eq(find(result.rows, "hour", "__kv:hour:" .. hourTs(2026, 10, 14, 11)).duration, 1352, "10-14 11 点")
|
||||||
|
Assert.eq(find(result.rows, "hour", "__kv:hour:" .. hourTs(2026, 10, 14, 14)).duration, 1812, "10-14 14 点")
|
||||||
|
Assert.eq(find(result.rows, "hour", "__kv:hour:" .. hourTs(2026, 9, 29, 18)).duration, 316, "9-29 18 点")
|
||||||
|
Assert.eq(find(result.rows, "hour", "__kv:hour:" .. hourTs(2026, 10, 15, 21)).duration, 845, "10-15 21 点")
|
||||||
|
-- 日页面「标题时长 = 时段图逐格之和」:逐日必须对得上
|
||||||
|
for _idx, d in ipairs(days) do
|
||||||
|
Assert.eq(hour_by_day[ymd(dayTs(d[1], d[2], d[3]))], d[4],
|
||||||
|
"时段逐日之和 = 日桶 " .. d[1] .. "-" .. d[2] .. "-" .. d[3])
|
||||||
|
end
|
||||||
|
-- 零时长会话(10-06 的 4 条等)整条丢弃,不留日桶
|
||||||
|
for _idx, d in ipairs({ { 2026, 10, 6 }, { 2026, 10, 9 }, { 2026, 10, 10 }, { 2026, 10, 12 } }) do
|
||||||
|
local ts = dayTs(d[1], d[2], d[3])
|
||||||
|
Assert.is_nil(find(result.rows, "day", "__kv:day:" .. ts, ts), "零时长日不留桶")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 多卷系列:章节 4 卷 → 逐卷身份;11271 只在 9-29 读过,11273 是其余各日。
|
||||||
|
local book_total = find(result.rows, "book_total", "7453:11273", FETCHED)
|
||||||
|
Assert.not_nil(book_total, "卷累计行")
|
||||||
|
Assert.eq(book_total.duration, 13921)
|
||||||
|
Assert.eq(find(result.rows, "book_total", "7453:11271", FETCHED).duration, 316)
|
||||||
|
|
||||||
|
Assert.eq(find(result.rows, "book_day", "7453:11271", dayTs(2026, 9, 29)).duration, 316)
|
||||||
|
local book_days, book_totals = 0, 0
|
||||||
|
for _idx, row in ipairs(result.rows) do
|
||||||
|
if row.record_type == "book_day" then
|
||||||
|
book_days = book_days + 1
|
||||||
|
Assert.is_true(row.duration > 0, "单书日行也必须正时长")
|
||||||
|
Assert.is_true(day_ts[row.start_time] == true, "单书日行 start_time = 服务端那天的本地零点")
|
||||||
|
elseif row.record_type == "book_total" then
|
||||||
|
book_totals = book_totals + 1
|
||||||
|
Assert.eq(row.start_time, FETCHED, "单书累计行的 start_time = 拉取时刻")
|
||||||
|
end
|
||||||
|
-- 云端快照没有页坐标,所有行 page / total_pages 恒为 0
|
||||||
|
Assert.eq(row.page, 0, "云端行 page=0")
|
||||||
|
Assert.eq(row.total_pages, 0, "云端行 total_pages=0")
|
||||||
|
Assert.eq(row.source_id, "kavita")
|
||||||
|
end
|
||||||
|
Assert.eq(book_days, 8, "11271 一天 + 11273 七天")
|
||||||
|
Assert.eq(book_totals, 2, "每卷一条累计快照")
|
||||||
|
|
||||||
|
-- 本次身份:持久化后下次当「上次身份」用于清孤儿行。
|
||||||
|
Assert.eq(#result.identities, 2)
|
||||||
|
Assert.contains(result.identities, "7453:11271")
|
||||||
|
Assert.contains(result.identities, "7453:11273")
|
||||||
|
|
||||||
|
-- 替换:账户桶按前缀 + 覆盖全量重拉窗口的时间窗;单书按上次 ∪ 本次身份精确清。
|
||||||
|
Assert.eq(result.replace.mode, "ranges")
|
||||||
|
Assert.eq(#result.replace.ranges, 3)
|
||||||
|
local ranges = {}
|
||||||
|
for _idx, range in ipairs(result.replace.ranges) do ranges[range.stable_prefix] = range end
|
||||||
|
local day_range, hour_range, total_range =
|
||||||
|
ranges["__kv:day:"], ranges["__kv:hour:"], ranges["__kv:total"]
|
||||||
|
Assert.not_nil(day_range, "日桶清理范围")
|
||||||
|
Assert.not_nil(hour_range, "时段桶清理范围")
|
||||||
|
Assert.not_nil(total_range, "总量行清理范围")
|
||||||
|
Assert.eq(day_range.from_ts, 0)
|
||||||
|
Assert.eq(day_range.to_ts, FETCHED)
|
||||||
|
Assert.eq(hour_range.from_ts, 0)
|
||||||
|
Assert.eq(hour_range.to_ts, FETCHED)
|
||||||
|
Assert.eq(total_range.from_ts, 0)
|
||||||
|
Assert.eq(total_range.to_ts, 0)
|
||||||
|
-- 全量重拉的清理窗口必须盖住本次写出的每个桶,否则消失的桶会残留
|
||||||
|
for _idx, row in ipairs(result.rows) do
|
||||||
|
if row.record_type == "day" then
|
||||||
|
Assert.is_true(row.start_time <= day_range.to_ts, "日桶落在清理窗口内")
|
||||||
|
elseif row.record_type == "hour" then
|
||||||
|
Assert.is_true(row.start_time <= hour_range.to_ts, "时段桶落在清理窗口内")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Assert.eq(#result.replace.books, 3, "上次身份 ∪ 本次身份(含漂移孤儿)")
|
||||||
|
Assert.contains(result.replace.books, "7453:11270")
|
||||||
|
Assert.contains(result.replace.books, "7453:11271")
|
||||||
|
Assert.contains(result.replace.books, "7453:11273")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 多章会话(跨卷)按章拆到各卷;单卷系列读在 series 行(research §5 的身份约定)。
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 55, localDate = "2026-10-10T00:00:00", chapters = {
|
||||||
|
{ chapterId = 11, durationSeconds = 100, pagesRead = 2 },
|
||||||
|
{ chapterId = 12, durationSeconds = 50, pagesRead = -1 },
|
||||||
|
} },
|
||||||
|
{ seriesId = 66, localDate = "2026-10-10T00:00:00", chapters = {
|
||||||
|
{ chapterId = 21, durationSeconds = 70, pagesRead = 0 },
|
||||||
|
} },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [55] = 2, [66] = 1 } })
|
||||||
|
local day = dayTs(2026, 10, 10)
|
||||||
|
Assert.eq(find(result.rows, "book_day", "55:11", day).duration, 100)
|
||||||
|
Assert.eq(find(result.rows, "book_day", "55:12", day).duration, 50)
|
||||||
|
Assert.eq(find(result.rows, "book_day", "66", day).duration, 70, "单卷记 series 身份")
|
||||||
|
Assert.eq(find(result.rows, "book_total", "55:11", 2000).duration, 100)
|
||||||
|
Assert.eq(find(result.rows, "book_total", "66", 2000).duration, 70)
|
||||||
|
local day_row = find(result.rows, "day", "__kv:day:" .. day, day)
|
||||||
|
Assert.eq(day_row.duration, 220, "账户日是各章之和")
|
||||||
|
Assert.eq(day_row.event_count, 1, "当天页数先求和:2 + (-1) + 0")
|
||||||
|
Assert.eq(find(result.rows, "total", "__kv:total", 0).duration, 220)
|
||||||
|
-- 没有 startTimeUtc 的条目退回 localDate 分日;造不出小时就不造,绝不凭空补一个整点。
|
||||||
|
for _idx, row in ipairs(result.rows) do
|
||||||
|
Assert.is_true(row.record_type ~= "hour", "缺 startTimeUtc 不造时段桶")
|
||||||
|
end
|
||||||
|
Assert.len(result.identities, 3)
|
||||||
|
Assert.contains(result.identities, "55:11")
|
||||||
|
Assert.contains(result.identities, "55:12")
|
||||||
|
Assert.contains(result.identities, "66")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 分日 / 分时按服务端 UTC 时刻在设备本地(CST-8)换算,不信服务端按请求时区给的 localDate。
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
-- 本地 10-16 07:59(UTC 10-15 23:59):服务端若按 UTC 算 localDate 会给 10-15,差一天。
|
||||||
|
{ seriesId = 31, startTimeUtc = "2026-10-15T23:59:00.1", localDate = "2026-10-15T00:00:00",
|
||||||
|
chapters = { { chapterId = 1, startTimeUtc = "2026-10-15T23:59:00.1", durationSeconds = 60, pagesRead = 1 } } },
|
||||||
|
-- 本地 10-17 00:30 起、23:50 又读了一段:日桶在 10-17,两个时段格也都算 10-17 这天。
|
||||||
|
{ seriesId = 32, startTimeUtc = "2026-10-16T16:30:00", localDate = "2026-10-17T00:00:00",
|
||||||
|
chapters = {
|
||||||
|
{ chapterId = 1, startTimeUtc = "2026-10-16T16:30:00", durationSeconds = 40, pagesRead = 0 },
|
||||||
|
{ chapterId = 1, startTimeUtc = "2026-10-17T15:50:00", durationSeconds = 60, pagesRead = 0 },
|
||||||
|
} },
|
||||||
|
}, { source_id = "kavita", fetched_at = FETCHED, volumes = { [31] = 2, [32] = 2, [33] = 2 } })
|
||||||
|
local d16, d17 = dayTs(2026, 10, 16), dayTs(2026, 10, 17)
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d16, d16).duration, 60, "本地 07:59 落本地当天")
|
||||||
|
Assert.eq(find(result.rows, "hour", "__kv:hour:" .. hourTs(2026, 10, 16, 7)).duration, 60, "本地 7 点格")
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d17, d17).duration, 100, "本地 0:30 起的那条落 10-17")
|
||||||
|
Assert.eq(find(result.rows, "hour", "__kv:hour:" .. hourTs(2026, 10, 17, 0)).duration, 40, "0 点格")
|
||||||
|
Assert.eq(find(result.rows, "hour", "__kv:hour:" .. hourTs(2026, 10, 17, 23)).duration, 60, "23 点格")
|
||||||
|
Assert.is_nil(find(result.rows, "hour", "__kv:hour:" .. hourTs(2026, 10, 18, 0)),
|
||||||
|
"跨零点前的活动行不另起一天")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 负页数:按天先求和再钳制。逐条钳制会让 +5 / -5 相抵的日子凭空多出 5 页。
|
||||||
|
local d1, d2 = dayTs(2026, 10, 1), dayTs(2026, 10, 2)
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 7, localDate = "2026-10-01T00:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 10, pagesRead = 5 } } },
|
||||||
|
{ seriesId = 7, localDate = "2026-10-01T00:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 10, pagesRead = -5 } } },
|
||||||
|
{ seriesId = 7, localDate = "2026-10-02T00:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 10, pagesRead = -3 },
|
||||||
|
{ chapterId = 1, durationSeconds = 10, pagesRead = -4 } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = 3000, volumes = { [7] = 2 } })
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d1, d1).event_count, 0, "正负相抵为净 0")
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d2, d2).event_count, 0, "负和钳制到 0")
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d1, d1).duration, 20)
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d2, d2).duration, 20)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 时区回退(UTC)下服务端的「日」可能晚于设备本地的拉取时刻(设备为负偏移):
|
||||||
|
-- 日桶清理窗口的上界要盖到最后观测日的日终,否则当天桶清不掉,会残留到下一轮。
|
||||||
|
local last_day = dayTs(2026, 10, 16)
|
||||||
|
local fetched = last_day - 600 -- 设备本地 23:50,比最后观测日的零点还早
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 21, localDate = "2026-10-16T00:00:00",
|
||||||
|
chapters = { { chapterId = 1, durationSeconds = 300, pagesRead = 1 } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = fetched, volumes = { [21] = 2 } })
|
||||||
|
local day_range
|
||||||
|
for _idx, range in ipairs(result.replace.ranges) do
|
||||||
|
if range.stable_prefix == "__kv:day:" then day_range = range end
|
||||||
|
end
|
||||||
|
Assert.not_nil(day_range)
|
||||||
|
Assert.eq(day_range.from_ts, 0, "窗口下界仍是 0(全量重拉)")
|
||||||
|
Assert.eq(day_range.to_ts, last_day + 86399, "上界盖到最后观测日的日终")
|
||||||
|
for _idx, row in ipairs(result.rows) do
|
||||||
|
if row.record_type == "day" then
|
||||||
|
Assert.is_true(row.start_time <= day_range.to_ts, "日桶落在清理窗口内")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Assert.eq(day_range.stable_prefix:sub(1, 5), "__kv:", "范围只匹配本源的合成行,本地记录不受影响")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 零时长条目整条丢弃(连页数一起):Kavita 会给「打开没读」建 0 时长会话。
|
||||||
|
-- 本次身份照交回,好让 replace.books 清掉它上次留下的行。
|
||||||
|
local d = dayTs(2026, 10, 3)
|
||||||
|
local before = #warnings
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 8, localDate = "2026-10-03T00:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 0, pagesRead = 9 } } },
|
||||||
|
{ seriesId = 8, localDate = "2026-10-03T00:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = 0 } } },
|
||||||
|
-- 目录拿不到章数的系列判不出身份:整体跳过,不猜单卷 / 多卷
|
||||||
|
{ seriesId = 999, localDate = "2026-10-03T00:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 100, pagesRead = 1 } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = 4000, volumes = { [8] = 2 }, seen = { "8:1" } })
|
||||||
|
Assert.eq(find(result.rows, "book_day", "8:1", d).duration, 60)
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d, d).event_count, 0, "零时长条目的页数不算")
|
||||||
|
Assert.eq(find(result.rows, "total", "__kv:total", 0).duration, 60, "跳过的系列不进总量")
|
||||||
|
Assert.eq(#result.identities, 1)
|
||||||
|
Assert.contains(result.identities, "8:1")
|
||||||
|
Assert.eq(#result.replace.books, 1)
|
||||||
|
Assert.contains(result.replace.books, "8:1")
|
||||||
|
local mentioned = false
|
||||||
|
for i = before + 1, #warnings do
|
||||||
|
if warnings[i]:find("999", 1, true) then mentioned = true end
|
||||||
|
end
|
||||||
|
Assert.is_true(mentioned, "跳过的系列要能被日志定位")
|
||||||
|
|
||||||
|
-- 空回包不炸:仍给出完整的替换指令(全量重拉窗口照旧清)
|
||||||
|
local empty = Stats.fromHistory(nil, { source_id = "kavita", fetched_at = 4000 })
|
||||||
|
Assert.len(empty.rows, 0)
|
||||||
|
Assert.len(empty.identities, 0)
|
||||||
|
Assert.len(empty.replace.books, 0)
|
||||||
|
Assert.eq(#empty.replace.ranges, 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- seen 的重复 / 空串不进 books;并集按 stable_id 精确去重(4 / 42 互为前缀,不能用 LIKE)
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 9, localDate = "2026-10-04T00:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 5, pagesRead = 0 } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = 5000, volumes = { [9] = 2 },
|
||||||
|
seen = { "9:1", "", "9:1", "stale" } })
|
||||||
|
Assert.eq(#result.replace.books, 2)
|
||||||
|
Assert.contains(result.replace.books, "9:1")
|
||||||
|
Assert.contains(result.replace.books, "stale")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 时区映射全表:设备时钟的 19 项 POSIX 串 → IANA(Kavita 的 TimeZoneId)
|
||||||
|
local expected = {
|
||||||
|
["HST10"] = "Pacific/Honolulu",
|
||||||
|
["AKST9AKDT,M3.2.0,M11.1.0"] = "America/Anchorage",
|
||||||
|
["PST8PDT,M3.2.0,M11.1.0"] = "America/Los_Angeles",
|
||||||
|
["MST7MDT,M3.2.0,M11.1.0"] = "America/Denver",
|
||||||
|
["CST6CDT,M3.2.0,M11.1.0"] = "America/Chicago",
|
||||||
|
["EST5EDT,M3.2.0,M11.1.0"] = "America/New_York",
|
||||||
|
["<-03>3"] = "America/Sao_Paulo",
|
||||||
|
["UTC0"] = "UTC",
|
||||||
|
["GMT0BST,M3.5.0/1,M10.5.0"] = "Europe/London",
|
||||||
|
["CET-1CEST,M3.5.0,M10.5.0/3"] = "Europe/Berlin",
|
||||||
|
["EET-2EEST,M3.5.0/3,M10.5.0/4"] = "Europe/Athens",
|
||||||
|
["MSK-3"] = "Europe/Moscow",
|
||||||
|
["<+04>-4"] = "Asia/Dubai",
|
||||||
|
["IST-5:30"] = "Asia/Kolkata",
|
||||||
|
["<+07>-7"] = "Asia/Bangkok",
|
||||||
|
["CST-8"] = "Asia/Shanghai",
|
||||||
|
["JST-9"] = "Asia/Tokyo",
|
||||||
|
["AEST-10AEDT,M10.1.0,M4.1.0/3"] = "Australia/Sydney",
|
||||||
|
["NZST-12NZDT,M9.5.0,M4.1.0/3"] = "Pacific/Auckland",
|
||||||
|
}
|
||||||
|
local n = 0
|
||||||
|
for posix, iana in pairs(expected) do
|
||||||
|
n = n + 1
|
||||||
|
Assert.eq(Stats.ianaTimezone(posix), iana, posix)
|
||||||
|
end
|
||||||
|
Assert.eq(n, 19)
|
||||||
|
|
||||||
|
-- 与设置页的时区表保持同步(读源码不 require UI 依赖):时钟加项时必须同步映射
|
||||||
|
local file = assert(io.open(Config.root() .. "/book.koplugin/features/clock/init.lua", "r"))
|
||||||
|
local source = file:read("*a")
|
||||||
|
file:close()
|
||||||
|
local in_block, covered = false, 0
|
||||||
|
for line in source:gmatch("[^\n]+") do
|
||||||
|
if line:match("Clock%.TIMEZONES%s*=") then
|
||||||
|
in_block = true
|
||||||
|
elseif in_block then
|
||||||
|
if line:match("^}") then break end
|
||||||
|
local posix = line:match('tz%s*=%s*"([^"]*)"')
|
||||||
|
if posix and posix ~= "" then
|
||||||
|
covered = covered + 1
|
||||||
|
Assert.not_nil(expected[posix], "时钟时区缺少 IANA 映射:" .. posix)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Assert.eq(covered, 19, "时钟时区表全部覆盖")
|
||||||
|
|
||||||
|
-- 未知 / 空串(跟随系统)回退 UTC 并 warn,不做地区默认
|
||||||
|
local before = #warnings
|
||||||
|
Assert.eq(Stats.ianaTimezone(""), "UTC")
|
||||||
|
Assert.eq(Stats.ianaTimezone("NOPE-1"), "UTC")
|
||||||
|
Assert.eq(Stats.ianaTimezone(nil), "UTC")
|
||||||
|
Assert.eq(#warnings, before + 3, "每次回退都记一条日志")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 阅读会话行:每个「会话 × 章」切片的真实起始时刻 / 时长 / 页数,供详情「阅读记录」列出时段。
|
||||||
|
-- 它只进列表,不参与日 / 时段 / 总量汇总。
|
||||||
|
local day = dayTs(2026, 10, 10)
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 66, startTimeUtc = "2026-10-10T09:00:00.0000000", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 600, pagesRead = 12,
|
||||||
|
startTimeUtc = "2026-10-10T09:00:00.0000000" },
|
||||||
|
{ chapterId = 2, durationSeconds = 300, pagesRead = 3,
|
||||||
|
startTimeUtc = "2026-10-10T09:20:00.0000000" },
|
||||||
|
} },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [66] = 1 } })
|
||||||
|
|
||||||
|
local first = find(result.rows, "cloud_session", "66", hourTs(2026, 10, 10, 17))
|
||||||
|
Assert.not_nil(first, "会话行按章切片的本地起始时刻落行")
|
||||||
|
Assert.eq(first.duration, 600)
|
||||||
|
Assert.eq(first.event_count, 12, "页数记在 event_count")
|
||||||
|
Assert.eq(first.last_time, 2000, "会话行 last_time = 拉取时刻")
|
||||||
|
local second = find(result.rows, "cloud_session", "66", hourTs(2026, 10, 10, 17) + 20 * 60)
|
||||||
|
Assert.not_nil(second)
|
||||||
|
Assert.eq(second.duration, 300)
|
||||||
|
Assert.eq(second.event_count, 3)
|
||||||
|
|
||||||
|
-- 会话行不影响任何汇总桶:日桶 / 总量仍是 900,且不会多出 hour 之外的重复
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. day, day).duration, 900)
|
||||||
|
Assert.eq(find(result.rows, "total", "__kv:total", 0).duration, 900)
|
||||||
|
Assert.eq(find(result.rows, "book_day", "66", day).duration, 900)
|
||||||
|
|
||||||
|
-- 零时长会话不落会话行
|
||||||
|
local zero = Stats.fromHistory({
|
||||||
|
{ seriesId = 66, startTimeUtc = "2026-10-10T10:00:00.0000000", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 0, pagesRead = 0,
|
||||||
|
startTimeUtc = "2026-10-10T10:00:00.0000000" },
|
||||||
|
} },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [66] = 1 } })
|
||||||
|
Assert.is_nil(find(zero.rows, "cloud_session", "66"), "打开没读的会话不落行")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 漫画(seriesFormat 0 Image / 1 Archive)的会话行补真实页坐标:page = endPage(读到哪)、
|
||||||
|
-- total_pages = chapter.totalPages(卷级,汇总处继续 MAX);event_count 是**本次新推进的页数**
|
||||||
|
-- (不是 pagesRead —— 重读会重复计入,见下方进度用例)。pagesRead = 0 是合法值,不是缺数据。
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 70, seriesFormat = 0, startTimeUtc = "2026-10-10T09:00:00.0000000", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 300, pagesRead = 12, startPage = 3, endPage = 15,
|
||||||
|
totalPages = 194, startTimeUtc = "2026-10-10T09:00:00.0000000" },
|
||||||
|
} },
|
||||||
|
-- Archive 同样算漫画;同一系列两卷各自的卷级总页数不同,不能被条目级 totalPages 抹平。
|
||||||
|
{ seriesId = 71, seriesFormat = 1, startTimeUtc = "2026-10-10T10:00:00.0000000", chapters = {
|
||||||
|
{ chapterId = 2, durationSeconds = 60, pagesRead = 0, startPage = 1, endPage = 1,
|
||||||
|
totalPages = 40, startTimeUtc = "2026-10-10T10:00:00.0000000" },
|
||||||
|
{ chapterId = 3, durationSeconds = 90, pagesRead = 7, startPage = 20, endPage = 30,
|
||||||
|
totalPages = 52, startTimeUtc = "2026-10-10T10:30:00.0000000" },
|
||||||
|
} },
|
||||||
|
-- epub 的 Chapter.Pages 是 spine 数、与渲染页无关:页坐标保持 0,不因带 endPage 就填。
|
||||||
|
{ seriesId = 72, seriesFormat = 3, startTimeUtc = "2026-10-10T11:00:00.0000000", chapters = {
|
||||||
|
{ chapterId = 4, durationSeconds = 600, pagesRead = 7, startPage = 15, endPage = 15,
|
||||||
|
totalPages = 22, startTimeUtc = "2026-10-10T11:00:00.0000000" },
|
||||||
|
} },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [70] = 1, [71] = 1, [72] = 1 } })
|
||||||
|
|
||||||
|
local image = find(result.rows, "cloud_session", "70", hourTs(2026, 10, 10, 17))
|
||||||
|
Assert.not_nil(image, "Image 漫画的会话行")
|
||||||
|
Assert.eq(image.page, 15, "page = chapter.endPage")
|
||||||
|
Assert.eq(image.total_pages, 194, "total_pages = chapter.totalPages")
|
||||||
|
Assert.eq(image.event_count, 15, "event_count = 本次新推进的页数(0 → 15)")
|
||||||
|
|
||||||
|
local archive_zero = find(result.rows, "cloud_session", "71", hourTs(2026, 10, 10, 18))
|
||||||
|
Assert.not_nil(archive_zero, "Archive 漫画的会话行")
|
||||||
|
Assert.eq(archive_zero.page, 1, "page = endPage(未翻页也合法)")
|
||||||
|
Assert.eq(archive_zero.total_pages, 40, "卷级总页数")
|
||||||
|
Assert.eq(archive_zero.event_count, 1, "推进到第 1 页即 1 页,与 pagesRead = 0 无关")
|
||||||
|
local archive_more = find(result.rows, "cloud_session", "71", hourTs(2026, 10, 10, 18) + 30 * 60)
|
||||||
|
Assert.not_nil(archive_more, "同一条目里的第二卷")
|
||||||
|
Assert.eq(archive_more.page, 30)
|
||||||
|
Assert.eq(archive_more.total_pages, 52, "逐章取自己的卷级总页数")
|
||||||
|
Assert.eq(archive_more.event_count, 29, "1 → 30 只推进 29 页(不是 pagesRead 7)")
|
||||||
|
|
||||||
|
local epub = find(result.rows, "cloud_session", "72", hourTs(2026, 10, 10, 19))
|
||||||
|
Assert.not_nil(epub, "epub 的会话行照旧落")
|
||||||
|
Assert.eq(epub.page, 0, "epub 不填 page")
|
||||||
|
Assert.eq(epub.total_pages, 0, "epub 不填 total_pages")
|
||||||
|
Assert.eq(epub.event_count, 7, "epub 仍用 pagesRead")
|
||||||
|
|
||||||
|
-- 页坐标只加在会话行上:日 / 单书桶维持「云端快照没有页坐标」的语义(汇总另算)。
|
||||||
|
local day = dayTs(2026, 10, 10)
|
||||||
|
for _idx, row in ipairs(result.rows) do
|
||||||
|
if row.record_type ~= "cloud_session" then
|
||||||
|
Assert.eq(row.page, 0, row.record_type .. " 行 page 仍为 0")
|
||||||
|
Assert.eq(row.total_pages, 0, row.record_type .. " 行 total_pages 仍为 0")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- 当天页数 = 15(70)+ 1(71 卷 2)+ 29(71 卷 3)+ 7(epub 仍是 pagesRead)
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. day, day).event_count, 52)
|
||||||
|
Assert.eq(find(result.rows, "book_day", "70", day).duration, 300)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 漫画的已读页数按「最远进度」算,不按页次累加:pagesRead 是「这次翻了多少页」,
|
||||||
|
-- 重读会重复计入(实测 194 页的卷 6 条会话 pagesRead 合计 284,已读页数超过了总页数)。
|
||||||
|
-- 样本:大剑 Vol.10,总 194 页;依次读到 3 → 91 → 42(重读)→ 94 → 126 → 194。
|
||||||
|
local sessions = {
|
||||||
|
{ end_page = 3, pages_read = 3 },
|
||||||
|
{ end_page = 91, pages_read = 87 },
|
||||||
|
{ end_page = 42, pages_read = 42 },
|
||||||
|
{ end_page = 94, pages_read = 48 },
|
||||||
|
{ end_page = 126, pages_read = 34 },
|
||||||
|
{ end_page = 194, pages_read = 70 },
|
||||||
|
}
|
||||||
|
local expected = { 3, 88, 0, 3, 32, 68 } -- 每次都只是「比此前更远」的那一段;合计 194
|
||||||
|
|
||||||
|
local function history()
|
||||||
|
local entries = {}
|
||||||
|
for i, s in ipairs(sessions) do
|
||||||
|
-- UTC 01..06 点 → 本地(CST-8)09..14 点,同一本地的天。
|
||||||
|
local utc = string.format("2026-10-10T%02d:00:00", i)
|
||||||
|
entries[#entries + 1] = { seriesId = 100, seriesFormat = 0, startTimeUtc = utc, chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = s.pages_read, startPage = 0,
|
||||||
|
endPage = s.end_page, totalPages = 194, startTimeUtc = utc } } }
|
||||||
|
end
|
||||||
|
return entries
|
||||||
|
end
|
||||||
|
|
||||||
|
local day = dayTs(2026, 10, 10)
|
||||||
|
local function check(entries, label)
|
||||||
|
local result = Stats.fromHistory(entries,
|
||||||
|
{ source_id = "kavita", fetched_at = 2000, volumes = { [100] = 1 } })
|
||||||
|
local sum = 0
|
||||||
|
local session_rows = 0
|
||||||
|
for _idx, row in ipairs(result.rows) do
|
||||||
|
if row.record_type == "cloud_session" and row.stable_id == "100" then
|
||||||
|
session_rows = session_rows + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Assert.eq(session_rows, #sessions, label .. ":每条有时长的会话各落一行,不多不少")
|
||||||
|
for i, want in ipairs(expected) do
|
||||||
|
local row = find(result.rows, "cloud_session", "100", hourTs(2026, 10, 10, 8 + i))
|
||||||
|
Assert.not_nil(row, label .. ":第 " .. i .. " 条会话行")
|
||||||
|
Assert.eq(row.event_count, want, label .. ":第 " .. i .. " 条只算新推进的页数")
|
||||||
|
-- 重读(第 3 条 endPage 42 < 已到达 91)页数为 0,但 page 仍如实记 42。
|
||||||
|
Assert.eq(row.page, sessions[i].end_page, label .. ":第 " .. i .. " 条 page 仍记 endPage")
|
||||||
|
Assert.eq(row.total_pages, 194, label .. ":第 " .. i .. " 条卷级总页数")
|
||||||
|
sum = sum + row.event_count
|
||||||
|
end
|
||||||
|
Assert.eq(sum, 194, label .. ":合计 = 读到的最远页码 = 总页数")
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. day, day).event_count, 194,
|
||||||
|
label .. ":当天页数也是进度而不是页次")
|
||||||
|
end
|
||||||
|
|
||||||
|
check(history(), "正序")
|
||||||
|
-- 回包可能是新→旧:按章起始时刻排序,结果不受遍历顺序影响。
|
||||||
|
local reversed = {}
|
||||||
|
local forward = history()
|
||||||
|
for i = #forward, 1, -1 do reversed[#reversed + 1] = forward[i] end
|
||||||
|
check(reversed, "倒序")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- durationSeconds = 0 但有推进的章行照样发行:Kavita 的会话是「两次进度写入之间」,
|
||||||
|
-- 只写一次就是 0 秒,可推进的页数是真的(详情页「已读页数 / 上次阅读」靠它)。
|
||||||
|
-- 它同时要参与进度序列与当天页数,否则这段跳读会从当天页面消失、
|
||||||
|
-- 而后续会话又因为 reached 更高而少算,合计就对不上读到的最远页码。
|
||||||
|
local d = dayTs(2026, 10, 11)
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 101, seriesFormat = 0, startTimeUtc = "2026-10-11T02:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 0, pagesRead = 20, startPage = 5, endPage = 60,
|
||||||
|
totalPages = 100, startTimeUtc = "2026-10-11T02:00:00" } } },
|
||||||
|
{ seriesId = 101, seriesFormat = 0, startTimeUtc = "2026-10-11T03:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 120, pagesRead = 5, startPage = 60, endPage = 70,
|
||||||
|
totalPages = 100, startTimeUtc = "2026-10-11T03:00:00" } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [101] = 1 } })
|
||||||
|
|
||||||
|
local jump = find(result.rows, "cloud_session", "101", hourTs(2026, 10, 11, 10))
|
||||||
|
Assert.not_nil(jump, "零时长但有推进的章行也发行(页数是真推进)")
|
||||||
|
Assert.eq(jump.duration, 0)
|
||||||
|
Assert.eq(jump.event_count, 60)
|
||||||
|
local read = find(result.rows, "cloud_session", "101", hourTs(2026, 10, 11, 11))
|
||||||
|
Assert.not_nil(read)
|
||||||
|
Assert.eq(read.event_count, 10, "跳读已把进度推到 60,本次只推进 10 页")
|
||||||
|
Assert.eq(read.page, 70)
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d, d).event_count, 70,
|
||||||
|
"当天页数 = 最远页码(含零时长跳读推进的 60)")
|
||||||
|
|
||||||
|
-- 登记身份用于清孤儿行:零时长条目照旧算见过(它上次可能留下过行)。
|
||||||
|
Assert.contains(result.identities, "101")
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- endPage 超过总页数(不同版本页数不一致)时钳到总页数:已读页数不可能超过总页数。
|
||||||
|
local d = dayTs(2026, 10, 12)
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 102, seriesFormat = 1, startTimeUtc = "2026-10-12T02:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = 40, startPage = 0, endPage = 250,
|
||||||
|
totalPages = 194, startTimeUtc = "2026-10-12T02:00:00" } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [102] = 1 } })
|
||||||
|
local row = find(result.rows, "cloud_session", "102", hourTs(2026, 10, 12, 10))
|
||||||
|
Assert.not_nil(row)
|
||||||
|
Assert.eq(row.event_count, 194, "推进钳到总页数")
|
||||||
|
Assert.eq(row.total_pages, 194)
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d, d).event_count, 194, "当天页数也被钳")
|
||||||
|
|
||||||
|
-- 拿不到总页数(totalPages = 0 / 缺字段)时不假设上界:按 endPage 原样算。
|
||||||
|
local unknown = Stats.fromHistory({
|
||||||
|
{ seriesId = 103, seriesFormat = 0, startTimeUtc = "2026-10-12T05:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = 9, endPage = 77,
|
||||||
|
startTimeUtc = "2026-10-12T05:00:00" } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [103] = 1 } })
|
||||||
|
local no_total = find(unknown.rows, "cloud_session", "103", hourTs(2026, 10, 12, 13))
|
||||||
|
Assert.not_nil(no_total)
|
||||||
|
Assert.eq(no_total.event_count, 77, "缺总页数就照 endPage 算")
|
||||||
|
Assert.eq(no_total.total_pages, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- 多卷:每卷(stable_id = seriesId:chapterId)各自从 0 起算进度,互不影响;
|
||||||
|
-- 合计 = 各卷进度之和(≤ 各卷总页数之和)。
|
||||||
|
local d = dayTs(2026, 10, 13)
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 80, seriesFormat = 0, startTimeUtc = "2026-10-13T02:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = 10, endPage = 10, totalPages = 40,
|
||||||
|
startTimeUtc = "2026-10-13T02:00:00" } } },
|
||||||
|
{ seriesId = 80, seriesFormat = 0, startTimeUtc = "2026-10-13T03:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = 20, endPage = 30, totalPages = 40,
|
||||||
|
startTimeUtc = "2026-10-13T03:00:00" } } },
|
||||||
|
{ seriesId = 80, seriesFormat = 0, startTimeUtc = "2026-10-13T04:00:00", chapters = {
|
||||||
|
{ chapterId = 2, durationSeconds = 60, pagesRead = 5, endPage = 5, totalPages = 60,
|
||||||
|
startTimeUtc = "2026-10-13T04:00:00" } } },
|
||||||
|
{ seriesId = 80, seriesFormat = 0, startTimeUtc = "2026-10-13T05:00:00", chapters = {
|
||||||
|
{ chapterId = 2, durationSeconds = 60, pagesRead = 45, endPage = 50, totalPages = 60,
|
||||||
|
startTimeUtc = "2026-10-13T05:00:00" } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [80] = 2 } })
|
||||||
|
|
||||||
|
Assert.eq(find(result.rows, "cloud_session", "80:1", hourTs(2026, 10, 13, 10)).event_count, 10)
|
||||||
|
Assert.eq(find(result.rows, "cloud_session", "80:1", hourTs(2026, 10, 13, 11)).event_count, 20)
|
||||||
|
Assert.eq(find(result.rows, "cloud_session", "80:2", hourTs(2026, 10, 13, 12)).event_count, 5)
|
||||||
|
Assert.eq(find(result.rows, "cloud_session", "80:2", hourTs(2026, 10, 13, 13)).event_count, 45)
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d, d).event_count, 80, "10 + 20 + 5 + 45")
|
||||||
|
Assert.eq(find(result.rows, "cloud_session", "80:1", hourTs(2026, 10, 13, 10)).total_pages, 40)
|
||||||
|
Assert.eq(find(result.rows, "cloud_session", "80:2", hourTs(2026, 10, 13, 13)).total_pages, 60)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
-- epub / PDF 不受进度口径影响:pagesRead 照旧累加(重读同一页也算,这是「翻页数」语义),
|
||||||
|
-- 页坐标仍为 0。
|
||||||
|
local d = dayTs(2026, 10, 14)
|
||||||
|
local result = Stats.fromHistory({
|
||||||
|
{ seriesId = 202, seriesFormat = 3, startTimeUtc = "2026-10-14T02:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = 7, startPage = 15, endPage = 15,
|
||||||
|
totalPages = 22, startTimeUtc = "2026-10-14T02:00:00" } } },
|
||||||
|
{ seriesId = 202, seriesFormat = 3, startTimeUtc = "2026-10-14T03:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = 7, startPage = 15, endPage = 15,
|
||||||
|
totalPages = 22, startTimeUtc = "2026-10-14T03:00:00" } } },
|
||||||
|
-- PDF(4)同样不是渲染页,口径与 epub 一致。
|
||||||
|
{ seriesId = 203, seriesFormat = 4, startTimeUtc = "2026-10-14T04:00:00", chapters = {
|
||||||
|
{ chapterId = 1, durationSeconds = 60, pagesRead = 4, endPage = 99,
|
||||||
|
totalPages = 120, startTimeUtc = "2026-10-14T04:00:00" } } },
|
||||||
|
}, { source_id = "kavita", fetched_at = 2000, volumes = { [202] = 1, [203] = 1 } })
|
||||||
|
|
||||||
|
local first = find(result.rows, "cloud_session", "202", hourTs(2026, 10, 14, 10))
|
||||||
|
local again = find(result.rows, "cloud_session", "202", hourTs(2026, 10, 14, 11))
|
||||||
|
Assert.eq(first.event_count, 7, "epub 仍是 pagesRead")
|
||||||
|
Assert.eq(again.event_count, 7, "epub 重读不折成 0(不是进度口径)")
|
||||||
|
Assert.eq(first.page, 0)
|
||||||
|
Assert.eq(first.total_pages, 0)
|
||||||
|
local pdf = find(result.rows, "cloud_session", "203", hourTs(2026, 10, 14, 12))
|
||||||
|
Assert.eq(pdf.event_count, 4, "PDF 仍是 pagesRead")
|
||||||
|
Assert.eq(pdf.page, 0)
|
||||||
|
Assert.eq(pdf.total_pages, 0)
|
||||||
|
Assert.eq(find(result.rows, "day", "__kv:day:" .. d, d).event_count, 18, "7 + 7 + 4")
|
||||||
|
end
|
||||||
@@ -0,0 +1,282 @@
|
|||||||
|
--[[--
|
||||||
|
端到端:卷列表里「缓存整部」→ 真实缓存适配层 → 真实后台任务队列 → 顶栏读到的任务 → 收尾提示。
|
||||||
|
|
||||||
|
用假的 kamare 模块(真缓存适配层 + 真队列 + 真卷列表 + 真轮询),只把「下载」外包出去,
|
||||||
|
其余全走产品代码:这是跨仓 E2E 在离线环境里能做到的最大范围(模拟器 / 真机另做手工冒烟)。
|
||||||
|
|
||||||
|
@module tests.moonsource_kavita.tasks_e2e_spec
|
||||||
|
--]]
|
||||||
|
---@diagnostic disable: undefined-field, missing-fields, inject-field, redundant-parameter
|
||||||
|
|
||||||
|
local Assert = require("support.assert")
|
||||||
|
local Config = require("support.config")
|
||||||
|
local Kit = require("support.widget_stubs")
|
||||||
|
Kit.install("paper")
|
||||||
|
local Themed = require("support.theme_stubs")
|
||||||
|
Themed.install()
|
||||||
|
-- 真实的卷列表与二级菜单:Themed 的 list 桩会把 item.widget 丢掉,也就点不了行。
|
||||||
|
package.preload["ui.themes.widgets.list"] = nil
|
||||||
|
package.loaded["ui.themes.widgets.list"] = nil
|
||||||
|
|
||||||
|
local PLUGIN = (debug.getinfo(1, "S").source:match("^@(.-)/tests/") .. "/moonsource-kavita.koplugin/moonsource_kavita")
|
||||||
|
|
||||||
|
-- 源配置:真 cache.lua 只读 base_url / api_key;其余键仍走 Kit 的主题设置桩。
|
||||||
|
local cfg = { base_url = "http://kavita.local", api_key = "key" }
|
||||||
|
package.preload["utils.settings"] = function()
|
||||||
|
return {
|
||||||
|
get = function(owner)
|
||||||
|
local name = owner:match("[^.]+$")
|
||||||
|
if name == "ui" then return Kit.display end
|
||||||
|
return Kit.sections[name]
|
||||||
|
end,
|
||||||
|
getSource = function() return cfg end,
|
||||||
|
saveSource = function() end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["utils.log"] = function()
|
||||||
|
return { info = function() end, warn = function() end, err = function() end, dbg = function() end }
|
||||||
|
end
|
||||||
|
package.preload["ui/network/manager"] = function()
|
||||||
|
return { isConnected = function() return true end }
|
||||||
|
end
|
||||||
|
package.preload["ui.guard"] = function()
|
||||||
|
return {
|
||||||
|
call = function(_label, fn, ...) return fn(...) end,
|
||||||
|
wrap = function(_label, fn) return fn end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 假 kamare:队列与章状态都在内存里,由用例推进。
|
||||||
|
local statuses, queue = {}, {}
|
||||||
|
--- 重置假 kamare 的队列与章状态。
|
||||||
|
local function resetKamare()
|
||||||
|
statuses, queue = {}, {}
|
||||||
|
queue = { state = "idle", entries = {} }
|
||||||
|
end
|
||||||
|
local kamare = {
|
||||||
|
api_version = 1,
|
||||||
|
capabilities = {
|
||||||
|
status = true, resume_page = true, queue = true, queue_control = true,
|
||||||
|
index = true, enqueue = true, delete = true, estimate = true, server = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
function kamare.register_server() return "server-key" end
|
||||||
|
function kamare.status(_base_url, chapter_id) return statuses[tostring(chapter_id)] end
|
||||||
|
function kamare.queue_state() return queue end
|
||||||
|
function kamare.estimate(_base_url, entries)
|
||||||
|
return { ok = true, chapters = #entries, bytes = #entries * 1024 * 1024,
|
||||||
|
available = 4096 * 1024 * 1024 }
|
||||||
|
end
|
||||||
|
function kamare.enqueue(_base_url, entries)
|
||||||
|
for _idx, entry in ipairs(entries) do
|
||||||
|
queue.entries[tostring(entry.chapterId)] = { chapterId = entry.chapterId, state = "queued" }
|
||||||
|
end
|
||||||
|
queue.state = "downloading"
|
||||||
|
return true, nil, { chapters = #entries }
|
||||||
|
end
|
||||||
|
package.loaded["kamarecache"] = kamare
|
||||||
|
|
||||||
|
--- kamare 开始下某一卷。
|
||||||
|
local function startChapter(id)
|
||||||
|
queue.entries[tostring(id)] = { chapterId = id, state = "downloading" }
|
||||||
|
queue.current_chapter_id = id
|
||||||
|
queue.state = "downloading"
|
||||||
|
end
|
||||||
|
|
||||||
|
--- kamare 下完某一卷:章状态变 complete,队列项消失。
|
||||||
|
local function finishChapter(id)
|
||||||
|
statuses[tostring(id)] = { state = "complete", bytes = 1024 * 1024 }
|
||||||
|
queue.entries[tostring(id)] = nil
|
||||||
|
queue.current_chapter_id = nil
|
||||||
|
if next(queue.entries) == nil then queue.state = "idle" end
|
||||||
|
end
|
||||||
|
|
||||||
|
package.preload["moonsource_kavita.cache"] = function()
|
||||||
|
return dofile(PLUGIN .. "/cache.lua")
|
||||||
|
end
|
||||||
|
package.preload["moonsource_kavita.cache_task"] = function()
|
||||||
|
return dofile(PLUGIN .. "/cache_task.lua")
|
||||||
|
end
|
||||||
|
package.preload["moonsource_kavita.volume_list"] = function()
|
||||||
|
return dofile(PLUGIN .. "/volume_list.lua")
|
||||||
|
end
|
||||||
|
|
||||||
|
local Cache = require("moonsource_kavita.cache")
|
||||||
|
local Tasks = require("workers.tasks")
|
||||||
|
local VolumeList = require("moonsource_kavita.volume_list")
|
||||||
|
|
||||||
|
local series = { stable_id = "900", title = "测试系列" }
|
||||||
|
local function entry(id, title, pages_read)
|
||||||
|
return { chapterId = id, volumeId = id, seriesId = 900, libraryId = 1, format = 1,
|
||||||
|
title = title, pages = 100, pagesRead = pages_read or 0 }
|
||||||
|
end
|
||||||
|
local toc = { entry(601, "第 1 卷", 100), entry(602, "第 2 卷", 40), entry(603, "第 3 卷", 0) }
|
||||||
|
|
||||||
|
--- Kit 的 unschedule 只记录、不从已排列表里删;真实 UIManager 会删,这里按记录过滤。
|
||||||
|
---@param item table
|
||||||
|
---@return boolean
|
||||||
|
local function alive(item)
|
||||||
|
for _idx, fn in ipairs(Kit.unscheduled) do
|
||||||
|
if fn == item.fn then return false end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 结清队列的变更拍(pause_auto_suspend)。
|
||||||
|
local function changes()
|
||||||
|
while true do
|
||||||
|
local fired = false
|
||||||
|
for index, item in ipairs(Kit.scheduled) do
|
||||||
|
if item.delay < 1 and alive(item) then
|
||||||
|
table.remove(Kit.scheduled, index)
|
||||||
|
item.fn()
|
||||||
|
fired = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not fired then return end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 跑一拍所有 1 秒以上的定时器(页面轮询 + 后台任务轮询各一拍)。
|
||||||
|
local function round()
|
||||||
|
local now, rest = {}, {}
|
||||||
|
for _idx, item in ipairs(Kit.scheduled) do
|
||||||
|
if item.delay >= 1 and alive(item) then now[#now + 1] = item else rest[#rest + 1] = item end
|
||||||
|
end
|
||||||
|
Kit.scheduled = rest
|
||||||
|
for _idx, item in ipairs(now) do item.fn() end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 顶栏「后台任务」的读数(与 desktop/topbar 同一口径:running / 未结束总数)。
|
||||||
|
local function topbarText()
|
||||||
|
local list = Tasks.tasks()
|
||||||
|
if #list == 0 then return "空闲" end
|
||||||
|
local running = 0
|
||||||
|
for _idx, task in ipairs(list) do
|
||||||
|
if task.state == "running" then running = running + 1 end
|
||||||
|
end
|
||||||
|
return running .. "/" .. #list
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param list table
|
||||||
|
---@param widget table
|
||||||
|
local function tap(list, widget)
|
||||||
|
local size = widget.dimen
|
||||||
|
local ges = Kit.tap(size.x + math.floor(size.w / 2), size.y + math.floor(size.h / 2))
|
||||||
|
ges.ges = "tap"
|
||||||
|
list:handleEvent(require("ui/event"):new("Gesture", ges))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- 打开卷列表并走「缓存整部」(菜单第一项)。第 1 卷已缓存,本批只下 2 卷。
|
||||||
|
local function openAndCacheAll()
|
||||||
|
statuses["601"] = { state = "complete", bytes = 1024 }
|
||||||
|
local list = assert(VolumeList.pick(series, toc, function() end))
|
||||||
|
list:show()
|
||||||
|
list:paintTo(Kit.canvas(), 0, 0)
|
||||||
|
list.left_callback()
|
||||||
|
local menu = Kit.shown[#Kit.shown]
|
||||||
|
menu:paintTo(Kit.canvas(), 0, 0)
|
||||||
|
local rows = Kit.taps(menu)
|
||||||
|
Assert.is_true(#rows >= 1, "有「缓存整部」")
|
||||||
|
tap(menu, rows[1])
|
||||||
|
local confirm = Themed.last("confirm")
|
||||||
|
Assert.not_nil(confirm, "确认框")
|
||||||
|
confirm.ok_callback()
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
|
||||||
|
local function cleanup()
|
||||||
|
for _idx, item in ipairs(Tasks.tasks()) do
|
||||||
|
local live = Tasks.get(item.key)
|
||||||
|
if live then live.cancel() end
|
||||||
|
end
|
||||||
|
changes()
|
||||||
|
Kit.scheduled, Kit.unscheduled = {}, {}
|
||||||
|
Themed.made = {}
|
||||||
|
Cache.reset()
|
||||||
|
resetKamare()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 页面开着:入队 → 顶栏看得到 → 进度跟着 kamare 走 → 页面自己的进度框收尾(只提示一次)。
|
||||||
|
do
|
||||||
|
cleanup()
|
||||||
|
local list = openAndCacheAll()
|
||||||
|
|
||||||
|
local tracked = Tasks.tasks()
|
||||||
|
Assert.len(tracked, 1, "缓存进了后台任务队列")
|
||||||
|
Assert.eq(tracked[1].kind, "cache")
|
||||||
|
Assert.eq(tracked[1].title, "测试系列")
|
||||||
|
Assert.eq(topbarText(), "1/1", "顶栏读到「1/1」")
|
||||||
|
changes()
|
||||||
|
Assert.is_true(require("pluginshare").pause_auto_suspend, "缓存期间不自动休眠")
|
||||||
|
|
||||||
|
startChapter(602)
|
||||||
|
round()
|
||||||
|
Assert.eq(Tasks.tasks()[1].text, "第 2 卷", "任务说明行跟 kamare 的当前卷")
|
||||||
|
Assert.eq(Tasks.tasks()[1].total, 2, "只数本批(601 已缓存)")
|
||||||
|
|
||||||
|
finishChapter(602)
|
||||||
|
startChapter(603)
|
||||||
|
round()
|
||||||
|
Assert.eq(Tasks.tasks()[1].count, 1, "下完一卷进度 +1")
|
||||||
|
|
||||||
|
finishChapter(603)
|
||||||
|
round()
|
||||||
|
Assert.len(Tasks.tasks(), 0, "全部落地后离开队列")
|
||||||
|
Assert.eq(topbarText(), "空闲")
|
||||||
|
changes()
|
||||||
|
Assert.is_false(require("pluginshare").pause_auto_suspend, "结束放行自动休眠")
|
||||||
|
local toasts = Themed.all("toast")
|
||||||
|
Assert.eq(#toasts, 1, "页面进度框收尾,只提示一次")
|
||||||
|
Assert.eq(toasts[1].text, "已缓存 2 卷")
|
||||||
|
list:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 页面提前关掉:后台任务继续跑,完成时由任务提示(不再有页面轮询)。
|
||||||
|
do
|
||||||
|
cleanup()
|
||||||
|
local list = openAndCacheAll()
|
||||||
|
startChapter(602)
|
||||||
|
round()
|
||||||
|
list:close()
|
||||||
|
Assert.is_true(#Kit.unscheduled > 0, "关页撤掉页面轮询")
|
||||||
|
|
||||||
|
finishChapter(602)
|
||||||
|
startChapter(603)
|
||||||
|
round()
|
||||||
|
Assert.eq(Tasks.tasks()[1].count, 1, "关页后任务仍在推进")
|
||||||
|
|
||||||
|
finishChapter(603)
|
||||||
|
round()
|
||||||
|
Assert.len(Tasks.tasks(), 0)
|
||||||
|
local toasts = Themed.all("toast")
|
||||||
|
Assert.eq(#toasts, 1, "关页后由任务报完成")
|
||||||
|
Assert.eq(toasts[1].text, "已缓存 2 卷")
|
||||||
|
Assert.eq(topbarText(), "空闲")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 队列因空间不足暂停:任务留在列表里、报暂停原因、不再压制自动休眠;恢复后继续。
|
||||||
|
do
|
||||||
|
cleanup()
|
||||||
|
local list = openAndCacheAll()
|
||||||
|
startChapter(602)
|
||||||
|
round()
|
||||||
|
queue.state = "paused"
|
||||||
|
queue.pause_reason = "low_space"
|
||||||
|
round()
|
||||||
|
Assert.eq(Tasks.tasks()[1].text, "空间不足,已暂停")
|
||||||
|
changes()
|
||||||
|
Assert.is_false(require("pluginshare").pause_auto_suspend, "暂停时允许自动休眠")
|
||||||
|
|
||||||
|
queue.state = "downloading"
|
||||||
|
queue.pause_reason = nil
|
||||||
|
round()
|
||||||
|
changes()
|
||||||
|
Assert.is_true(require("pluginshare").pause_auto_suspend, "恢复后继续撑住")
|
||||||
|
finishChapter(602)
|
||||||
|
finishChapter(603)
|
||||||
|
round()
|
||||||
|
Assert.len(Tasks.tasks(), 0, "恢复后照常收尾")
|
||||||
|
list:close()
|
||||||
|
end
|
||||||
File diff suppressed because it is too large.
Load diff
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# 打包本仓库的书源插件:moonsource-<名字>.koplugin-<VERSION>.zip,同时生成 SHA256SUMS。
|
||||||
|
# 用法:tools/package.sh <VERSION> [OUT_DIR] (OUT_DIR 默认 dist/)
|
||||||
|
# 打包时把 <包名>/version.lua 里的版本占位符换成发布版本;剔除 *.md、.DS_Store、*~。
|
||||||
|
set -eu
|
||||||
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
VERSION="${1:?用法:tools/package.sh <VERSION> [OUT_DIR]}"
|
||||||
|
OUT="${2:-$ROOT/dist}"
|
||||||
|
case "$OUT" in /*) ;; *) OUT="$PWD/$OUT" ;; esac
|
||||||
|
|
||||||
|
NAME="$(cd "$ROOT" && ls -d moonsource-*.koplugin | head -n 1)"
|
||||||
|
[ -f "$ROOT/$NAME/main.lua" ] || { echo "找不到插件目录:$NAME" >&2; exit 1; }
|
||||||
|
PKG="$(echo "${NAME%.koplugin}" | tr - _)"
|
||||||
|
|
||||||
|
mkdir -p "$OUT"
|
||||||
|
STAGE="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$STAGE"' EXIT
|
||||||
|
rsync -a --exclude '*.md' --exclude '.DS_Store' --exclude '*~' "$ROOT/$NAME/" "$STAGE/$NAME/"
|
||||||
|
sed "s/@VERSION@/$VERSION/" "$ROOT/$NAME/$PKG/version.lua" > "$STAGE/$NAME/$PKG/version.lua"
|
||||||
|
ZIP="$OUT/$NAME-$VERSION.zip"
|
||||||
|
rm -f "$ZIP"
|
||||||
|
(cd "$STAGE" && zip -qr "$ZIP" "$NAME")
|
||||||
|
echo "Packaged $ZIP"
|
||||||
|
|
||||||
|
(cd "$OUT" && { command -v sha256sum >/dev/null && sha256sum ./*.zip || shasum -a 256 ./*.zip; } | sed 's# \./# #' > SHA256SUMS)
|
||||||
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# 发布本书源:校验更新日志 → 本地打包 → 打轻量标签 v<版本> → 推送当前分支和标签。
|
||||||
|
# Release 由 .github/workflows/release.yml 在标签推上去之后创建,日志取 CHANGELOG.md 里精确的「## <版本>」一节。
|
||||||
|
# 用法:tools/release.sh <VERSION>
|
||||||
|
set -eu
|
||||||
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
cd "$ROOT"
|
||||||
|
VERSION="${1:?用法:tools/release.sh <VERSION>}"
|
||||||
|
|
||||||
|
case "$VERSION" in
|
||||||
|
v*) echo "版本不要带 v:$VERSION" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
printf '%s\n' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([.+-].*)?$' \
|
||||||
|
|| { echo "版本应为 MAJOR.MINOR.PATCH:$VERSION" >&2; exit 1; }
|
||||||
|
|
||||||
|
grep -qx "## ${VERSION}" CHANGELOG.md \
|
||||||
|
|| { echo "CHANGELOG.md 缺少单独一行「## ${VERSION}」" >&2; exit 1; }
|
||||||
|
|
||||||
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
echo "工作区不干净,先提交再发布" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tools/package.sh "$VERSION" dist
|
||||||
|
|
||||||
|
TAG="v${VERSION}"
|
||||||
|
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
|
||||||
|
HAVE="$(git rev-parse "${TAG}^{}")"
|
||||||
|
HEAD="$(git rev-parse HEAD)"
|
||||||
|
if [ "$HAVE" != "$HEAD" ]; then
|
||||||
|
echo "标签 ${TAG} 已经指向别的提交" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
git tag "$TAG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
||||||
|
git push origin "$BRANCH"
|
||||||
|
git push origin "$TAG"
|
||||||
|
echo "已推送 ${TAG}。Actions 会打包并创建 Release。"
|
||||||
Executable
+16
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# 离线单元测试:借用月读仓库的测试运行器与桩,把本仓库的插件目录和 tests/ 加进 LUA_PATH。
|
||||||
|
# 用法:MOON_DIR=/path/to/moon tools/run-tests.sh [spec 文件…]
|
||||||
|
set -euo pipefail
|
||||||
|
here="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
: "${MOON_DIR:?请把 MOON_DIR 设为月读仓库路径}"
|
||||||
|
paths="$here/tests/?.lua;$here/tests/?/init.lua"
|
||||||
|
for plugin in "$here"/moonsource-*.koplugin; do
|
||||||
|
paths="$paths;$plugin/?.lua"
|
||||||
|
done
|
||||||
|
export LUA_PATH="$paths;;"
|
||||||
|
if [ "$#" -eq 0 ]; then
|
||||||
|
set -- $(find "$here/tests" -name '*_spec.lua' | sort)
|
||||||
|
fi
|
||||||
|
cd "$MOON_DIR"
|
||||||
|
exec luajit tests/run.lua "$@"
|
||||||
Reference in new issue
Block a user