mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-06 12:24:33 -05:00
Compare commits
59 Commits
348d525b00
...
extensions
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4440ad502 | ||
|
|
e71c94547d | ||
|
|
84a1789850 | ||
|
|
70a027f6f0 | ||
|
|
650c075723 | ||
|
|
a69e29d1a5 | ||
|
|
eec0951a75 | ||
|
|
4ace76f508 | ||
|
|
cd91b6e6ef | ||
|
|
f748bc7f6d | ||
|
|
11ff4bb280 | ||
|
|
388586f23b | ||
|
|
c8f5d83e9c | ||
|
|
be5e3f022e | ||
|
|
40a21fabca | ||
|
|
b33069f107 | ||
|
|
14ab3aa9f4 | ||
|
|
bfa0038f53 | ||
|
|
b8ffbebc76 | ||
|
|
3048df307d | ||
|
|
3b3770cb3d | ||
|
|
9667aeba18 | ||
|
|
6c8a024b0f | ||
|
|
5b2613dad3 | ||
|
|
396cfa734a | ||
|
|
a1fdf6d77a | ||
|
|
07ae17105b | ||
|
|
b8772f60bf | ||
|
|
733b9c9919 | ||
|
|
0b0c056bcb | ||
|
|
aff95bfc37 | ||
|
|
00bc3e39b6 | ||
|
|
e9c2cc49a6 | ||
|
|
ea310ba54b | ||
|
|
72347f45cc | ||
|
|
1e73e526c6 | ||
|
|
8fd0fdba08 | ||
|
|
4b61d375ed | ||
|
|
3cf4cf6cf8 | ||
|
|
74ade8a3a3 | ||
|
|
3bb2e4329e | ||
|
|
33ec15c136 | ||
|
|
3a78453a02 | ||
|
|
b7c259a4cb | ||
|
|
41ef220a0b | ||
|
|
85fe9802e2 | ||
|
|
676aed14c0 | ||
|
|
ceac5f74c4 | ||
|
|
934459f15f | ||
|
|
bab58daecc | ||
|
|
61eb0630cb | ||
|
|
0d3afadfa3 | ||
|
|
f9e81c75b6 | ||
|
|
e123857399 | ||
|
|
31817639bd | ||
|
|
2b91ab755d | ||
|
|
98576c6e62 | ||
|
|
8fbc8fd3d4 | ||
|
|
c81020dbb1 |
@@ -21,7 +21,7 @@ object CefHelper {
|
||||
}
|
||||
|
||||
fun waitForInit() =
|
||||
callbackFlow<CefApp> {
|
||||
callbackFlow {
|
||||
val app = cefApp.first { it.isFailure || it.getOrThrow() != null }.getOrThrow()!!
|
||||
app.onInitialization {
|
||||
logger.debug { "CEF: Initialization state $it" }
|
||||
|
||||
@@ -68,6 +68,7 @@ import org.cef.handler.CefLoadHandler
|
||||
import org.cef.handler.CefLoadHandlerAdapter
|
||||
import org.cef.handler.CefMessageRouterHandlerAdapter
|
||||
import org.cef.handler.CefPermissionHandler
|
||||
import org.cef.handler.CefRenderHandlerAdapter
|
||||
import org.cef.handler.CefRequestHandler
|
||||
import org.cef.handler.CefRequestHandlerAdapter
|
||||
import org.cef.handler.CefResourceHandler
|
||||
@@ -82,10 +83,13 @@ import org.cef.network.CefPostDataElement
|
||||
import org.cef.network.CefRequest
|
||||
import org.cef.network.CefResponse
|
||||
import org.koin.mp.KoinPlatformTools
|
||||
import java.awt.Rectangle
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.concurrent.Executor
|
||||
import javax.swing.JPanel
|
||||
import kotlin.math.min
|
||||
import kotlin.reflect.KFunction
|
||||
import kotlin.reflect.full.declaredMemberFunctions
|
||||
@@ -97,6 +101,7 @@ class KcefWebViewProvider(
|
||||
private val settings = KcefWebSettings()
|
||||
private var viewClient = WebViewClient()
|
||||
private var chromeClient = WebChromeClient()
|
||||
private val renderHandler = RenderHandler()
|
||||
private val mappings: MutableList<FunctionMapping> = mutableListOf()
|
||||
private val urlHttpMapping: MutableMap<String, String> = mutableMapOf()
|
||||
private var initialRequestData: InitialRequestData? = null
|
||||
@@ -522,6 +527,21 @@ class KcefWebViewProvider(
|
||||
}
|
||||
}
|
||||
|
||||
private class RenderHandler : CefRenderHandlerAdapter() {
|
||||
override fun getViewRect(browser: CefBrowser): Rectangle = Rectangle(0, 0, 1280, 2856)
|
||||
|
||||
override fun onPaint(
|
||||
browser: CefBrowser,
|
||||
popup: Boolean,
|
||||
dirtyRects: Array<Rectangle>,
|
||||
buffer: ByteBuffer,
|
||||
width: Int,
|
||||
height: Int,
|
||||
) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
override fun init(
|
||||
javaScriptInterfaces: Map<String, Any>?,
|
||||
privateBrowsing: Boolean,
|
||||
@@ -617,7 +637,7 @@ class KcefWebViewProvider(
|
||||
kcefClient!!
|
||||
.createBrowser(
|
||||
loadUrl,
|
||||
CefRendering.OFFSCREEN,
|
||||
CefRendering.CefRenderingWithHandler(renderHandler, JPanel()),
|
||||
false,
|
||||
).apply {
|
||||
// NOTE: Without this, we don't seem to be receiving any events
|
||||
@@ -642,7 +662,7 @@ class KcefWebViewProvider(
|
||||
kcefClient!!
|
||||
.createBrowser(
|
||||
url,
|
||||
CefRendering.OFFSCREEN,
|
||||
CefRendering.CefRenderingWithHandler(renderHandler, JPanel()),
|
||||
false,
|
||||
).apply {
|
||||
// NOTE: Without this, we don't seem to be receiving any events
|
||||
@@ -676,7 +696,7 @@ class KcefWebViewProvider(
|
||||
kcefClient!!
|
||||
.createBrowser(
|
||||
url,
|
||||
CefRendering.OFFSCREEN,
|
||||
CefRendering.CefRenderingWithHandler(renderHandler, JPanel()),
|
||||
false,
|
||||
).apply {
|
||||
// NOTE: Without this, we don't seem to be receiving any events
|
||||
|
||||
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
### Added
|
||||
- (**Sync**) Added [SyncYomi](https://github.com/syncyomi/syncyomi) support
|
||||
- (**OPDS**) Add option to skip chapter metadata feed providing direct stream/download links
|
||||
- (**Extension/API**) Support Extensions API v1.6
|
||||
|
||||
### Changed
|
||||
- (**Database/H2**) Use the latest H2 database engine
|
||||
@@ -29,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
- (**API**) Fix GraphQL `Filter` `notAll` and `notAny` being inversed
|
||||
- (**API**) Fix GraphQL `Filter` causing an UnsupportedOperationException when passing an empty list as a `Any` filter value
|
||||
- (**Build**) Fix CURL failing silently in builds
|
||||
- (**Backup/Database**) Fix backup creation slowdown when mapping chapters
|
||||
|
||||
## [v2.2.2100] + [WebUI: v20260508.01] - 2026-05-08
|
||||
|
||||
|
||||
@@ -110,18 +110,13 @@ Download the latest `linux-x64`(x86_64) release from [the releases section](http
|
||||
WebView support is implemented via [JCEF](https://github.com/JetBrains/jcef).
|
||||
This is optional, and is only necessary to support some extensions.
|
||||
|
||||
To have a functional WebView, several dependencies are required; aside from X11 libraries necessary for rendering Chromium, some JNI bindings are necessary: gluegen and jogl (found in Ubuntu as `libgluegen2-jni` and `libjogl2-jni`).
|
||||
Note that on some systems (e.g. Ubuntu), the JNI libraries are not automatically found, see below.
|
||||
To have a functional WebView, some X11 dependencies are required for rendering Chromium.
|
||||
These include `libxrender`, `libxcomposite` `libxdamage`, `libxkbcommon` and `libxtst`.
|
||||
|
||||
A CEF server is launched on startup, which loads the X11 libraries.
|
||||
If those are missing, you should see "Could not load 'jcef' library".
|
||||
If so, use `ldd ~/.local/share/Tachidesk/bin/kcef/libjcef.so | grep not` to figure out which libraries are not found on your system.
|
||||
|
||||
The JNI bindings are only loaded when a browser is actually launched.
|
||||
This is done by extensions that rely on WebView, not by Suwayomi itself.
|
||||
If there is a problem loading the JNI libraries, you should see a message indicating the library and the search path.
|
||||
This search path includes the current working directory, if you do not want to modify system directories.
|
||||
|
||||
Refer to the [Dockerfile](https://github.com/Suwayomi/Suwayomi-Server-docker/blob/main/Dockerfile) for more details.
|
||||
|
||||
Note that it is required to have an X session active and available to Suwayomi (i.e. `DISPLAY` is set).
|
||||
|
||||
@@ -14,7 +14,7 @@ val getTachideskVersion = { "v2.2.${getCommitCount()}" }
|
||||
|
||||
val webUIRevisionTag = "r3136"
|
||||
|
||||
val webviewJbrRelease = "jbr-release-25.0.3b496.62"
|
||||
val webviewJbrRelease = "jbr-release-25.0.3b508.4"
|
||||
|
||||
private val getCommitCount = {
|
||||
runCatching {
|
||||
|
||||
@@ -159,15 +159,20 @@ server.systemTrayEnabled = true
|
||||
server.maxLogFiles = 31
|
||||
server.maxLogFileSize = "10mb"
|
||||
server.maxLogFolderSize = "100mb"
|
||||
server.extensionRepos = []
|
||||
server.maxSourcesInParallel = 6
|
||||
|
||||
```
|
||||
- `server.debugLogsEnabled` controls whether if Suwayomi-Server should print more information while being run inside a Terminal/CMD/Powershell window.
|
||||
- `server.systemTrayEnabled = true` whether if Suwayomi-Server should show a System Tray Icon, disabling this on headless servers is recommended.
|
||||
- `server.maxLogFiles = 31` sets the maximum number of days to keep files before they get deleted.
|
||||
- `server.maxLogFileSize = "10mb"` sets the maximum size of a log file - values are formatted like: 1 (bytes), 1KB (kilobytes), 1MB (megabytes), 1GB (gigabytes)
|
||||
- `server.maxLogFolderSize = "100mb"` sets the maximum size of all saved log files - values are formatted like: 1 (bytes), 1KB (kilobytes), 1MB (megabytes), 1GB (gigabytes)
|
||||
- `server.extensionRepos` is a list of extension repositories for custom sources. Uses the same format as Mihon; each entry is expected to be a string URL pointing to a JSON file representing the repository.
|
||||
|
||||
### Extension/Source
|
||||
```
|
||||
server.extensionStores = []
|
||||
server.maxSourcesInParallel = 6
|
||||
```
|
||||
- `server.extensionStores` is a list of extension stores (previously called repositories) for custom sources. Uses the same format as Mihon; each entry is expected to be a string URL pointing to a JSON or PROTOBUF file representing the repository.
|
||||
- `server.maxSourcesInParallel = 6` sets how many sources can do requests (updates, downloads) in parallel. Updates/downloads are grouped by source and all mangas of a source are updated/downloaded synchronously. Range: 1 <= n <= 20.
|
||||
|
||||
### Backup
|
||||
@@ -232,6 +237,7 @@ server.opdsShowOnlyUnreadChapters = false
|
||||
server.opdsShowOnlyDownloadedChapters = false
|
||||
server.opdsChapterSortOrder = "DESC"
|
||||
server.opdsCbzMimetype = "MODERN"
|
||||
server.opdsSkipChapterMetadataFeed = false
|
||||
```
|
||||
- `server.opdsUseBinaryFileSizes = false` controls if Suwayomi should display file sizes in binary units (KiB, MiB, GiB) or decimal (KB, MB, GB) in OPDS listings.
|
||||
- `server.opdsItemsPerPage = 50` sets the number of items per page in OPDS listings. Range: 10 <= n <= 5000.
|
||||
@@ -241,6 +247,7 @@ server.opdsCbzMimetype = "MODERN"
|
||||
- `server.opdsShowOnlyDownloadedChapters = false` controls if OPDS listings should only include downloaded chapters.
|
||||
- `server.opdsChapterSortOrder = "DESC"` sets the default chapter sort order in OPDS listings, either `"ASC"` or `"DESC"`
|
||||
- `server.opdsCbzMimetype = "MODERN"` controls which mimetype to use for CBZ downloads. This affects the offered link in OPDS, as well as the content type of the CBZ download. Allowed is MODERN (current IANA standard), LEGACY (deprecated mimetype for .cbz) and COMPATIBLE (deprecated mimetype for all comic archives). Use LEGACY or COMPATIBLE if older clients don't offer the chapter download (note that the chapter needs to first be downloaded in Suwayomi, before it is available in OPDS).
|
||||
- `server.opdsSkipChapterMetadataFeed = false` controls if the metadata feed should be skipped. When enabled, download and streaming links are provided directly in the chapter list. This improves compatibility with automated downloaders (like KOReader). KoSync strategies are applied, but `PROMPT` conflicts are ignored (treating local progress as priority).
|
||||
|
||||
### KOReader Sync
|
||||
```
|
||||
|
||||
@@ -3,19 +3,19 @@ kotlin = "2.4.0"
|
||||
coroutines = "1.11.0"
|
||||
serialization = "1.11.0"
|
||||
jvmTarget = "21"
|
||||
okhttp = "5.3.2" # Major version is locked by Tachiyomi extensions
|
||||
okhttp = "5.4.0" # Major version is locked by Tachiyomi extensions
|
||||
javalin = "7.2.2"
|
||||
jte = "3.2.4"
|
||||
jackson = "3.1.4" # jackson version locked by javalin, ref: `io.javalin.core.util.OptionalDependency`
|
||||
jackson = "3.2.0" # jackson version locked by javalin, ref: `io.javalin.core.util.OptionalDependency`
|
||||
exposed = "1.2.0"
|
||||
dex2jar = "2.4.36"
|
||||
dex2jar = "2.4.37"
|
||||
polyglot = "25.0.3"
|
||||
settings = "1.3.0"
|
||||
twelvemonkeys = "3.13.1"
|
||||
graphqlkotlin = "10.0.0"
|
||||
xmlserialization = "0.91.3"
|
||||
ktlint = "1.8.0"
|
||||
koin = "4.2.1"
|
||||
koin = "4.2.2"
|
||||
moko = "0.26.4"
|
||||
jcef = "144.0.15-g72717cf-chromium-144.0.7559.172-api-1.21-262-b37"
|
||||
|
||||
@@ -47,6 +47,7 @@ okhttp-core = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
|
||||
okhttp-logging = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
|
||||
okhttp-dnsoverhttps = { module = "com.squareup.okhttp3:okhttp-dnsoverhttps", version.ref = "okhttp" }
|
||||
okhttp-brotli = { module = "com.squareup.okhttp3:okhttp-brotli", version.ref = "okhttp" }
|
||||
okhttp-zstd = { module = "com.squareup.okhttp3:okhttp-zstd", version.ref = "okhttp" }
|
||||
okio = "com.squareup.okio:okio:3.17.0"
|
||||
|
||||
# Javalin api
|
||||
@@ -70,9 +71,10 @@ exposed-dao = { module = "org.jetbrains.exposed:exposed-dao", version.ref = "exp
|
||||
exposed-jdbc = { module = "org.jetbrains.exposed:exposed-jdbc", version.ref = "exposed" }
|
||||
exposed-javatime = { module = "org.jetbrains.exposed:exposed-java-time", version.ref = "exposed" }
|
||||
exposed-kotlintime = { module = "org.jetbrains.exposed:exposed-kotlin-datetime", version.ref = "exposed" }
|
||||
exposed-json = { module = "org.jetbrains.exposed:exposed-json ", version.ref = "exposed" }
|
||||
postgres = "org.postgresql:postgresql:42.7.11"
|
||||
h2 = "com.h2database:h2:2.4.240"
|
||||
hikaricp = "com.zaxxer:HikariCP:7.0.2"
|
||||
hikaricp = "com.zaxxer:HikariCP:7.1.0"
|
||||
|
||||
# Exposed Migrations
|
||||
exposed-migrations = "com.github.Suwayomi:exposed-migrations:3.10.1"
|
||||
@@ -145,7 +147,7 @@ twelvemonkeys-imageio-metadata = { module = "com.twelvemonkeys.imageio:imageio-m
|
||||
twelvemonkeys-imageio-jpeg = { module = "com.twelvemonkeys.imageio:imageio-jpeg", version.ref = "twelvemonkeys" }
|
||||
twelvemonkeys-imageio-webp = { module = "com.twelvemonkeys.imageio:imageio-webp", version.ref = "twelvemonkeys" }
|
||||
|
||||
imageio-webp = "com.github.usefulness:webp-imageio:0.10.2"
|
||||
imageio-webp = "com.github.usefulness:webp-imageio:0.11.0"
|
||||
|
||||
# Testing
|
||||
mockk = "io.mockk:mockk:1.14.11"
|
||||
@@ -158,8 +160,6 @@ cronUtils = "com.cronutils:cron-utils:9.2.1"
|
||||
|
||||
# Webview
|
||||
jcef = { module = "org.jetbrains.intellij.deps.jcef:jcef", version.ref = "jcef" }
|
||||
gluegen = "org.jogamp.gluegen:gluegen-rt:2.5.0"
|
||||
jogl = "org.jogamp.jogl:jogl-all:2.5.0"
|
||||
|
||||
# User
|
||||
jwt = "com.auth0:java-jwt:4.5.2"
|
||||
@@ -229,6 +229,7 @@ okhttp = [
|
||||
"okhttp-logging",
|
||||
"okhttp-dnsoverhttps",
|
||||
"okhttp-brotli",
|
||||
"okhttp-zstd",
|
||||
]
|
||||
javalin = [
|
||||
"javalin-core",
|
||||
@@ -247,6 +248,7 @@ exposed = [
|
||||
"exposed-jdbc",
|
||||
"exposed-javatime",
|
||||
"exposed-kotlintime",
|
||||
"exposed-json",
|
||||
]
|
||||
systemtray = [
|
||||
"systemtray-core",
|
||||
|
||||
@@ -37,10 +37,6 @@ dependencies {
|
||||
implementation(libs.bundles.shared)
|
||||
testImplementation(libs.bundles.sharedTest)
|
||||
|
||||
// WebView
|
||||
implementation(libs.gluegen)
|
||||
implementation(libs.jogl)
|
||||
|
||||
// OkHttp
|
||||
implementation(libs.bundles.okhttp)
|
||||
implementation(libs.okio)
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
<!-- OPDS errors -->
|
||||
<string name="opds_error_manga_not_found">Series with ID %1$d not found.</string>
|
||||
<string name="opds_error_chapter_not_found">Chapter with index %1$d not found.</string>
|
||||
<string name="opds_error_chapters_not_found">No chapters found or the source is unreachable on page %1$d.</string>
|
||||
|
||||
<!-- OPDS facets (Filters and Sorting) -->
|
||||
<string name="opds_facetgroup_sort_order">Sort Order</string>
|
||||
@@ -153,4 +154,7 @@
|
||||
<string name="login_label_login">Log In</string>
|
||||
<string name="login_placeholder_username">Type username...</string>
|
||||
<string name="login_placeholder_password">Secret...</string>
|
||||
|
||||
<string name="opds_chapter_title_oneshot">Oneshot</string>
|
||||
<string name="opds_chapter_title_fallback">Chapter %1$s</string>
|
||||
</resources>
|
||||
|
||||
125
server/i18n/src/commonMain/moko-resources/values/el/strings.xml
Normal file
125
server/i18n/src/commonMain/moko-resources/values/el/strings.xml
Normal file
@@ -0,0 +1,125 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
<string name="opds_feeds_root">Suwayomi OPDS Κατάλογος</string>
|
||||
<string name="opds_feeds_manga_chapters">Κεφάλαια %1$s</string>
|
||||
<string name="opds_feeds_chapter_details">%1$s | %2$s | Λεπτομέρειες</string>
|
||||
<string name="opds_feeds_explore_title">Εξερεύνηση</string>
|
||||
<string name="opds_feeds_explore_entry_content">Εξερεύνησε νέες σειρές από τις πηγές σου</string>
|
||||
<string name="opds_feeds_history_title">Ιστορικό</string>
|
||||
<string name="opds_feeds_history_entry_content">Πρόσφατα διαβασμένα κεφάλαια</string>
|
||||
<string name="opds_feeds_all_series_in_library_title">Όλες οι σειρές</string>
|
||||
<string name="opds_feeds_all_series_in_library_entry_content">Περιήγηση σε όλες τις σειρές της βιβλιοθήκης σου</string>
|
||||
<string name="opds_feeds_library_sources_title">Πηγές</string>
|
||||
<string name="opds_feeds_library_sources_entry_content">Περιήγηση σε σειρές της βιβλιοθήκης σου φιλτραρισμένες κατά πηγή</string>
|
||||
<string name="opds_feeds_categories_title">Κατηγορίες</string>
|
||||
<string name="opds_feeds_categories_entry_content">Περιήγηση σε σειρές οργανωμένες κατά κατηγορία</string>
|
||||
<string name="opds_feeds_genres_title">Είδη</string>
|
||||
<string name="opds_feeds_genres_entry_content">Περιήγηση σε σειρές κατά ετικέτες είδους</string>
|
||||
<string name="opds_feeds_status_title">Κατάσταση</string>
|
||||
<string name="opds_feeds_status_entry_content">Περιήγηση σε σειρές κατά κατάσταση δημοσίευσης</string>
|
||||
<string name="opds_feeds_languages_title">Γλώσσες</string>
|
||||
<string name="opds_feeds_languages_entry_content">Περιήγηση σε σειρές κατά γλώσσα περιεχομένου</string>
|
||||
<string name="opds_feeds_library_updates_title">Ιστορικό ενημερώσεων βιβλιοθήκης</string>
|
||||
<string name="opds_feeds_library_updates_entry_content">Πρόσφατα ενημερωμένα κεφάλαια από τη βιβλιοθήκη σου</string>
|
||||
<string name="opds_feeds_search_results_title">Αποτελέσματα αναζήτησης</string>
|
||||
<string name="opds_feeds_sources_title">Όλες οι πηγές</string>
|
||||
<string name="opds_feeds_category_specific_title">Κατηγορία: %1$s</string>
|
||||
<string name="opds_feeds_genre_specific_title">Είδος: %1$s</string>
|
||||
<string name="opds_feeds_status_specific_title">Κατάσταση: %1$s</string>
|
||||
<string name="opds_feeds_language_specific_title">Γλώσσα: %1$s</string>
|
||||
<string name="opds_feeds_source_specific_title">Πηγή: %1$s</string>
|
||||
<string name="opds_feeds_library_source_specific_title">Βιβλιοθήκη - Πηγή: %1$s</string>
|
||||
<string name="opds_feeds_source_specific_popular_title">Πηγή: %1$s - Δημοφιλές</string>
|
||||
<string name="opds_feeds_source_specific_latest_title">Πηγή: %1$s - Τελευταίο</string>
|
||||
<string name="opds_search_shortname">Suwayomi OPDS Αναζήτηση</string>
|
||||
<string name="opds_search_description">Αναζήτηση σειρών στον κατάλογο.</string>
|
||||
<string name="opds_error_manga_not_found">Η σειρά με ID %1$d δεν βρέθηκε.</string>
|
||||
<string name="opds_error_chapter_not_found">Το κεφάλαιο με δείκτη %1$d δεν βρέθηκε.</string>
|
||||
<string name="opds_facetgroup_sort_order">Σειρά ταξινόμησης</string>
|
||||
<string name="opds_facetgroup_filter_read_status">Φίλτρο κατά κατάσταση ανάγνωσης</string>
|
||||
<string name="opds_facetgroup_filter_content">Φίλτρο περιεχομένου</string>
|
||||
<string name="opds_facetgroup_filter_source">Φίλτρο κατά πηγή</string>
|
||||
<string name="opds_facetgroup_filter_category">Φίλτρο κατά κατηγορία</string>
|
||||
<string name="opds_facetgroup_filter_status">Φίλτρο κατά κατάσταση</string>
|
||||
<string name="opds_facetgroup_filter_language">Φίλτρο κατά γλώσσα</string>
|
||||
<string name="opds_facetgroup_filter_genre">Φίλτρο κατά είδος</string>
|
||||
<string name="opds_facet_sort_oldest_first">Παλαιότερα πρώτα</string>
|
||||
<string name="opds_facet_sort_newest_first">Νεότερα πρώτα</string>
|
||||
<string name="opds_facet_sort_date_asc">Ημερομηνία αύξουσα</string>
|
||||
<string name="opds_facet_sort_date_desc">Ημερομηνία φθίνουσα</string>
|
||||
<string name="opds_facet_sort_popular">Δημοφιλές</string>
|
||||
<string name="opds_facet_sort_latest">Τελευταίο</string>
|
||||
<string name="opds_facet_sort_alpha_asc">Αλφαβητικά Α-Ω</string>
|
||||
<string name="opds_facet_sort_alpha_desc">Αλφαβητικά Ω-Α</string>
|
||||
<string name="opds_facet_sort_last_read_desc">Τελευταία ανάγνωση</string>
|
||||
<string name="opds_facet_sort_latest_chapter_desc">Τελευταίο κεφάλαιο</string>
|
||||
<string name="opds_facet_sort_date_added_desc">Ημερομηνία προσθήκης</string>
|
||||
<string name="opds_facet_sort_unread_desc">Αδιάβαστα κεφάλαια</string>
|
||||
<string name="opds_facet_filter_all">Όλα</string>
|
||||
<string name="opds_facet_filter_all_chapters">Όλα τα κεφάλαια</string>
|
||||
<string name="opds_facet_filter_unread_only">Αδιάβαστα</string>
|
||||
<string name="opds_facet_filter_read_only">Διαβασμένα</string>
|
||||
<string name="opds_facet_filter_downloaded">Ληφθέντα</string>
|
||||
<string name="opds_facet_filter_ongoing">Σε εξέλιξη</string>
|
||||
<string name="opds_facet_filter_completed">Ολοκληρωμένα</string>
|
||||
<string name="opds_facet_all_sources">Όλες οι πηγές</string>
|
||||
<string name="opds_facet_all_categories">Όλες οι κατηγορίες</string>
|
||||
<string name="opds_facet_all_statuses">Όλες οι καταστάσεις</string>
|
||||
<string name="opds_facet_all_languages">Όλες οι γλώσσες</string>
|
||||
<string name="opds_facet_all_genres">Όλα τα είδη</string>
|
||||
<string name="opds_linktitle_catalog_root">Ρίζα καταλόγου</string>
|
||||
<string name="opds_linktitle_search_catalog">Αναζήτηση καταλόγου</string>
|
||||
<string name="opds_linktitle_first_page">Πρώτη σελίδα</string>
|
||||
<string name="opds_linktitle_previous_page">Προηγούμενη σελίδα</string>
|
||||
<string name="opds_linktitle_next_page">Επόμενη σελίδα</string>
|
||||
<string name="opds_linktitle_last_page">Τελευταία σελίδα</string>
|
||||
<string name="opds_linktitle_self_feed">Τρέχουσα ροή</string>
|
||||
<string name="opds_linktitle_view_on_web">Προβολή στο Web</string>
|
||||
<string name="opds_linktitle_stream_pages_start">Διάβασε Online</string>
|
||||
<string name="opds_linktitle_stream_pages_continue">Συνέχισε να διαβάζεις Online</string>
|
||||
<string name="opds_linktitle_stream_pages_start_local">Διάβασε Online (Τοπική πρόοδος)</string>
|
||||
<string name="opds_linktitle_stream_pages_continue_local">Συνέχισε να διαβάζεις Online (Τοπική πρόοδος)</string>
|
||||
<string name="opds_linktitle_stream_pages_start_remote">Διάβασε Online (Συγχρονισμένο από %1$s)</string>
|
||||
<string name="opds_linktitle_stream_pages_continue_remote">Συνέχισε να διαβάζεις Online (Συγχρονισμένο από %1$s)</string>
|
||||
<string name="opds_linktitle_download_cbz">Λήψη CBZ</string>
|
||||
<string name="opds_linktitle_chapter_cover">Εξώφυλλο κεφαλαίου</string>
|
||||
<string name="opds_linktitle_view_chapter_details">Λεπτομέρειες κεφαλαίου & Σελίδες</string>
|
||||
<string name="opds_chapter_status_read">✅</string>
|
||||
<string name="opds_chapter_status_in_progress">⌛</string>
|
||||
<string name="opds_chapter_status_unread">⭕</string>
|
||||
<string name="opds_chapter_status_downloaded">⬇️</string>
|
||||
<string name="opds_chapter_status_synced">🌐</string>
|
||||
<string name="opds_chapter_details_base">Σειρά: %1$s | %2$s</string>
|
||||
<string name="opds_chapter_details_scanlator">| Από %1$s</string>
|
||||
<string name="opds_chapter_details_progress">| Πρόοδος: %1$d από %2$d</string>
|
||||
<string name="opds_manga_summary_status">Κατάσταση: %1$s</string>
|
||||
<string name="opds_manga_summary_source">Πηγή: %1$s</string>
|
||||
<string name="opds_manga_summary_language">Γλώσσα: %1$s</string>
|
||||
<string name="manga_status_ongoing">Σε εξέλιξη</string>
|
||||
<string name="manga_status_completed">Ολοκληρωμένο</string>
|
||||
<string name="manga_status_licensed">Υπό άδεια</string>
|
||||
<string name="manga_status_publishing_finished">Δημοσίευση ολοκληρωμένη</string>
|
||||
<string name="manga_status_cancelled">Ακυρωμένο</string>
|
||||
<string name="manga_status_on_hiatus">Σε παύση</string>
|
||||
<string name="manga_status_unknown">Άγνωστο</string>
|
||||
<string name="label_error">Σφάλμα</string>
|
||||
<string name="label_version">Έκδοση <xliff:g id="version" example="v2.0.1833">%1$s</xliff:g></string>
|
||||
<string name="label_close">Κλείσε</string>
|
||||
<string name="webview_label_title">Suwayomi WebView</string>
|
||||
<string name="webview_label_disconnected">Αποσυνδεδεμένο, κάνε ανανέωση</string>
|
||||
<string name="webview_label_reversescroll">Αντίστροφη κύλιση</string>
|
||||
<string name="webview_label_bindingshint">Σημείωση: Όταν η εστίαση είναι στο τμήμα WebView, καμία συντόμευση πληκτρολογίου, συμπεριλαμβανομένης της ανανέωσης, δεν θα αντιμετωπίζεται από το πρόγραμμα περιήγησης.</string>
|
||||
<string name="webview_label_init">Αρχικοποίηση... Παρακαλώ περίμενε</string>
|
||||
<string name="webview_label_getstarted">Εισήγαγε μια διεύθυνση URL για να ξεκινήσεις</string>
|
||||
<string name="webview_label_loading">Φόρτωση σελίδας...</string>
|
||||
<string name="webview_label_copy">Αντιγραφή στο πρόχειρο</string>
|
||||
<string name="webview_label_copy_description">Η αυτόματη αντιγραφή στο πρόχειρο απέτυχε, χρησιμοποίησε το παρακάτω πεδίο για να αντιγράψεις χειροκίνητα την τιμή.</string>
|
||||
<string name="webview_label_login_required">Η διαμόρφωσή σου απαιτεί σύνδεση. Εισήγαγε όνομα χρήστη και κωδικό.</string>
|
||||
<string name="webview_placeholder_url">Εισήγαγε URL...</string>
|
||||
<string name="login_label_title">Suwayomi Σύνδεση</string>
|
||||
<string name="login_label_username">Όνομα χρήστη</string>
|
||||
<string name="login_label_password">Κωδικός</string>
|
||||
<string name="login_label_login">Σύνδεση</string>
|
||||
<string name="login_placeholder_username">Πληκτρολόγησε όνομα χρήστη...</string>
|
||||
<string name="login_placeholder_password">Μυστικό...</string>
|
||||
</resources>
|
||||
@@ -15,16 +15,13 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import org.jetbrains.exposed.v1.core.SortOrder
|
||||
import suwayomi.tachidesk.graphql.types.AuthMode
|
||||
@@ -279,30 +276,38 @@ class ServerConfig(
|
||||
description = "Ignore re-uploaded chapters from auto-download",
|
||||
)
|
||||
|
||||
val extensionRepos: MutableStateFlow<List<String>> by ListSetting<String>(
|
||||
@Deprecated("Will get removed", replaceWith = ReplaceWith("extensionStores"))
|
||||
val extensionRepos: MutableStateFlow<List<String>> by MigratedConfigValue(
|
||||
protoNumber = 22,
|
||||
group = SettingGroup.EXTENSION,
|
||||
privacySafe = false,
|
||||
defaultValue = emptyList(),
|
||||
itemValidator = { url ->
|
||||
if (url.matches(repoMatchRegex)) {
|
||||
null
|
||||
} else {
|
||||
"Invalid repository URL format"
|
||||
}
|
||||
},
|
||||
itemToValidValue = { url ->
|
||||
if (url.matches(repoMatchRegex)) {
|
||||
url
|
||||
} else {
|
||||
null
|
||||
}
|
||||
},
|
||||
deprecated =
|
||||
SettingsRegistry.SettingDeprecated(
|
||||
message = "Replaced with addExtensionStore and removeExtensionStore mutations",
|
||||
migrateConfigValue = {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(it.unwrapped() as? List<String>)
|
||||
?.map {
|
||||
if (it.contains("github.com")) {
|
||||
it.replace(repoMatchRegex) {
|
||||
"https://raw.githubusercontent.com/${it.groupValues[2]}/${it.groupValues[3]}/" +
|
||||
(it.groupValues.getOrNull(4)?.ifBlank { null } ?: "repo") +
|
||||
"/" +
|
||||
(it.groupValues.getOrNull(5)?.ifBlank { null } ?: "index.min.json")
|
||||
}
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
readMigrated = { extensionStores.value },
|
||||
setMigrated = { extensionStores.value = it.distinct() },
|
||||
typeInfo =
|
||||
SettingsRegistry.PartialTypeInfo(
|
||||
specificType = "List<String>",
|
||||
),
|
||||
description = "example: [\"https://github.com/MY_ACCOUNT/MY_REPO/tree/repo\"]",
|
||||
)
|
||||
|
||||
val maxSourcesInParallel: MutableStateFlow<Int> by IntSetting(
|
||||
@@ -1101,6 +1106,37 @@ class ServerConfig(
|
||||
privacySafe = true,
|
||||
)
|
||||
|
||||
val opdsSkipChapterMetadataFeed: MutableStateFlow<Boolean> by BooleanSetting(
|
||||
protoNumber = 96,
|
||||
group = SettingGroup.OPDS,
|
||||
privacySafe = true,
|
||||
defaultValue = false,
|
||||
description = "Skips the metadata feed and provides download/stream links directly in the chapter list. Improves compatibility with KOReader auto-downloader. KoSync strategies are applied, but PROMPT conflicts are ignored (treating local progress as priority)."
|
||||
)
|
||||
|
||||
val extensionStores: MutableStateFlow<List<String>> by ListSetting<String>(
|
||||
protoNumber = 97,
|
||||
group = SettingGroup.EXTENSION,
|
||||
privacySafe = true,
|
||||
defaultValue = emptyList(),
|
||||
requiresRestart = true,
|
||||
itemValidator = { url ->
|
||||
if (url.isNotEmpty()) {
|
||||
null
|
||||
} else {
|
||||
"Invalid store URL format"
|
||||
}
|
||||
},
|
||||
itemToValidValue = { url ->
|
||||
url.ifEmpty { null }
|
||||
},
|
||||
typeInfo =
|
||||
SettingsRegistry.PartialTypeInfo(
|
||||
specificType = "List<String>",
|
||||
),
|
||||
description = "List of extension store index URLs",
|
||||
)
|
||||
|
||||
/** ****************************************************************** **/
|
||||
/** **/
|
||||
/** Renamed settings **/
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.kanade.tachiyomi.network
|
||||
|
||||
import okhttp3.Response
|
||||
|
||||
/**
|
||||
* Exception that handles HTTP codes considered not successful by OkHttp.
|
||||
* Use it to have a standardized error message in the app across the extensions.
|
||||
*
|
||||
* @see Response.isSuccessful
|
||||
* @since tachiyomix 1.6
|
||||
* @param code [Int] the HTTP status code
|
||||
*/
|
||||
class HttpException(
|
||||
val code: Int,
|
||||
) : IllegalStateException("HTTP error $code")
|
||||
@@ -2,26 +2,25 @@ package eu.kanade.tachiyomi.network
|
||||
|
||||
import android.content.Context
|
||||
import app.cash.quickjs.QuickJs
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
|
||||
/**
|
||||
* Util for evaluating JavaScript in sources.
|
||||
*/
|
||||
@Suppress("UNUSED", "UNCHECKED_CAST")
|
||||
class JavaScriptEngine(
|
||||
@Suppress("UNUSED_PARAMETER") context: Context,
|
||||
context: Context,
|
||||
) {
|
||||
/**
|
||||
* Evaluate arbitrary JavaScript code and get the result as a primitive type
|
||||
* (e.g., String, Int).
|
||||
*
|
||||
* @since extensions-lib 1.4
|
||||
* @since tachiyomix 1.4
|
||||
* @param script JavaScript to execute.
|
||||
* @return Result of JavaScript code as a primitive type.
|
||||
*/
|
||||
@Suppress("UNUSED", "UNCHECKED_CAST")
|
||||
suspend fun <T> evaluate(script: String): T =
|
||||
withContext(Dispatchers.IO) {
|
||||
withIOContext {
|
||||
QuickJs.create().use {
|
||||
it.evaluate(script) as T
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ package eu.kanade.tachiyomi.network
|
||||
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.network.interceptor.CloudflareInterceptor
|
||||
import eu.kanade.tachiyomi.network.interceptor.IgnoreGzipInterceptor
|
||||
import eu.kanade.tachiyomi.network.interceptor.UncaughtExceptionInterceptor
|
||||
import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
@@ -22,7 +21,6 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import okhttp3.Cache
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.brotli.BrotliInterceptor
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource
|
||||
import java.net.CookieHandler
|
||||
@@ -84,8 +82,6 @@ class NetworkHelper(
|
||||
),
|
||||
).addInterceptor(UncaughtExceptionInterceptor())
|
||||
.addInterceptor(UserAgentInterceptor(::defaultUserAgentProvider))
|
||||
.addNetworkInterceptor(IgnoreGzipInterceptor())
|
||||
.addNetworkInterceptor(BrotliInterceptor)
|
||||
|
||||
// if (preferences.verboseLogging().get()) {
|
||||
val httpLoggingInterceptor =
|
||||
@@ -128,5 +124,7 @@ class NetworkHelper(
|
||||
// val client by lazy { baseClientBuilder.cache(Cache(cacheDir, cacheSize)).build() }
|
||||
val client by lazy { baseClientBuilder.build() }
|
||||
|
||||
@Deprecated("The regular client handles Cloudflare by default")
|
||||
@Suppress("UNUSED")
|
||||
val cloudflareClient by lazy { client }
|
||||
}
|
||||
|
||||
@@ -15,11 +15,14 @@ import rx.Observable
|
||||
import rx.Producer
|
||||
import rx.Subscription
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import kotlin.concurrent.atomics.AtomicBoolean
|
||||
import kotlin.concurrent.atomics.ExperimentalAtomicApi
|
||||
import kotlin.coroutines.resumeWithException
|
||||
|
||||
val jsonMime = "application/json; charset=utf-8".toMediaType()
|
||||
|
||||
@OptIn(ExperimentalAtomicApi::class)
|
||||
@Deprecated("Use suspend APIs instead")
|
||||
fun Call.asObservable(): Observable<Response> {
|
||||
return Observable.unsafeCreate { subscriber ->
|
||||
// Since Call is a one-shot type, clone it for each new subscriber.
|
||||
@@ -27,9 +30,11 @@ fun Call.asObservable(): Observable<Response> {
|
||||
|
||||
// Wrap the call in a helper which handles both unsubscription and backpressure.
|
||||
val requestArbiter =
|
||||
object : AtomicBoolean(), Producer, Subscription {
|
||||
object : Producer, Subscription {
|
||||
val boolean = AtomicBoolean(false)
|
||||
|
||||
override fun request(n: Long) {
|
||||
if (n == 0L || !compareAndSet(false, true)) return
|
||||
if (n == 0L || !boolean.compareAndSet(expectedValue = false, newValue = true)) return
|
||||
|
||||
try {
|
||||
val response = call.execute()
|
||||
@@ -37,15 +42,15 @@ fun Call.asObservable(): Observable<Response> {
|
||||
subscriber.onNext(response)
|
||||
subscriber.onCompleted()
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
} catch (e: Exception) {
|
||||
if (!subscriber.isUnsubscribed) {
|
||||
subscriber.onError(error)
|
||||
subscriber.onError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun unsubscribe() {
|
||||
// call.cancel()
|
||||
call.cancel()
|
||||
}
|
||||
|
||||
override fun isUnsubscribed(): Boolean = call.isCanceled()
|
||||
@@ -56,50 +61,50 @@ fun Call.asObservable(): Observable<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
fun Call.asObservableSuccess(): Observable<Response> =
|
||||
asObservable()
|
||||
.doOnNext { response ->
|
||||
if (!response.isSuccessful) {
|
||||
response.close()
|
||||
throw HttpException(response.code)
|
||||
@Deprecated("Use suspend APIs instead")
|
||||
fun Call.asObservableSuccess(): Observable<Response> {
|
||||
@Suppress("DEPRECATION")
|
||||
return asObservable().doOnNext { response ->
|
||||
if (!response.isSuccessful) {
|
||||
response.close()
|
||||
throw HttpException(response.code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Based on https://github.com/square/okhttp/blob/master/okhttp-coroutines/src/main/kotlin/okhttp3/coroutines/ExecuteAsync.kt
|
||||
// and https://github.com/gildor/kotlin-coroutines-okhttp
|
||||
private suspend fun Call.await(callStack: Array<StackTraceElement>): Response {
|
||||
return suspendCancellableCoroutine { continuation ->
|
||||
continuation.invokeOnCancellation {
|
||||
try {
|
||||
this.cancel()
|
||||
} catch (_: Throwable) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Based on https://github.com/gildor/kotlin-coroutines-okhttp
|
||||
private suspend fun Call.await(callStack: Array<StackTraceElement>): Response {
|
||||
return suspendCancellableCoroutine { continuation ->
|
||||
val callback =
|
||||
this.enqueue(
|
||||
object : Callback {
|
||||
override fun onResponse(
|
||||
call: Call,
|
||||
response: Response,
|
||||
) {
|
||||
continuation.resume(response) { _, resourceToClose, _ ->
|
||||
response.body.close()
|
||||
resourceToClose.close()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(
|
||||
call: Call,
|
||||
e: IOException,
|
||||
) {
|
||||
// Don't bother with resuming the continuation if it is already cancelled.
|
||||
if (continuation.isCancelled) return
|
||||
val exception = IOException(e.message, e).apply { stackTrace = callStack }
|
||||
continuation.resumeWithException(exception)
|
||||
}
|
||||
}
|
||||
|
||||
enqueue(callback)
|
||||
|
||||
continuation.invokeOnCancellation {
|
||||
try {
|
||||
cancel()
|
||||
} catch (ex: Throwable) {
|
||||
// Ignore cancel exception
|
||||
}
|
||||
}
|
||||
override fun onResponse(
|
||||
call: Call,
|
||||
response: Response,
|
||||
) {
|
||||
continuation.resume(response) { _, value, _ ->
|
||||
value.close()
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +114,7 @@ suspend fun Call.await(): Response {
|
||||
}
|
||||
|
||||
/**
|
||||
* @since extensions-lib 1.5
|
||||
* Similar to [await] but throws [HttpException] if [Response.isSuccessful] returns false
|
||||
*/
|
||||
suspend fun Call.awaitSuccess(): Response {
|
||||
val callStack = Exception().stackTrace.run { copyOfRange(1, size) }
|
||||
@@ -150,7 +155,3 @@ fun <T> decodeFromJsonResponse(
|
||||
response.body.source().use {
|
||||
json.decodeFromBufferedSource(deserializer, it)
|
||||
}
|
||||
|
||||
class HttpException(
|
||||
val code: Int,
|
||||
) : IllegalStateException("HTTP error $code")
|
||||
|
||||
@@ -35,7 +35,11 @@ class ProgressResponseBody(
|
||||
val bytesRead = super.read(sink, byteCount)
|
||||
// read() returns the number of bytes read, or -1 if this source is exhausted.
|
||||
totalBytesRead += if (bytesRead != -1L) bytesRead else 0
|
||||
progressListener.update(totalBytesRead, responseBody.contentLength(), bytesRead == -1L)
|
||||
progressListener.update(
|
||||
totalBytesRead,
|
||||
responseBody.contentLength(),
|
||||
bytesRead == -1L,
|
||||
)
|
||||
return bytesRead
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import okhttp3.CacheControl
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody
|
||||
import java.util.concurrent.TimeUnit.MINUTES
|
||||
@@ -18,13 +19,7 @@ fun GET(
|
||||
url: String,
|
||||
headers: Headers = DEFAULT_HEADERS,
|
||||
cache: CacheControl = DEFAULT_CACHE_CONTROL,
|
||||
): Request =
|
||||
Request
|
||||
.Builder()
|
||||
.url(url)
|
||||
.headers(headers)
|
||||
.cacheControl(cache)
|
||||
.build()
|
||||
): Request = GET(url.toHttpUrl(), headers, cache)
|
||||
|
||||
/**
|
||||
* @since extensions-lib 1.4
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package eu.kanade.tachiyomi.network.interceptor
|
||||
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
||||
/**
|
||||
* To use [okhttp3.brotli.BrotliInterceptor] as a network interceptor,
|
||||
* add [IgnoreGzipInterceptor] right before it.
|
||||
*
|
||||
* This nullifies the transparent gzip of [okhttp3.internal.http.BridgeInterceptor]
|
||||
* so gzip and Brotli are explicitly handled by the [okhttp3.brotli.BrotliInterceptor].
|
||||
*/
|
||||
class IgnoreGzipInterceptor : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
var request = chain.request()
|
||||
if (request.header("Accept-Encoding") == "gzip") {
|
||||
request = request.newBuilder().removeHeader("Accept-Encoding").build()
|
||||
}
|
||||
return chain.proceed(request)
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,12 @@ package eu.kanade.tachiyomi.source
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.SMangaUpdate
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
import rx.Observable
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
|
||||
|
||||
@@ -11,68 +17,62 @@ interface CatalogueSource : Source {
|
||||
*/
|
||||
override val lang: String
|
||||
|
||||
/**
|
||||
* Whether the source has support for latest updates.
|
||||
*/
|
||||
val supportsLatest: Boolean
|
||||
|
||||
/**
|
||||
* Get a page with a list of manga.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
suspend fun getPopularManga(page: Int): MangasPage = fetchPopularManga(page).awaitSingle()
|
||||
override suspend fun getPopularManga(page: Int): MangasPage = fetchPopularManga(page).awaitSingle()
|
||||
|
||||
/**
|
||||
* Get a page with a list of manga.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
* @param page the page number to retrieve.
|
||||
* @param query the search query.
|
||||
* @param filters the list of filters to apply.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
suspend fun getSearchManga(
|
||||
override suspend fun getLatestUpdates(page: Int): MangasPage = fetchLatestUpdates(page).awaitSingle()
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
override suspend fun getSearchManga(
|
||||
page: Int,
|
||||
query: String,
|
||||
filters: FilterList,
|
||||
): MangasPage = fetchSearchManga(page, query, filters).awaitSingle()
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
override suspend fun getMangaUpdate(
|
||||
manga: SManga,
|
||||
chapters: List<SChapter>,
|
||||
fetchDetails: Boolean,
|
||||
fetchChapters: Boolean,
|
||||
): SMangaUpdate =
|
||||
supervisorScope {
|
||||
val asyncManga = if (fetchDetails) async { fetchMangaDetails(manga).awaitSingle() } else null
|
||||
val asyncChapters = if (fetchChapters) async { fetchChapterList(manga).awaitSingle() } else null
|
||||
SMangaUpdate(asyncManga?.await() ?: manga, asyncChapters?.await() ?: chapters)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
override suspend fun getPageList(chapter: SChapter): List<Page> = fetchPageList(chapter).awaitSingle()
|
||||
|
||||
/**
|
||||
* Get a page with a list of latest manga updates.
|
||||
* Returns an observable containing a page with a list of manga.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
suspend fun getLatestUpdates(page: Int): MangasPage = fetchLatestUpdates(page).awaitSingle()
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getPopularManga"))
|
||||
fun fetchPopularManga(page: Int): Observable<MangasPage> = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Returns the list of filters for the source.
|
||||
* Returns an observable containing a page with a list of manga.
|
||||
*
|
||||
* @param page the page number to retrieve.
|
||||
* @param query the search query.
|
||||
* @param filters the list of filters to apply.
|
||||
*/
|
||||
fun getFilterList(): FilterList
|
||||
|
||||
@Deprecated(
|
||||
"Use the non-RxJava API instead",
|
||||
ReplaceWith("getPopularManga"),
|
||||
)
|
||||
fun fetchPopularManga(page: Int): Observable<MangasPage> = throw IllegalStateException("Not used")
|
||||
|
||||
@Deprecated(
|
||||
"Use the non-RxJava API instead",
|
||||
ReplaceWith("getSearchManga"),
|
||||
)
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getSearchManga"))
|
||||
fun fetchSearchManga(
|
||||
page: Int,
|
||||
query: String,
|
||||
filters: FilterList,
|
||||
): Observable<MangasPage> = throw IllegalStateException("Not used")
|
||||
): Observable<MangasPage> = throw UnsupportedOperationException()
|
||||
|
||||
@Deprecated(
|
||||
"Use the non-RxJava API instead",
|
||||
ReplaceWith("getLatestUpdates"),
|
||||
)
|
||||
fun fetchLatestUpdates(page: Int): Observable<MangasPage> = throw IllegalStateException("Not used")
|
||||
/**
|
||||
* Returns an observable containing a page with a list of latest manga updates.
|
||||
*
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getLatestUpdates"))
|
||||
fun fetchLatestUpdates(page: Int): Observable<MangasPage> = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package eu.kanade.tachiyomi.source
|
||||
|
||||
@Suppress("unused")
|
||||
typealias PreferenceScreen = androidx.preference.PreferenceScreen
|
||||
@@ -1,10 +1,12 @@
|
||||
package eu.kanade.tachiyomi.source
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.SMangaUpdate
|
||||
import rx.Observable
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
|
||||
|
||||
/**
|
||||
* A basic interface for creating a source. It could be an online source, a local source, etc.
|
||||
@@ -24,53 +26,86 @@ interface Source {
|
||||
get() = ""
|
||||
|
||||
/**
|
||||
* Get the updated details for a manga.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
* @param manga the manga to update.
|
||||
* @return the updated manga.
|
||||
* Whether the source has support for latest updates.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
suspend fun getMangaDetails(manga: SManga): SManga = fetchMangaDetails(manga).awaitSingle()
|
||||
val supportsLatest: Boolean
|
||||
|
||||
/**
|
||||
* Get all the available chapters for a manga.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
* @param manga the manga to update.
|
||||
* @return the chapters for the manga.
|
||||
* Returns the list of filters for the source.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
suspend fun getChapterList(manga: SManga): List<SChapter> = fetchChapterList(manga).awaitSingle()
|
||||
fun getFilterList(): FilterList = FilterList()
|
||||
|
||||
/**
|
||||
* Get a page with a list of manga.
|
||||
*
|
||||
* @since tachiyomix 1.6
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
suspend fun getPopularManga(page: Int): MangasPage
|
||||
|
||||
/**
|
||||
* Get a page with a list of latest manga updates.
|
||||
*
|
||||
* @since tachiyomix 1.6
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
suspend fun getLatestUpdates(page: Int): MangasPage
|
||||
|
||||
/**
|
||||
* Get a page with a list of manga.
|
||||
*
|
||||
* @since tachiyomix 1.6
|
||||
* @param page the page number to retrieve.
|
||||
* @param query the search query.
|
||||
* @param filters the list of filters to apply.
|
||||
*/
|
||||
suspend fun getSearchManga(
|
||||
page: Int,
|
||||
query: String,
|
||||
filters: FilterList,
|
||||
): MangasPage
|
||||
|
||||
/**
|
||||
* Fetches updated information for a manga.
|
||||
*
|
||||
* Depending on the provided flags or source availability, this may include
|
||||
* updated manga metadata, available chapters, or both.
|
||||
*
|
||||
* If a value is not requested, the existing provided value can be returned as-is.
|
||||
* The host app may apply any returned updates regardless of the flags,
|
||||
* so care should be taken to only return accurate and intentional changes.
|
||||
*
|
||||
* @since tachiyomix 1.6
|
||||
* @param manga The manga to fetch updates for.
|
||||
* @param chapters Existing chapters of the manga
|
||||
* @param fetchDetails Whether to fetch updated manga details.
|
||||
* @param fetchChapters Whether to fetch available chapters.
|
||||
*/
|
||||
suspend fun getMangaUpdate(
|
||||
manga: SManga,
|
||||
chapters: List<SChapter>,
|
||||
fetchDetails: Boolean,
|
||||
fetchChapters: Boolean,
|
||||
): SMangaUpdate
|
||||
|
||||
/**
|
||||
* Get the list of pages a chapter has. Pages should be returned
|
||||
* in the expected order; the index is ignored.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
* @since tachiyomix 1.6
|
||||
* @param chapter the chapter.
|
||||
* @return the pages for the chapter.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
suspend fun getPageList(chapter: SChapter): List<Page> = fetchPageList(chapter).awaitSingle()
|
||||
suspend fun getPageList(chapter: SChapter): List<Page>
|
||||
|
||||
@Deprecated(
|
||||
"Use the non-RxJava API instead",
|
||||
ReplaceWith("getMangaDetails"),
|
||||
)
|
||||
fun fetchMangaDetails(manga: SManga): Observable<SManga> = throw IllegalStateException("Not used")
|
||||
@Deprecated("Use the combined suspend API instead", ReplaceWith("getMangaUpdate"))
|
||||
fun fetchMangaDetails(manga: SManga): Observable<SManga> = throw UnsupportedOperationException()
|
||||
|
||||
@Deprecated(
|
||||
"Use the non-RxJava API instead",
|
||||
ReplaceWith("getChapterList"),
|
||||
)
|
||||
fun fetchChapterList(manga: SManga): Observable<List<SChapter>> = throw IllegalStateException("Not used")
|
||||
@Deprecated("Use the combined suspend API instead", ReplaceWith("getMangaUpdate"))
|
||||
fun fetchChapterList(manga: SManga): Observable<List<SChapter>> = throw UnsupportedOperationException()
|
||||
|
||||
@Deprecated(
|
||||
"Use the non-RxJava API instead",
|
||||
ReplaceWith("getPageList"),
|
||||
)
|
||||
fun fetchPageList(chapter: SChapter): Observable<List<Page>> = throw IllegalStateException("Not used")
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getPageList"))
|
||||
fun fetchPageList(chapter: SChapter): Observable<List<Page>> = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
// fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this)
|
||||
|
||||
@@ -23,12 +23,15 @@ import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.SMangaUpdate
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
|
||||
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
||||
import eu.kanade.tachiyomi.util.storage.EpubFile
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
@@ -167,8 +170,20 @@ class LocalSource(
|
||||
return MangasPage(mangas.toList(), false)
|
||||
}
|
||||
|
||||
override suspend fun getMangaUpdate(
|
||||
manga: SManga,
|
||||
chapters: List<SChapter>,
|
||||
fetchDetails: Boolean,
|
||||
fetchChapters: Boolean,
|
||||
): SMangaUpdate =
|
||||
supervisorScope {
|
||||
val asyncManga = if (fetchDetails) async { getMangaDetails(manga) } else null
|
||||
val asyncChapters = if (fetchChapters) async { getChapterList(manga) } else null
|
||||
SMangaUpdate(asyncManga?.await() ?: manga, asyncChapters?.await() ?: chapters)
|
||||
}
|
||||
|
||||
// Manga details related
|
||||
override suspend fun getMangaDetails(manga: SManga): SManga =
|
||||
private suspend fun getMangaDetails(manga: SManga): SManga =
|
||||
withContext(Dispatchers.IO) {
|
||||
coverManager.find(manga.url)?.let {
|
||||
manga.thumbnail_url = it.absolutePath
|
||||
@@ -289,7 +304,7 @@ class LocalSource(
|
||||
}
|
||||
|
||||
// Chapters
|
||||
override suspend fun getChapterList(manga: SManga): List<SChapter> =
|
||||
private suspend fun getChapterList(manga: SManga): List<SChapter> =
|
||||
fileSystem
|
||||
.getFilesInMangaDirectory(manga.url)
|
||||
// Only keep supported formats
|
||||
@@ -467,7 +482,8 @@ class LocalSource(
|
||||
it[versionName] = "1.2"
|
||||
it[versionCode] = 0
|
||||
it[lang] = LANG
|
||||
it[isNsfw] = false
|
||||
it[extensionLib] = "1.2"
|
||||
it[contentWarning] = 0
|
||||
it[isInstalled] = true
|
||||
}
|
||||
|
||||
@@ -476,7 +492,6 @@ class LocalSource(
|
||||
it[name] = NAME
|
||||
it[lang] = LANG
|
||||
it[extension] = extensionId
|
||||
it[isNsfw] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
data class MangasPage(
|
||||
class MangasPage(
|
||||
val mangas: List<SManga>,
|
||||
val hasNextPage: Boolean,
|
||||
)
|
||||
) {
|
||||
@Deprecated("MangasPage is now a regular class")
|
||||
operator fun component1(): List<SManga> = mangas
|
||||
|
||||
@Deprecated("MangasPage is now a regular class")
|
||||
operator fun component2(): Boolean = hasNextPage
|
||||
|
||||
@Deprecated("MangasPage is now a regular class")
|
||||
fun copy(
|
||||
mangas: List<SManga> = this.mangas,
|
||||
hasNextPage: Boolean = this.hasNextPage,
|
||||
): MangasPage =
|
||||
MangasPage(
|
||||
mangas = mangas,
|
||||
hasNextPage = hasNextPage,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -27,12 +27,4 @@ open class Page(
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val QUEUE = 0
|
||||
const val LOAD_PAGE = 1
|
||||
const val DOWNLOAD_IMAGE = 2
|
||||
const val READY = 3
|
||||
const val ERROR = 4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import java.io.Serializable
|
||||
|
||||
interface SChapter : Serializable {
|
||||
@@ -9,12 +10,25 @@ interface SChapter : Serializable {
|
||||
|
||||
var name: String
|
||||
|
||||
var date_upload: Long
|
||||
|
||||
var chapter_number: Float
|
||||
|
||||
var scanlator: String?
|
||||
|
||||
var date_upload: Long
|
||||
|
||||
/**
|
||||
* Extra metadata associated with the chapter.
|
||||
*
|
||||
* The JSON object is not visible to users and intended for internal or source-specific
|
||||
* purposes. Apps may define their own namespaced keys (e.g., `"mihon.*"`) for sources to populate.
|
||||
*
|
||||
* This allows apps to attach and ask for custom information without affecting the visible
|
||||
* chapter data.
|
||||
*
|
||||
* @since tachiyomix 1.6
|
||||
*/
|
||||
var memo: JsonObject
|
||||
|
||||
fun copyFrom(other: SChapter) {
|
||||
name = other.name
|
||||
url = other.url
|
||||
|
||||
@@ -2,14 +2,19 @@
|
||||
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.EMPTY
|
||||
|
||||
class SChapterImpl : SChapter {
|
||||
override lateinit var url: String
|
||||
|
||||
override lateinit var name: String
|
||||
|
||||
override var date_upload: Long = 0
|
||||
|
||||
override var chapter_number: Float = -1f
|
||||
|
||||
override var scanlator: String? = null
|
||||
|
||||
override var date_upload: Long = 0
|
||||
|
||||
override var memo: JsonObject = JsonObject.EMPTY
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import java.io.Serializable
|
||||
|
||||
interface SManga : Serializable {
|
||||
@@ -9,22 +10,58 @@ interface SManga : Serializable {
|
||||
|
||||
var title: String
|
||||
|
||||
var thumbnail_url: String?
|
||||
|
||||
var artist: String?
|
||||
|
||||
var author: String?
|
||||
|
||||
var status: Int
|
||||
|
||||
var description: String?
|
||||
|
||||
var genre: String?
|
||||
|
||||
var status: Int
|
||||
|
||||
var thumbnail_url: String?
|
||||
|
||||
var update_strategy: UpdateStrategy
|
||||
|
||||
var initialized: Boolean
|
||||
|
||||
/**
|
||||
* Extra metadata associated with the manga.
|
||||
*
|
||||
* The JSON object is not visible to users and intended for internal or source-specific
|
||||
* purposes. Apps may define their own namespaced keys (e.g., `"mihon.*"`) for sources to populate.
|
||||
*
|
||||
* This allows apps to attach and ask for custom information without affecting the visible
|
||||
* manga data.
|
||||
*
|
||||
* @since tachiyomix 1.6
|
||||
*/
|
||||
var memo: JsonObject
|
||||
|
||||
fun getGenres(): List<String>? {
|
||||
if (genre.isNullOrBlank()) return null
|
||||
return genre
|
||||
?.split(", ")
|
||||
?.map { it.trim() }
|
||||
?.filterNot { it.isBlank() }
|
||||
?.distinct()
|
||||
}
|
||||
|
||||
fun copy() =
|
||||
create().also {
|
||||
it.url = url
|
||||
it.title = title
|
||||
it.artist = artist
|
||||
it.author = author
|
||||
it.description = description
|
||||
it.genre = genre
|
||||
it.status = status
|
||||
it.thumbnail_url = thumbnail_url
|
||||
it.update_strategy = update_strategy
|
||||
it.initialized = initialized
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val UNKNOWN = 0
|
||||
const val ONGOING = 1
|
||||
@@ -37,30 +74,3 @@ interface SManga : Serializable {
|
||||
fun create(): SManga = SMangaImpl()
|
||||
}
|
||||
}
|
||||
|
||||
// fun SManga.toMangaInfo(): MangaInfo {
|
||||
// return MangaInfo(
|
||||
// key = this.url,
|
||||
// title = this.title,
|
||||
// artist = this.artist ?: "",
|
||||
// author = this.author ?: "",
|
||||
// description = this.description ?: "",
|
||||
// genres = this.genre?.split(", ") ?: emptyList(),
|
||||
// status = this.status,
|
||||
// cover = this.thumbnail_url ?: ""
|
||||
// )
|
||||
// }
|
||||
//
|
||||
// fun MangaInfo.toSManga(): SManga {
|
||||
// val mangaInfo = this
|
||||
// return SManga.create().apply {
|
||||
// url = mangaInfo.key
|
||||
// title = mangaInfo.title
|
||||
// artist = mangaInfo.artist
|
||||
// author = mangaInfo.author
|
||||
// description = mangaInfo.description
|
||||
// genre = mangaInfo.genres.joinToString(", ")
|
||||
// status = mangaInfo.status
|
||||
// thumbnail_url = mangaInfo.cover
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -2,24 +2,29 @@
|
||||
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.EMPTY
|
||||
|
||||
class SMangaImpl : SManga {
|
||||
override lateinit var url: String
|
||||
|
||||
override lateinit var title: String
|
||||
|
||||
override var thumbnail_url: String? = null
|
||||
|
||||
override var artist: String? = null
|
||||
|
||||
override var author: String? = null
|
||||
|
||||
override var status: Int = 0
|
||||
|
||||
override var description: String? = null
|
||||
|
||||
override var genre: String? = null
|
||||
|
||||
override var status: Int = 0
|
||||
|
||||
override var thumbnail_url: String? = null
|
||||
|
||||
override var update_strategy: UpdateStrategy = UpdateStrategy.ALWAYS_UPDATE
|
||||
|
||||
override var initialized: Boolean = false
|
||||
|
||||
override var memo: JsonObject = JsonObject.EMPTY
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
@Suppress("UNUSED")
|
||||
class SMangaUpdate(
|
||||
val manga: SManga,
|
||||
val chapters: List<SChapter>,
|
||||
)
|
||||
@@ -1,6 +1,22 @@
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
/**
|
||||
* Define the update strategy for a single [SManga].
|
||||
* The strategy used will only take effect on the library update.
|
||||
*
|
||||
* @since extensions-lib 1.4
|
||||
*/
|
||||
enum class UpdateStrategy {
|
||||
/**
|
||||
* Series marked as always update will be included in the library
|
||||
* update if they aren't excluded by additional restrictions.
|
||||
*/
|
||||
ALWAYS_UPDATE,
|
||||
|
||||
/**
|
||||
* Series marked as only fetch once will be automatically skipped
|
||||
* during library updates. Useful for cases where the series is previously
|
||||
* known to be finished and have only a single chapter, for example.
|
||||
*/
|
||||
ONLY_FETCH_ONCE,
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.security.MessageDigest
|
||||
/**
|
||||
* A simple implementation for sources from a website.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
abstract class HttpSource : CatalogueSource {
|
||||
/**
|
||||
* Network service.
|
||||
@@ -37,11 +36,24 @@ abstract class HttpSource : CatalogueSource {
|
||||
*/
|
||||
abstract val baseUrl: String
|
||||
|
||||
/**
|
||||
* Returns the base (home) URL of the website as a string.
|
||||
*
|
||||
* This is typically the root address that serves as the main entry point
|
||||
* to the site's content, such as "https://mihon.tech".
|
||||
*
|
||||
* This method is used in the browse screen to determine the URL
|
||||
* opened when tapping "Open in WebView".
|
||||
*
|
||||
* @return The website’s home page URL. Defaults to [baseUrl].
|
||||
*/
|
||||
open fun getHomeUrl(): String = baseUrl
|
||||
|
||||
/**
|
||||
* Version id used to generate the source id. If the site completely changes and urls are
|
||||
* incompatible, you may increase this value and it'll be considered as a new source.
|
||||
*/
|
||||
open val versionId = 1
|
||||
open val versionId: Int = 1
|
||||
|
||||
/**
|
||||
* ID of the source. By default it uses a generated id using the first 16 characters (64 bits)
|
||||
@@ -53,7 +65,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* Note: the generated ID sets the sign bit to `0`.
|
||||
*/
|
||||
override val id by lazy { generateId() }
|
||||
override val id: Long by lazy { generateId(name, lang, versionId) }
|
||||
|
||||
/**
|
||||
* Headers used for requests.
|
||||
@@ -63,10 +75,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
/**
|
||||
* Default network client for doing requests.
|
||||
*/
|
||||
open val client: OkHttpClient
|
||||
get() = network.client
|
||||
|
||||
private fun generateId(): Long = generateId("${name.lowercase()}/$lang/$versionId")
|
||||
open val client: OkHttpClient get() = network.client
|
||||
|
||||
/**
|
||||
* Generates a unique ID for the source based on the provided [name], [lang] and
|
||||
@@ -91,10 +100,6 @@ abstract class HttpSource : CatalogueSource {
|
||||
versionId: Int,
|
||||
): Long {
|
||||
val key = "${name.lowercase()}/$lang/$versionId"
|
||||
return generateId(key)
|
||||
}
|
||||
|
||||
private fun generateId(key: String): Long {
|
||||
val bytes = MessageDigest.getInstance("MD5").digest(key.toByteArray())
|
||||
return (0..7).map { bytes[it].toLong() and 0xff shl 8 * (7 - it) }.reduce(Long::or) and Long.MAX_VALUE
|
||||
}
|
||||
@@ -102,7 +107,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
/**
|
||||
* Headers builder for requests. Implementations can override this method for custom headers.
|
||||
*/
|
||||
protected open fun headersBuilder() =
|
||||
protected open fun headersBuilder(): Headers.Builder =
|
||||
Headers.Builder().apply {
|
||||
add("User-Agent", network.defaultUserAgentProvider())
|
||||
}
|
||||
@@ -110,7 +115,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
/**
|
||||
* Visible name of the source.
|
||||
*/
|
||||
override fun toString() = "$name (${lang.uppercase()})"
|
||||
override fun toString(): String = "$name (${lang.uppercase()})"
|
||||
|
||||
/**
|
||||
* Returns an observable containing a page with a list of manga. Normally it's not needed to
|
||||
@@ -118,7 +123,8 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getPopularManga"))
|
||||
@Suppress("DEPRECATION")
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getPopularManga"))
|
||||
override fun fetchPopularManga(page: Int): Observable<MangasPage> =
|
||||
client
|
||||
.newCall(popularMangaRequest(page))
|
||||
@@ -132,14 +138,24 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
protected abstract fun popularMangaRequest(page: Int): Request
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun popularMangaRequest(page: Int): Request = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Parses the response from the site and returns a [MangasPage] object.
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
protected abstract fun popularMangaParse(response: Response): MangasPage
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun popularMangaParse(response: Response): MangasPage = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Returns an observable containing a page with a list of manga. Normally it's not needed to
|
||||
@@ -149,22 +165,17 @@ abstract class HttpSource : CatalogueSource {
|
||||
* @param query the search query.
|
||||
* @param filters the list of filters to apply.
|
||||
*/
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getSearchManga"))
|
||||
@Suppress("DEPRECATION")
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getSearchManga"))
|
||||
override fun fetchSearchManga(
|
||||
page: Int,
|
||||
query: String,
|
||||
filters: FilterList,
|
||||
): Observable<MangasPage> =
|
||||
Observable
|
||||
.defer {
|
||||
try {
|
||||
client.newCall(searchMangaRequest(page, query, filters)).asObservableSuccess()
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
// RxJava doesn't handle Errors, which tends to happen during global searches
|
||||
// if an old extension using non-existent classes is still around
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
}.map { response ->
|
||||
client
|
||||
.newCall(searchMangaRequest(page, query, filters))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchMangaParse(response)
|
||||
}
|
||||
|
||||
@@ -175,25 +186,36 @@ abstract class HttpSource : CatalogueSource {
|
||||
* @param query the search query.
|
||||
* @param filters the list of filters to apply.
|
||||
*/
|
||||
protected abstract fun searchMangaRequest(
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun searchMangaRequest(
|
||||
page: Int,
|
||||
query: String,
|
||||
filters: FilterList,
|
||||
): Request
|
||||
): Request = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Parses the response from the site and returns a [MangasPage] object.
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
protected abstract fun searchMangaParse(response: Response): MangasPage
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun searchMangaParse(response: Response): MangasPage = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Returns an observable containing a page with a list of latest manga updates.
|
||||
*
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getLatestUpdates"))
|
||||
@Suppress("DEPRECATION")
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getLatestUpdates"))
|
||||
override fun fetchLatestUpdates(page: Int): Observable<MangasPage> =
|
||||
client
|
||||
.newCall(latestUpdatesRequest(page))
|
||||
@@ -207,26 +229,33 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param page the page number to retrieve.
|
||||
*/
|
||||
protected abstract fun latestUpdatesRequest(page: Int): Request
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun latestUpdatesRequest(page: Int): Request = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Parses the response from the site and returns a [MangasPage] object.
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
protected abstract fun latestUpdatesParse(response: Response): MangasPage
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun latestUpdatesParse(response: Response): MangasPage = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Get the updated details for a manga.
|
||||
* Normally it's not needed to override this method.
|
||||
* Returns an observable with the updated details for a manga. Normally it's not needed to
|
||||
* override this method.
|
||||
*
|
||||
* @param manga the manga to update.
|
||||
* @return the updated manga.
|
||||
* @param manga the manga to be updated.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
override suspend fun getMangaDetails(manga: SManga): SManga = fetchMangaDetails(manga).awaitSingle()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getMangaDetails"))
|
||||
@Deprecated("Use the combined suspend API instead", replaceWith = ReplaceWith("getMangaUpdate"))
|
||||
override fun fetchMangaDetails(manga: SManga): Observable<SManga> =
|
||||
client
|
||||
.newCall(mangaDetailsRequest(manga))
|
||||
@@ -241,6 +270,11 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param manga the manga to be updated.
|
||||
*/
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
open fun mangaDetailsRequest(manga: SManga): Request = GET(baseUrl + manga.url, headers)
|
||||
|
||||
/**
|
||||
@@ -248,37 +282,28 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
protected abstract fun mangaDetailsParse(response: Response): SManga
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun mangaDetailsParse(response: Response): SManga = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Get all the available chapters for a manga.
|
||||
* Normally it's not needed to override this method.
|
||||
* Returns an observable with the updated chapter list for a manga. Normally it's not needed to
|
||||
* override this method.
|
||||
*
|
||||
* @param manga the manga to update.
|
||||
* @return the chapters for the manga.
|
||||
* @throws LicensedMangaChaptersException if a manga is licensed and therefore no chapters are available.
|
||||
* @param manga the manga to look for chapters.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
override suspend fun getChapterList(manga: SManga): List<SChapter> {
|
||||
if (manga.status == SManga.LICENSED) {
|
||||
throw LicensedMangaChaptersException()
|
||||
}
|
||||
|
||||
return fetchChapterList(manga).awaitSingle()
|
||||
}
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getChapterList"))
|
||||
@Deprecated("Use the combined suspend API instead", replaceWith = ReplaceWith("getMangaUpdate"))
|
||||
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> =
|
||||
if (manga.status != SManga.LICENSED) {
|
||||
client
|
||||
.newCall(chapterListRequest(manga))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
chapterListParse(response)
|
||||
}
|
||||
} else {
|
||||
Observable.error(LicensedMangaChaptersException())
|
||||
}
|
||||
client
|
||||
.newCall(chapterListRequest(manga))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
chapterListParse(response)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request for updating the chapter list. Override only if it's needed to override
|
||||
@@ -286,6 +311,11 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param manga the manga to look for chapters.
|
||||
*/
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun chapterListRequest(manga: SManga): Request = GET(baseUrl + manga.url, headers)
|
||||
|
||||
/**
|
||||
@@ -293,19 +323,20 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
protected abstract fun chapterListParse(response: Response): List<SChapter>
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun chapterListParse(response: Response): List<SChapter> = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Get the list of pages a chapter has. Pages should be returned
|
||||
* in the expected order; the index is ignored.
|
||||
* Returns an observable with the page list for a chapter.
|
||||
*
|
||||
* @param chapter the chapter.
|
||||
* @return the pages for the chapter.
|
||||
* @param chapter the chapter whose page list has to be fetched.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
override suspend fun getPageList(chapter: SChapter): List<Page> = fetchPageList(chapter).awaitSingle()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getPageList"))
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getPageList"))
|
||||
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> =
|
||||
client
|
||||
.newCall(pageListRequest(chapter))
|
||||
@@ -320,6 +351,11 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param chapter the chapter whose page list has to be fetched.
|
||||
*/
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun pageListRequest(chapter: SChapter): Request = GET(baseUrl + chapter.url, headers)
|
||||
|
||||
/**
|
||||
@@ -327,31 +363,47 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
protected abstract fun pageListParse(response: Response): List<Page>
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun pageListParse(response: Response): List<Page> = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Returns an observable with the page containing the source url of the image. If there's any
|
||||
* error, it will return null instead of throwing an exception.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
* @param page the page whose source image has to be fetched.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
open suspend fun getImageUrl(page: Page): String = fetchImageUrl(page).awaitSingle()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getImageUrl"))
|
||||
@Deprecated("Use the suspend API instead", ReplaceWith("getImageUrl"))
|
||||
open fun fetchImageUrl(page: Page): Observable<String> =
|
||||
client
|
||||
.newCall(imageUrlRequest(page))
|
||||
.asObservableSuccess()
|
||||
.map { imageUrlParse(it) }
|
||||
|
||||
/**
|
||||
* Returns the image url for the provided [page]. The function is only called if [Page.imageUrl] is null.
|
||||
*
|
||||
* @since tachiyomix 1.6
|
||||
* @param page the page whose source image has to be fetched.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
open suspend fun getImageUrl(page: Page): String = fetchImageUrl(page).awaitSingle()
|
||||
|
||||
/**
|
||||
* Returns the request for getting the url to the source image. Override only if it's needed to
|
||||
* override the url, send different headers or request method like POST.
|
||||
*
|
||||
* @param page the chapter whose page list has to be fetched
|
||||
*/
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun imageUrlRequest(page: Page): Request = GET(page.url, headers)
|
||||
|
||||
/**
|
||||
@@ -359,16 +411,14 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
protected abstract fun imageUrlParse(response: Response): String
|
||||
@Deprecated(
|
||||
message =
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
protected open fun imageUrlParse(response: Response): String = throw UnsupportedOperationException()
|
||||
|
||||
/**
|
||||
* Returns the response of the source image.
|
||||
* Typically does not need to be overridden.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
* @param page the page whose source image has to be downloaded.
|
||||
*/
|
||||
open suspend fun getImage(page: Page): Response =
|
||||
suspend fun getImage(page: Page): Response =
|
||||
client
|
||||
.newCachelessCallWithProgress(imageRequest(page), page)
|
||||
.awaitSuccess()
|
||||
@@ -387,6 +437,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param url the full url to the chapter.
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
fun SChapter.setUrlWithoutDomain(url: String) {
|
||||
this.url = getUrlWithoutDomain(url)
|
||||
}
|
||||
@@ -397,6 +448,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
*
|
||||
* @param url the full url to the manga.
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
fun SManga.setUrlWithoutDomain(url: String) {
|
||||
this.url = getUrlWithoutDomain(url)
|
||||
}
|
||||
@@ -417,7 +469,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
out += "#" + uri.fragment
|
||||
}
|
||||
out
|
||||
} catch (e: URISyntaxException) {
|
||||
} catch (_: URISyntaxException) {
|
||||
orig
|
||||
}
|
||||
|
||||
@@ -428,6 +480,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
* @param manga the manga
|
||||
* @return url of the manga
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
open fun getMangaUrl(manga: SManga): String = mangaDetailsRequest(manga).url.toString()
|
||||
|
||||
/**
|
||||
@@ -437,6 +490,7 @@ abstract class HttpSource : CatalogueSource {
|
||||
* @param chapter the chapter
|
||||
* @return url of the chapter
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
open fun getChapterUrl(chapter: SChapter): String = pageListRequest(chapter).url.toString()
|
||||
|
||||
/**
|
||||
@@ -446,15 +500,9 @@ abstract class HttpSource : CatalogueSource {
|
||||
* @param chapter the chapter to be added.
|
||||
* @param manga the manga of the chapter.
|
||||
*/
|
||||
@Deprecated("All modifications should be done when constructing the chapter")
|
||||
open fun prepareNewChapter(
|
||||
chapter: SChapter,
|
||||
manga: SManga,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Returns the list of filters for the source.
|
||||
*/
|
||||
override fun getFilterList() = FilterList()
|
||||
}
|
||||
|
||||
class LicensedMangaChaptersException : Exception("Licensed - No chapters to show")
|
||||
|
||||
@@ -12,12 +12,20 @@ import org.jsoup.nodes.Element
|
||||
/**
|
||||
* A simple implementation for sources from a website using Jsoup, an HTML parser.
|
||||
*/
|
||||
@Deprecated(
|
||||
message =
|
||||
"In most cases sources only require a subset of the methods from this class. " +
|
||||
"Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
abstract class ParsedHttpSource : HttpSource() {
|
||||
/**
|
||||
* Parses the response from the site and returns a [MangasPage] object.
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
@Deprecated(
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
override fun popularMangaParse(response: Response): MangasPage {
|
||||
val document = response.asJsoup()
|
||||
|
||||
@@ -58,6 +66,9 @@ abstract class ParsedHttpSource : HttpSource() {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
@Deprecated(
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
override fun searchMangaParse(response: Response): MangasPage {
|
||||
val document = response.asJsoup()
|
||||
|
||||
@@ -98,6 +109,9 @@ abstract class ParsedHttpSource : HttpSource() {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
@Deprecated(
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
override fun latestUpdatesParse(response: Response): MangasPage {
|
||||
val document = response.asJsoup()
|
||||
|
||||
@@ -138,6 +152,9 @@ abstract class ParsedHttpSource : HttpSource() {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
@Deprecated(
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
override fun mangaDetailsParse(response: Response): SManga = mangaDetailsParse(response.asJsoup())
|
||||
|
||||
/**
|
||||
@@ -152,6 +169,9 @@ abstract class ParsedHttpSource : HttpSource() {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
@Deprecated(
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
override fun chapterListParse(response: Response): List<SChapter> {
|
||||
val document = response.asJsoup()
|
||||
return document.select(chapterListSelector()).map { chapterFromElement(it) }
|
||||
@@ -174,6 +194,9 @@ abstract class ParsedHttpSource : HttpSource() {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
@Deprecated(
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
override fun pageListParse(response: Response): List<Page> = pageListParse(response.asJsoup())
|
||||
|
||||
/**
|
||||
@@ -188,6 +211,9 @@ abstract class ParsedHttpSource : HttpSource() {
|
||||
*
|
||||
* @param response the response from the site.
|
||||
*/
|
||||
@Deprecated(
|
||||
"The helper functions are inherently limiting and hides the underlying implementation. Source developers should make their own implementation according to their needs.",
|
||||
)
|
||||
override fun imageUrlParse(response: Response): String = imageUrlParse(response.asJsoup())
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,26 +1,44 @@
|
||||
package eu.kanade.tachiyomi.source.online
|
||||
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
|
||||
/**
|
||||
* A source that may handle opening an SManga for a given URI.
|
||||
* A source that may handle opening an SManga or SChapter for a given URI.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
*/
|
||||
@Suppress("unused")
|
||||
interface ResolvableSource : Source {
|
||||
/**
|
||||
* Whether this source may potentially handle the given URI.
|
||||
* Returns what the given URI may open.
|
||||
* Returns [UriType.Unknown] if the source is not able to resolve the URI.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
*/
|
||||
fun canResolveUri(uri: String): Boolean
|
||||
fun getUriType(uri: String): UriType
|
||||
|
||||
/**
|
||||
* Called if canHandleUri is true. Returns the corresponding SManga, if possible.
|
||||
* Called if [getUriType] is [UriType.Manga].
|
||||
* Returns the corresponding SManga, if possible.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
*/
|
||||
suspend fun getManga(uri: String): SManga?
|
||||
|
||||
/**
|
||||
* Called if [getUriType] is [UriType.Chapter].
|
||||
* Returns the corresponding SChapter, if possible.
|
||||
*
|
||||
* @since extensions-lib 1.5
|
||||
*/
|
||||
suspend fun getChapter(uri: String): SChapter?
|
||||
}
|
||||
|
||||
sealed interface UriType {
|
||||
data object Manga : UriType
|
||||
|
||||
data object Chapter : UriType
|
||||
|
||||
data object Unknown : UriType
|
||||
}
|
||||
|
||||
@@ -4,11 +4,15 @@ import android.app.Application
|
||||
import android.content.Context
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.network.PUT
|
||||
import eu.kanade.tachiyomi.network.await
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.javalin.http.HttpStatus
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.SerializationException
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
@@ -36,31 +40,66 @@ object SyncYomiSyncService {
|
||||
message: String?,
|
||||
) : Exception(message)
|
||||
|
||||
@Serializable
|
||||
private data class SyncEvent(
|
||||
val event: SyncEventStatus,
|
||||
val device_Name: String? = null,
|
||||
val message: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
private enum class SyncEventStatus {
|
||||
SYNC_STARTED,
|
||||
SYNC_SUCCESS,
|
||||
SYNC_FAILED,
|
||||
SYNC_ERROR,
|
||||
SYNC_CANCELLED,
|
||||
}
|
||||
|
||||
suspend fun doSync(
|
||||
syncData: SyncData,
|
||||
startDate: Instant,
|
||||
setSyncState: (SyncManager.SyncState) -> Unit,
|
||||
): Backup? {
|
||||
reportSyncEvent(SyncEventStatus.SYNC_STARTED)
|
||||
setSyncState(SyncManager.SyncState.Downloading(startDate))
|
||||
val (remoteData, etag) = pullSyncData()
|
||||
|
||||
val finalSyncData =
|
||||
if (remoteData != null) {
|
||||
require(etag.isNotEmpty()) { "ETag should never be empty if remote data is not null" }
|
||||
logger.debug { "Try update remote data with ETag($etag)" }
|
||||
setSyncState(SyncManager.SyncState.Merging(startDate))
|
||||
mergeSyncData(syncData, remoteData)
|
||||
} else {
|
||||
// init or overwrite remote data
|
||||
logger.debug { "Try overwrite remote data with ETag($etag)" }
|
||||
syncData
|
||||
return try {
|
||||
val (remoteData, etag) = pullSyncData()
|
||||
|
||||
val finalSyncData =
|
||||
if (remoteData != null) {
|
||||
require(etag.isNotEmpty()) { "ETag should never be empty if remote data is not null" }
|
||||
logger.debug { "Try update remote data with ETag($etag)" }
|
||||
setSyncState(SyncManager.SyncState.Merging(startDate))
|
||||
mergeSyncData(syncData, remoteData)
|
||||
} else {
|
||||
// init or overwrite remote data
|
||||
logger.debug { "Try overwrite remote data with ETag($etag)" }
|
||||
syncData
|
||||
}
|
||||
|
||||
if (finalSyncData.backup != null) {
|
||||
setSyncState(SyncManager.SyncState.Uploading(startDate))
|
||||
}
|
||||
|
||||
if (finalSyncData.backup != null) {
|
||||
setSyncState(SyncManager.SyncState.Uploading(startDate))
|
||||
val success = pushSyncData(finalSyncData, etag)
|
||||
if (success) {
|
||||
reportSyncEvent(SyncEventStatus.SYNC_SUCCESS)
|
||||
} else {
|
||||
reportSyncEvent(SyncEventStatus.SYNC_FAILED, "Failed to push sync data")
|
||||
}
|
||||
|
||||
finalSyncData.backup
|
||||
} catch (e: Exception) {
|
||||
if (e is CancellationException) {
|
||||
reportSyncEvent(SyncEventStatus.SYNC_CANCELLED, e.message)
|
||||
throw e
|
||||
}
|
||||
logger.error { "Error syncing: ${e.message}" }
|
||||
reportSyncEvent(SyncEventStatus.SYNC_ERROR, e.message)
|
||||
throw e
|
||||
}
|
||||
pushSyncData(finalSyncData, etag)
|
||||
return finalSyncData.backup
|
||||
}
|
||||
|
||||
private suspend fun pullSyncData(): Pair<SyncData?, String> {
|
||||
@@ -122,8 +161,8 @@ object SyncYomiSyncService {
|
||||
private suspend fun pushSyncData(
|
||||
syncData: SyncData,
|
||||
eTag: String,
|
||||
) {
|
||||
val backup = syncData.backup ?: return
|
||||
): Boolean {
|
||||
val backup = syncData.backup ?: return true
|
||||
|
||||
val host = serverConfig.syncYomiHost.value
|
||||
val apiKey = serverConfig.syncYomiApiKey.value
|
||||
@@ -160,7 +199,7 @@ object SyncYomiSyncService {
|
||||
|
||||
val response = client.newCall(uploadRequest).await()
|
||||
|
||||
if (response.isSuccessful) {
|
||||
return if (response.isSuccessful) {
|
||||
val newETag =
|
||||
response.headers["ETag"]
|
||||
?.takeIf { it.isNotEmpty() } ?: throw SyncYomiException("Missing ETag")
|
||||
@@ -169,12 +208,53 @@ object SyncYomiSyncService {
|
||||
.putString("last_sync_etag", newETag)
|
||||
.apply()
|
||||
logger.debug { "SyncYomi sync completed" }
|
||||
true
|
||||
} else if (response.code == HttpStatus.PRECONDITION_FAILED.code) {
|
||||
// other clients updated remote data, will try next time
|
||||
logger.debug { "SyncYomi sync failed with 412" }
|
||||
false
|
||||
} else {
|
||||
val responseBody = response.body.string()
|
||||
logger.error { "SyncError: $responseBody" }
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun reportSyncEvent(
|
||||
event: SyncEventStatus,
|
||||
message: String? = null,
|
||||
) {
|
||||
try {
|
||||
val host = serverConfig.syncYomiHost.value
|
||||
val apiKey = serverConfig.syncYomiApiKey.value
|
||||
val url = "$host/api/sync/event"
|
||||
|
||||
val headers = Headers.Builder().add("X-API-Token", apiKey).build()
|
||||
|
||||
// Use a fixed server name.
|
||||
val bodyObj =
|
||||
SyncEvent(
|
||||
event = event,
|
||||
device_Name = "Suwayomi Server",
|
||||
message = message,
|
||||
)
|
||||
|
||||
val jsonBody = Json.encodeToString(SyncEvent.serializer(), bodyObj)
|
||||
val requestBody = jsonBody.toRequestBody("application/json; charset=utf-8".toMediaType())
|
||||
|
||||
val request =
|
||||
POST(
|
||||
url = url,
|
||||
headers = headers,
|
||||
body = requestBody,
|
||||
)
|
||||
|
||||
network.client
|
||||
.newCall(request)
|
||||
.await()
|
||||
.close()
|
||||
} catch (e: Exception) {
|
||||
logger.error { "Failed to report sync event: ${e.message}" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,7 +457,7 @@ object SyncYomiSyncService {
|
||||
// Use version number to decide which chapter to keep
|
||||
val chosenChapter =
|
||||
if (localChapter.version >= remoteChapter.version) {
|
||||
// If there mare more chapter on remote, local sourceOrder will need to be updated to maintain correct source order.
|
||||
// If there are more chapter on remote, local sourceOrder will need to be updated to maintain correct source order.
|
||||
if (localChapters.size < remoteChapters.size) {
|
||||
localChapter.copy(sourceOrder = remoteChapter.sourceOrder)
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package suwayomi.tachidesk.graphql.dataLoaders
|
||||
|
||||
import com.expediagroup.graphql.dataloader.KotlinDataLoader
|
||||
import graphql.GraphQLContext
|
||||
import org.dataloader.DataLoader
|
||||
import org.dataloader.DataLoaderFactory
|
||||
import org.jetbrains.exposed.v1.core.Slf4jSqlDebugLogger
|
||||
import org.jetbrains.exposed.v1.core.inList
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionNodeList
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionNodeList.Companion.toNodeList
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionStoreType
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionType
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionStoreTable
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionTable
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
|
||||
class ExtensionStoreDataLoader : KotlinDataLoader<String, ExtensionStoreType> {
|
||||
override val dataLoaderName = "ExtensionStoreDataLoader"
|
||||
|
||||
override fun getDataLoader(graphQLContext: GraphQLContext): DataLoader<String, ExtensionStoreType> =
|
||||
DataLoaderFactory.newDataLoader { ids ->
|
||||
future {
|
||||
transaction {
|
||||
addLogger(Slf4jSqlDebugLogger)
|
||||
val extensionStoreByIndexUrl =
|
||||
ExtensionStoreTable
|
||||
.selectAll()
|
||||
.where { ExtensionStoreTable.indexUrl inList ids }
|
||||
.map { ExtensionStoreType(it) }
|
||||
.associateBy { it.indexUrl }
|
||||
ids.map { extensionStoreByIndexUrl[it] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ExtensionsForExtensionStore : KotlinDataLoader<String, ExtensionNodeList> {
|
||||
override val dataLoaderName = "ExtensionsForExtensionStore"
|
||||
|
||||
override fun getDataLoader(graphQLContext: GraphQLContext): DataLoader<String, ExtensionNodeList> =
|
||||
DataLoaderFactory.newDataLoader<String, ExtensionNodeList> { ids ->
|
||||
future {
|
||||
transaction {
|
||||
addLogger(Slf4jSqlDebugLogger)
|
||||
val extensionByIndexUrl =
|
||||
ExtensionTable
|
||||
.selectAll()
|
||||
.where { ExtensionTable.storeIndexUrl inList ids }
|
||||
.map { ExtensionType(it) }
|
||||
.groupBy { it.storeIndexUrl }
|
||||
ids.map { (extensionByIndexUrl[it] ?: emptyList()).toNodeList() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jetbrains.exposed.v1.core.LikePattern
|
||||
@@ -25,6 +26,7 @@ import suwayomi.tachidesk.graphql.types.ChapterType
|
||||
import suwayomi.tachidesk.graphql.types.MetaInput
|
||||
import suwayomi.tachidesk.graphql.types.SyncConflictInfoType
|
||||
import suwayomi.tachidesk.manga.impl.Chapter
|
||||
import suwayomi.tachidesk.manga.impl.Manga
|
||||
import suwayomi.tachidesk.manga.impl.chapter.getChapterDownloadReadyById
|
||||
import suwayomi.tachidesk.manga.impl.sync.KoreaderSyncService
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterMetaTable
|
||||
@@ -167,11 +169,12 @@ class ChapterMutation {
|
||||
)
|
||||
|
||||
@RequireAuth
|
||||
@GraphQLDeprecated("Deprecated in Tachiyomix 1.6", ReplaceWith("fetchMangaAndChapters"))
|
||||
fun fetchChapters(input: FetchChaptersInput): CompletableFuture<FetchChaptersPayload?> {
|
||||
val (clientMutationId, mangaId) = input
|
||||
|
||||
return future {
|
||||
Chapter.fetchChapterList(mangaId)
|
||||
Manga.updateMangaAndChapters(mangaId, updateManga = false)
|
||||
|
||||
val chapters =
|
||||
transaction {
|
||||
|
||||
@@ -10,9 +10,11 @@ import org.jetbrains.exposed.v1.core.neq
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionStoreType
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionType
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension
|
||||
import suwayomi.tachidesk.manga.impl.extension.ExtensionsList
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionStoreTable
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionTable
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import java.util.concurrent.CompletableFuture
|
||||
@@ -129,6 +131,7 @@ class ExtensionMutation {
|
||||
data class FetchExtensionsPayload(
|
||||
val clientMutationId: String?,
|
||||
val extensions: List<ExtensionType>,
|
||||
val extensionStores: List<ExtensionStoreType>,
|
||||
)
|
||||
|
||||
@RequireAuth
|
||||
@@ -146,9 +149,17 @@ class ExtensionMutation {
|
||||
.map { ExtensionType(it) }
|
||||
}
|
||||
|
||||
val extensionStores =
|
||||
transaction {
|
||||
ExtensionStoreTable
|
||||
.selectAll()
|
||||
.map { ExtensionStoreType(it) }
|
||||
}
|
||||
|
||||
FetchExtensionsPayload(
|
||||
clientMutationId = clientMutationId,
|
||||
extensions = extensions,
|
||||
extensionStores = extensionStores,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.jdbc.deleteWhere
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionStoreType
|
||||
import suwayomi.tachidesk.manga.impl.extension.ExtensionStoreService
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionStoreTable
|
||||
import suwayomi.tachidesk.server.JavalinSetup.future
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class ExtensionStoreMutation {
|
||||
data class AddExtensionStoreInput(
|
||||
val clientMutationId: String? = null,
|
||||
val indexUrl: String,
|
||||
)
|
||||
|
||||
data class AddExtensionStorePayload(
|
||||
val clientMutationId: String?,
|
||||
val extensionStore: ExtensionStoreType,
|
||||
)
|
||||
|
||||
@RequireAuth
|
||||
fun addExtensionStore(input: AddExtensionStoreInput): CompletableFuture<AddExtensionStorePayload?> {
|
||||
val (clientMutationId, indexUrl) = input
|
||||
return future {
|
||||
val store = ExtensionStoreService.fetch(indexUrl)
|
||||
|
||||
ExtensionStoreService.upsert(store)
|
||||
ExtensionStoreService.syncDbToPrefs()
|
||||
val row =
|
||||
transaction {
|
||||
ExtensionStoreTable
|
||||
.selectAll()
|
||||
.where { ExtensionStoreTable.indexUrl eq store.indexUrl }
|
||||
.first()
|
||||
}
|
||||
|
||||
AddExtensionStorePayload(
|
||||
clientMutationId = clientMutationId,
|
||||
extensionStore = ExtensionStoreType(row),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class RemoveExtensionStoreInput(
|
||||
val clientMutationId: String? = null,
|
||||
val indexUrl: String,
|
||||
)
|
||||
|
||||
data class RemoveExtensionStorePayload(
|
||||
val clientMutationId: String?,
|
||||
val extensionStore: ExtensionStoreType?,
|
||||
)
|
||||
|
||||
@RequireAuth
|
||||
fun removeExtensionStore(input: RemoveExtensionStoreInput): CompletableFuture<RemoveExtensionStorePayload?> {
|
||||
val (clientMutationId, indexUrl) = input
|
||||
return future {
|
||||
val store =
|
||||
transaction {
|
||||
ExtensionStoreTable
|
||||
.selectAll()
|
||||
.where { ExtensionStoreTable.indexUrl eq indexUrl }
|
||||
.firstOrNull()
|
||||
?.let { ExtensionStoreType(it) }
|
||||
}
|
||||
|
||||
store?.let {
|
||||
transaction {
|
||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq indexUrl }
|
||||
}
|
||||
}
|
||||
|
||||
ExtensionStoreService.syncDbToPrefs()
|
||||
|
||||
RemoveExtensionStorePayload(
|
||||
clientMutationId = clientMutationId,
|
||||
extensionStore =
|
||||
store?.let {
|
||||
ExtensionStoreType(
|
||||
name = it.name,
|
||||
badgeLabel = it.badgeLabel,
|
||||
signingKey = it.signingKey,
|
||||
contactWebsite = it.contactWebsite,
|
||||
contactDiscord = it.contactDiscord,
|
||||
indexUrl = it.indexUrl,
|
||||
isLegacy = it.isLegacy,
|
||||
extensionListUrl = it.extensionListUrl,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||
import org.jetbrains.exposed.v1.core.LikePattern
|
||||
import org.jetbrains.exposed.v1.core.Op
|
||||
import org.jetbrains.exposed.v1.core.and
|
||||
@@ -14,12 +15,14 @@ import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import org.jetbrains.exposed.v1.jdbc.update
|
||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||
import suwayomi.tachidesk.graphql.types.ChapterType
|
||||
import suwayomi.tachidesk.graphql.types.MangaMetaType
|
||||
import suwayomi.tachidesk.graphql.types.MangaType
|
||||
import suwayomi.tachidesk.graphql.types.MetaInput
|
||||
import suwayomi.tachidesk.manga.impl.Library
|
||||
import suwayomi.tachidesk.manga.impl.Manga
|
||||
import suwayomi.tachidesk.manga.impl.update.IUpdater
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
@@ -146,11 +149,12 @@ class MangaMutation {
|
||||
)
|
||||
|
||||
@RequireAuth
|
||||
@GraphQLDeprecated("Deprecated in Tachiyomix 1.6", ReplaceWith("fetchMangaAndChapters"))
|
||||
fun fetchManga(input: FetchMangaInput): CompletableFuture<FetchMangaPayload?> {
|
||||
val (clientMutationId, id) = input
|
||||
|
||||
return future {
|
||||
Manga.fetchManga(id)
|
||||
Manga.updateMangaAndChapters(id, updateChapters = false)
|
||||
|
||||
val manga =
|
||||
transaction {
|
||||
@@ -163,6 +167,49 @@ class MangaMutation {
|
||||
}
|
||||
}
|
||||
|
||||
data class FetchMangaAndChaptersInput(
|
||||
val clientMutationId: String? = null,
|
||||
val id: Int,
|
||||
val fetchManga: Boolean,
|
||||
val fetchChapters: Boolean,
|
||||
)
|
||||
|
||||
data class FetchMangaAndChaptersPayload(
|
||||
val clientMutationId: String?,
|
||||
val manga: MangaType,
|
||||
val chapters: List<ChapterType>,
|
||||
)
|
||||
|
||||
@RequireAuth
|
||||
fun fetchMangaAndChapters(input: FetchMangaAndChaptersInput): CompletableFuture<FetchMangaAndChaptersPayload?> {
|
||||
val (clientMutationId, id, fetchManga, fetchChapters) = input
|
||||
|
||||
return future {
|
||||
Manga.updateMangaAndChapters(
|
||||
mangaId = id,
|
||||
updateManga = fetchManga,
|
||||
updateChapters = fetchChapters,
|
||||
)
|
||||
|
||||
val (manga, chapters) =
|
||||
transaction {
|
||||
Pair(
|
||||
MangaTable.selectAll().where { MangaTable.id eq id }.first(),
|
||||
ChapterTable
|
||||
.selectAll()
|
||||
.where { ChapterTable.manga eq id }
|
||||
.orderBy(ChapterTable.sourceOrder)
|
||||
.map { ChapterType(it) },
|
||||
)
|
||||
}
|
||||
FetchMangaAndChaptersPayload(
|
||||
clientMutationId = clientMutationId,
|
||||
manga = MangaType(manga),
|
||||
chapters = chapters,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class SetMangaMetaInput(
|
||||
val clientMutationId: String? = null,
|
||||
val meta: MangaMetaType,
|
||||
|
||||
@@ -21,12 +21,15 @@ import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.ContentWarningFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.Filter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.HasGetOp
|
||||
import suwayomi.tachidesk.graphql.queries.filter.IntFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.LongFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.OpAnd
|
||||
import suwayomi.tachidesk.graphql.queries.filter.StringFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompare
|
||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareEnum
|
||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
@@ -40,6 +43,7 @@ import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionNodeList
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionType
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
@@ -55,21 +59,23 @@ class ExtensionQuery {
|
||||
) : OrderBy<ExtensionType> {
|
||||
PKG_NAME(ExtensionTable.pkgName),
|
||||
NAME(ExtensionTable.name),
|
||||
APK_NAME(ExtensionTable.apkName),
|
||||
|
||||
@GraphQLDeprecated("")
|
||||
APK_NAME(ExtensionTable.pkgName),
|
||||
;
|
||||
|
||||
override fun greater(cursor: Cursor): Op<Boolean> =
|
||||
when (this) {
|
||||
PKG_NAME -> ExtensionTable.pkgName greater cursor.value
|
||||
NAME -> greaterNotUnique(ExtensionTable.name, ExtensionTable.pkgName, cursor, String::toString)
|
||||
APK_NAME -> greaterNotUnique(ExtensionTable.apkName, ExtensionTable.pkgName, cursor, String::toString)
|
||||
APK_NAME -> ExtensionTable.pkgName greater cursor.value
|
||||
}
|
||||
|
||||
override fun less(cursor: Cursor): Op<Boolean> =
|
||||
when (this) {
|
||||
PKG_NAME -> ExtensionTable.pkgName less cursor.value
|
||||
NAME -> lessNotUnique(ExtensionTable.name, ExtensionTable.pkgName, cursor, String::toString)
|
||||
APK_NAME -> lessNotUnique(ExtensionTable.apkName, ExtensionTable.pkgName, cursor, String::toString)
|
||||
APK_NAME -> ExtensionTable.pkgName less cursor.value
|
||||
}
|
||||
|
||||
override fun asCursor(type: ExtensionType): Cursor {
|
||||
@@ -89,29 +95,44 @@ class ExtensionQuery {
|
||||
) : Order<ExtensionOrderBy>
|
||||
|
||||
data class ExtensionCondition(
|
||||
val storeIndexUrl: String? = null,
|
||||
@GraphQLDeprecated("", ReplaceWith("storeIndexUrl"))
|
||||
val repo: String? = null,
|
||||
val apkName: String? = null,
|
||||
val iconUrl: String? = null,
|
||||
val name: String? = null,
|
||||
val pkgName: String? = null,
|
||||
val apkUrl: String? = null,
|
||||
val extensionLib: String? = null,
|
||||
val versionName: String? = null,
|
||||
val versionCode: Int? = null,
|
||||
val versionCodeLong: Long? = null,
|
||||
val lang: String? = null,
|
||||
@GraphQLDeprecated("", ReplaceWith("contentWarning"))
|
||||
val isNsfw: Boolean? = null,
|
||||
val contentWarning: ContentWarning? = null,
|
||||
val isInstalled: Boolean? = null,
|
||||
val hasUpdate: Boolean? = null,
|
||||
val isObsolete: Boolean? = null,
|
||||
) : HasGetOp {
|
||||
override fun getOp(): Op<Boolean>? {
|
||||
val opAnd = OpAnd()
|
||||
opAnd.eq(repo, ExtensionTable.repo)
|
||||
opAnd.eq(storeIndexUrl, ExtensionTable.storeIndexUrl)
|
||||
opAnd.eq(repo, ExtensionTable.storeIndexUrl)
|
||||
opAnd.eq(apkName, ExtensionTable.apkName)
|
||||
opAnd.eq(iconUrl, ExtensionTable.iconUrl)
|
||||
opAnd.eq(apkUrl, ExtensionTable.apkUrl)
|
||||
opAnd.eq(name, ExtensionTable.name)
|
||||
opAnd.eq(extensionLib, ExtensionTable.extensionLib)
|
||||
opAnd.eq(versionName, ExtensionTable.versionName)
|
||||
opAnd.eq(versionCode, ExtensionTable.versionCode)
|
||||
opAnd.eq(versionCode?.toLong(), ExtensionTable.versionCode)
|
||||
opAnd.eq(versionCodeLong, ExtensionTable.versionCode)
|
||||
opAnd.eq(lang, ExtensionTable.lang)
|
||||
opAnd.eq(isNsfw, ExtensionTable.isNsfw)
|
||||
opAnd.eq(
|
||||
isNsfw?.let { if (it) ContentWarning.MIXED.ordinal else ContentWarning.SAFE.ordinal },
|
||||
ExtensionTable.contentWarning,
|
||||
)
|
||||
opAnd.eq(contentWarning?.ordinal, ExtensionTable.contentWarning)
|
||||
opAnd.eq(isInstalled, ExtensionTable.isInstalled)
|
||||
opAnd.eq(hasUpdate, ExtensionTable.hasUpdate)
|
||||
opAnd.eq(isObsolete, ExtensionTable.isObsolete)
|
||||
@@ -121,15 +142,23 @@ class ExtensionQuery {
|
||||
}
|
||||
|
||||
data class ExtensionFilter(
|
||||
val storeIndexUrl: StringFilter? = null,
|
||||
@GraphQLDeprecated("", ReplaceWith("storeIndexUrl"))
|
||||
val repo: StringFilter? = null,
|
||||
val apkName: StringFilter? = null,
|
||||
val iconUrl: StringFilter? = null,
|
||||
val name: StringFilter? = null,
|
||||
val pkgName: StringFilter? = null,
|
||||
val apkUrl: StringFilter? = null,
|
||||
val versionName: StringFilter? = null,
|
||||
val extensionLib: StringFilter? = null,
|
||||
@GraphQLDeprecated("", ReplaceWith("versionCodeLong"))
|
||||
val versionCode: IntFilter? = null,
|
||||
val versionCodeLong: LongFilter? = null,
|
||||
val lang: StringFilter? = null,
|
||||
@GraphQLDeprecated("", ReplaceWith("contentWarning"))
|
||||
val isNsfw: BooleanFilter? = null,
|
||||
val contentWarning: ContentWarningFilter? = null,
|
||||
val isInstalled: BooleanFilter? = null,
|
||||
val hasUpdate: BooleanFilter? = null,
|
||||
val isObsolete: BooleanFilter? = null,
|
||||
@@ -139,15 +168,18 @@ class ExtensionQuery {
|
||||
) : Filter<ExtensionFilter> {
|
||||
override fun getOpList(): List<Op<Boolean>> =
|
||||
listOfNotNull(
|
||||
andFilterWithCompareString(ExtensionTable.repo, repo),
|
||||
andFilterWithCompareString(ExtensionTable.storeIndexUrl, storeIndexUrl),
|
||||
andFilterWithCompareString(ExtensionTable.storeIndexUrl, repo),
|
||||
andFilterWithCompareString(ExtensionTable.apkName, apkName),
|
||||
andFilterWithCompareString(ExtensionTable.iconUrl, iconUrl),
|
||||
andFilterWithCompareString(ExtensionTable.name, name),
|
||||
andFilterWithCompareString(ExtensionTable.pkgName, pkgName),
|
||||
andFilterWithCompareString(ExtensionTable.apkUrl, apkUrl),
|
||||
andFilterWithCompareString(ExtensionTable.extensionLib, extensionLib),
|
||||
andFilterWithCompareString(ExtensionTable.versionName, versionName),
|
||||
andFilterWithCompare(ExtensionTable.versionCode, versionCode),
|
||||
andFilterWithCompare(ExtensionTable.versionCode, versionCodeLong),
|
||||
andFilterWithCompareString(ExtensionTable.lang, lang),
|
||||
andFilterWithCompare(ExtensionTable.isNsfw, isNsfw),
|
||||
andFilterWithCompareEnum(ExtensionTable.contentWarning, contentWarning),
|
||||
andFilterWithCompare(ExtensionTable.isInstalled, isInstalled),
|
||||
andFilterWithCompare(ExtensionTable.hasUpdate, hasUpdate),
|
||||
andFilterWithCompare(ExtensionTable.isObsolete, isObsolete),
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
package suwayomi.tachidesk.graphql.queries
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||
import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.v1.core.Column
|
||||
import org.jetbrains.exposed.v1.core.Op
|
||||
import org.jetbrains.exposed.v1.core.SortOrder
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||
import suwayomi.tachidesk.graphql.queries.filter.Filter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.HasGetOp
|
||||
import suwayomi.tachidesk.graphql.queries.filter.OpAnd
|
||||
import suwayomi.tachidesk.graphql.queries.filter.StringFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Order
|
||||
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
|
||||
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
|
||||
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionStoreNodeList
|
||||
import suwayomi.tachidesk.graphql.types.ExtensionStoreType
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionStoreTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class ExtensionStoreQuery {
|
||||
@RequireAuth
|
||||
fun extensionStore(
|
||||
dataFetchingEnvironment: DataFetchingEnvironment,
|
||||
indexUrl: String,
|
||||
): CompletableFuture<ExtensionStoreType> = dataFetchingEnvironment.getValueFromDataLoader("ExtensionStoreDataLoader", indexUrl)
|
||||
|
||||
enum class ExtensionStoreOrderBy(
|
||||
override val column: Column<*>,
|
||||
) : OrderBy<ExtensionStoreType> {
|
||||
NAME(ExtensionStoreTable.name),
|
||||
INDEX_URL(ExtensionStoreTable.indexUrl),
|
||||
;
|
||||
|
||||
override fun greater(cursor: Cursor): Op<Boolean> =
|
||||
when (this) {
|
||||
NAME -> greaterNotUnique(ExtensionStoreTable.name, ExtensionStoreTable.id, cursor, String::toString)
|
||||
INDEX_URL -> greaterNotUnique(ExtensionStoreTable.indexUrl, ExtensionStoreTable.id, cursor, String::toString)
|
||||
}
|
||||
|
||||
override fun less(cursor: Cursor): Op<Boolean> =
|
||||
when (this) {
|
||||
NAME -> lessNotUnique(ExtensionStoreTable.name, ExtensionStoreTable.id, cursor, String::toString)
|
||||
INDEX_URL -> lessNotUnique(ExtensionStoreTable.indexUrl, ExtensionStoreTable.id, cursor, String::toString)
|
||||
}
|
||||
|
||||
override fun asCursor(type: ExtensionStoreType): Cursor {
|
||||
val value =
|
||||
when (this) {
|
||||
INDEX_URL -> type.indexUrl
|
||||
NAME -> type.indexUrl + "-" + type.name
|
||||
}
|
||||
return Cursor(value)
|
||||
}
|
||||
}
|
||||
|
||||
data class ExtensionStoreOrder(
|
||||
override val by: ExtensionStoreOrderBy,
|
||||
override val byType: SortOrder? = null,
|
||||
) : Order<ExtensionStoreOrderBy>
|
||||
|
||||
data class ExtensionStoreCondition(
|
||||
val id: Int? = null,
|
||||
val indexUrl: String? = null,
|
||||
val name: String? = null,
|
||||
) : HasGetOp {
|
||||
override fun getOp(): Op<Boolean>? {
|
||||
val opAnd = OpAnd()
|
||||
opAnd.eq(id, ExtensionStoreTable.id)
|
||||
opAnd.eq(indexUrl, ExtensionStoreTable.indexUrl)
|
||||
opAnd.eq(name, ExtensionStoreTable.name)
|
||||
|
||||
return opAnd.op
|
||||
}
|
||||
}
|
||||
|
||||
data class ExtensionStoreFilter(
|
||||
val indexUrl: StringFilter? = null,
|
||||
val name: StringFilter? = null,
|
||||
override val and: List<ExtensionStoreFilter>? = null,
|
||||
override val or: List<ExtensionStoreFilter>? = null,
|
||||
override val not: ExtensionStoreFilter? = null,
|
||||
) : Filter<ExtensionStoreFilter> {
|
||||
override fun getOpList(): List<Op<Boolean>> =
|
||||
listOfNotNull(
|
||||
andFilterWithCompareString(ExtensionStoreTable.indexUrl, indexUrl),
|
||||
andFilterWithCompareString(ExtensionStoreTable.name, name),
|
||||
)
|
||||
}
|
||||
|
||||
@RequireAuth
|
||||
fun extensionStores(
|
||||
condition: ExtensionStoreCondition? = null,
|
||||
filter: ExtensionStoreFilter? = null,
|
||||
order: List<ExtensionStoreOrder>? = null,
|
||||
before: Cursor? = null,
|
||||
after: Cursor? = null,
|
||||
first: Int? = null,
|
||||
last: Int? = null,
|
||||
offset: Int? = null,
|
||||
): ExtensionStoreNodeList {
|
||||
val queryResults =
|
||||
transaction {
|
||||
val res = ExtensionStoreTable.selectAll()
|
||||
|
||||
res.applyOps(condition, filter)
|
||||
|
||||
if (order != null || (last != null || before != null)) {
|
||||
val baseSort = listOf(ExtensionStoreOrder(ExtensionStoreOrderBy.INDEX_URL, SortOrder.ASC))
|
||||
val actualSort = (order.orEmpty() + baseSort)
|
||||
actualSort.forEach { (orderBy, orderByType) ->
|
||||
val orderByColumn = orderBy.column
|
||||
val orderType = orderByType.maybeSwap(last ?: before)
|
||||
|
||||
res.orderBy(orderByColumn to orderType)
|
||||
}
|
||||
}
|
||||
|
||||
val total = res.count()
|
||||
val firstResult = res.firstOrNull()?.get(ExtensionStoreTable.indexUrl)
|
||||
val lastResult = res.lastOrNull()?.get(ExtensionStoreTable.indexUrl)
|
||||
|
||||
res.applyBeforeAfter(
|
||||
before = before,
|
||||
after = after,
|
||||
orderBy = order?.firstOrNull()?.by ?: ExtensionStoreOrderBy.INDEX_URL,
|
||||
orderByType = order?.firstOrNull()?.byType,
|
||||
)
|
||||
|
||||
if (first != null) {
|
||||
res.limit(first).offset(offset?.toLong() ?: 0)
|
||||
} else if (last != null) {
|
||||
res.limit(last)
|
||||
}
|
||||
|
||||
QueryResults(total, firstResult, lastResult, res.toList())
|
||||
}
|
||||
|
||||
val getAsCursor: (ExtensionStoreType) -> Cursor = (order?.firstOrNull()?.by ?: ExtensionStoreOrderBy.INDEX_URL)::asCursor
|
||||
|
||||
val resultsAsType = queryResults.results.map { ExtensionStoreType(it) }
|
||||
|
||||
return ExtensionStoreNodeList(
|
||||
resultsAsType,
|
||||
if (resultsAsType.isEmpty()) {
|
||||
emptyList()
|
||||
} else {
|
||||
listOfNotNull(
|
||||
resultsAsType.firstOrNull()?.let {
|
||||
ExtensionStoreNodeList.ExtensionStoreEdge(
|
||||
getAsCursor(it),
|
||||
it,
|
||||
)
|
||||
},
|
||||
resultsAsType.lastOrNull()?.let {
|
||||
ExtensionStoreNodeList.ExtensionStoreEdge(
|
||||
getAsCursor(it),
|
||||
it,
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
pageInfo =
|
||||
PageInfo(
|
||||
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.indexUrl,
|
||||
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.indexUrl,
|
||||
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
|
||||
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) },
|
||||
),
|
||||
totalCount = queryResults.total.toInt(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -13,19 +13,22 @@ import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.v1.core.Column
|
||||
import org.jetbrains.exposed.v1.core.Op
|
||||
import org.jetbrains.exposed.v1.core.SortOrder
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.greater
|
||||
import org.jetbrains.exposed.v1.core.greaterEq
|
||||
import org.jetbrains.exposed.v1.core.less
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.ContentWarningFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.Filter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.HasGetOp
|
||||
import suwayomi.tachidesk.graphql.queries.filter.LongFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.OpAnd
|
||||
import suwayomi.tachidesk.graphql.queries.filter.StringFilter
|
||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompare
|
||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareEntity
|
||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareEnum
|
||||
import suwayomi.tachidesk.graphql.queries.filter.andFilterWithCompareString
|
||||
import suwayomi.tachidesk.graphql.queries.filter.applyOps
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
@@ -39,6 +42,7 @@ import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
|
||||
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
|
||||
import suwayomi.tachidesk.graphql.types.SourceNodeList
|
||||
import suwayomi.tachidesk.graphql.types.SourceType
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
import suwayomi.tachidesk.manga.model.table.SourceTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
@@ -91,14 +95,23 @@ class SourceQuery {
|
||||
val id: Long? = null,
|
||||
val name: String? = null,
|
||||
val lang: String? = null,
|
||||
@GraphQLDeprecated("replace with contentWarning == ContentRating.MIXED", ReplaceWith("contentWarning"))
|
||||
val isNsfw: Boolean? = null,
|
||||
val contentWarning: ContentWarning? = null,
|
||||
) : HasGetOp {
|
||||
override fun getOp(): Op<Boolean>? {
|
||||
val opAnd = OpAnd()
|
||||
opAnd.eq(id, SourceTable.id)
|
||||
opAnd.eq(name, SourceTable.name)
|
||||
opAnd.eq(lang, SourceTable.lang)
|
||||
opAnd.eq(isNsfw, SourceTable.isNsfw)
|
||||
opAnd.andWhere(isNsfw) {
|
||||
if (it) {
|
||||
SourceTable.contentWarning greaterEq ContentWarning.MIXED.ordinal
|
||||
} else {
|
||||
SourceTable.contentWarning less ContentWarning.MIXED.ordinal
|
||||
}
|
||||
}
|
||||
opAnd.andWhere(contentWarning) { SourceTable.contentWarning eq it.ordinal }
|
||||
|
||||
return opAnd.op
|
||||
}
|
||||
@@ -108,7 +121,9 @@ class SourceQuery {
|
||||
val id: LongFilter? = null,
|
||||
val name: StringFilter? = null,
|
||||
val lang: StringFilter? = null,
|
||||
@GraphQLDeprecated("replace with contentWarning", ReplaceWith("contentWarning"))
|
||||
val isNsfw: BooleanFilter? = null,
|
||||
val contentWarning: ContentWarningFilter? = null,
|
||||
override val and: List<SourceFilter>? = null,
|
||||
override val or: List<SourceFilter>? = null,
|
||||
override val not: SourceFilter? = null,
|
||||
@@ -118,7 +133,7 @@ class SourceQuery {
|
||||
andFilterWithCompareEntity(SourceTable.id, id),
|
||||
andFilterWithCompareString(SourceTable.name, name),
|
||||
andFilterWithCompareString(SourceTable.lang, lang),
|
||||
andFilterWithCompare(SourceTable.isNsfw, isNsfw),
|
||||
andFilterWithCompareEnum(SourceTable.contentWarning, contentWarning),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.exposed.v1.core.upperCase
|
||||
import org.jetbrains.exposed.v1.core.wrap
|
||||
import org.jetbrains.exposed.v1.jdbc.Query
|
||||
import org.jetbrains.exposed.v1.jdbc.andWhere
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
|
||||
class ILikeEscapeOp(
|
||||
expr1: Expression<*>,
|
||||
@@ -329,6 +330,24 @@ data class DoubleFilter(
|
||||
)
|
||||
}
|
||||
|
||||
data class ContentWarningFilter(
|
||||
override val isNull: Boolean? = null,
|
||||
override val equalTo: ContentWarning? = null,
|
||||
override val notEqualTo: ContentWarning? = null,
|
||||
override val notEqualToAll: List<ContentWarning>? = null,
|
||||
override val notEqualToAny: List<ContentWarning>? = null,
|
||||
override val distinctFrom: ContentWarning? = null,
|
||||
override val distinctFromAll: List<ContentWarning>? = null,
|
||||
override val distinctFromAny: List<ContentWarning>? = null,
|
||||
override val notDistinctFrom: ContentWarning? = null,
|
||||
override val `in`: List<ContentWarning>? = null,
|
||||
override val notIn: List<ContentWarning>? = null,
|
||||
override val lessThan: ContentWarning? = null,
|
||||
override val lessThanOrEqualTo: ContentWarning? = null,
|
||||
override val greaterThan: ContentWarning? = null,
|
||||
override val greaterThanOrEqualTo: ContentWarning? = null,
|
||||
) : ComparableScalarFilter<ContentWarning>
|
||||
|
||||
data class StringFilter(
|
||||
override val isNull: Boolean? = null,
|
||||
override val equalTo: String? = null,
|
||||
@@ -618,6 +637,35 @@ fun <T : Comparable<T>, S : T?> andFilterWithCompare(
|
||||
return opAnd.op
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Enum<T>> andFilterWithCompareEnum(
|
||||
column: Column<Int>,
|
||||
filter: ComparableScalarFilter<T>?,
|
||||
): Op<Boolean>? {
|
||||
filter ?: return null
|
||||
val opAnd = OpAnd()
|
||||
|
||||
opAnd.andWhere(filter.lessThan) { column less it.ordinal }
|
||||
opAnd.andWhere(filter.lessThanOrEqualTo) { column lessEq it.ordinal }
|
||||
opAnd.andWhere(filter.greaterThan) { column greater it.ordinal }
|
||||
opAnd.andWhere(filter.greaterThanOrEqualTo) { column greaterEq it.ordinal }
|
||||
|
||||
opAnd.andWhere(filter.isNull) { if (it) column.isNull() else column.isNotNull() }
|
||||
|
||||
opAnd.andWhere(filter.equalTo) { column eq it.ordinal }
|
||||
opAnd.andNotWhere(filter.notEqualTo, filter.notEqualToAll, filter.notEqualToAny) { column neq it.ordinal }
|
||||
opAnd.andWhere(filter.distinctFrom, filter.distinctFromAll, filter.distinctFromAny) { DistinctFromOp.distinctFrom(column, it.ordinal) }
|
||||
opAnd.andWhere(filter.notDistinctFrom) { DistinctFromOp.notDistinctFrom(column, it.ordinal) }
|
||||
if (!filter.`in`.isNullOrEmpty()) {
|
||||
opAnd.andWhere(filter.`in`) { column inList it.map { it.ordinal } }
|
||||
}
|
||||
if (!filter.notIn.isNullOrEmpty()) {
|
||||
opAnd.andWhere(filter.notIn) { column notInList it.map { it.ordinal } }
|
||||
}
|
||||
|
||||
return opAnd.op
|
||||
}
|
||||
|
||||
fun <T : Comparable<T>> andFilterWithCompareEntity(
|
||||
column: Column<EntityID<T>>,
|
||||
filter: ComparableScalarFilter<T>?,
|
||||
|
||||
@@ -21,6 +21,8 @@ import suwayomi.tachidesk.graphql.dataLoaders.DisplayScoreForTrackSearchDataLoad
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.DownloadedChapterCountForMangaDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.ExtensionDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.ExtensionForSourceDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.ExtensionStoreDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.ExtensionsForExtensionStore
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.FirstUnreadChapterForMangaDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.GlobalMetaDataLoader
|
||||
import suwayomi.tachidesk.graphql.dataLoaders.HasDuplicateChaptersForMangaDataLoader
|
||||
@@ -78,6 +80,8 @@ class TachideskDataLoaderRegistryFactory {
|
||||
SourceMetaDataLoader(),
|
||||
ExtensionDataLoader(),
|
||||
ExtensionForSourceDataLoader(),
|
||||
ExtensionsForExtensionStore(),
|
||||
ExtensionStoreDataLoader(),
|
||||
TrackerDataLoader(),
|
||||
TrackerStatusesDataLoader(),
|
||||
TrackerScoresDataLoader(),
|
||||
|
||||
@@ -20,6 +20,7 @@ import suwayomi.tachidesk.graphql.mutations.CategoryMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.ChapterMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.DownloadMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.ExtensionMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.ExtensionStoreMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.ImageMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.InfoMutation
|
||||
import suwayomi.tachidesk.graphql.mutations.KoreaderSyncMutation
|
||||
@@ -36,6 +37,7 @@ import suwayomi.tachidesk.graphql.queries.CategoryQuery
|
||||
import suwayomi.tachidesk.graphql.queries.ChapterQuery
|
||||
import suwayomi.tachidesk.graphql.queries.DownloadQuery
|
||||
import suwayomi.tachidesk.graphql.queries.ExtensionQuery
|
||||
import suwayomi.tachidesk.graphql.queries.ExtensionStoreQuery
|
||||
import suwayomi.tachidesk.graphql.queries.InfoQuery
|
||||
import suwayomi.tachidesk.graphql.queries.KoreaderSyncQuery
|
||||
import suwayomi.tachidesk.graphql.queries.MangaQuery
|
||||
@@ -95,6 +97,7 @@ val schema =
|
||||
TopLevelObject(ChapterQuery()),
|
||||
TopLevelObject(DownloadQuery()),
|
||||
TopLevelObject(ExtensionQuery()),
|
||||
TopLevelObject(ExtensionStoreQuery()),
|
||||
TopLevelObject(InfoQuery()),
|
||||
TopLevelObject(KoreaderSyncQuery()),
|
||||
TopLevelObject(MangaQuery()),
|
||||
@@ -112,6 +115,7 @@ val schema =
|
||||
TopLevelObject(ChapterMutation()),
|
||||
TopLevelObject(DownloadMutation()),
|
||||
TopLevelObject(ExtensionMutation()),
|
||||
TopLevelObject(ExtensionStoreMutation()),
|
||||
TopLevelObject(ImageMutation()),
|
||||
TopLevelObject(InfoMutation()),
|
||||
TopLevelObject(KoreaderSyncMutation()),
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package suwayomi.tachidesk.graphql.types
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||
import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Cursor
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Edge
|
||||
import suwayomi.tachidesk.graphql.server.primitives.Node
|
||||
import suwayomi.tachidesk.graphql.server.primitives.NodeList
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionStoreTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class ExtensionStoreType(
|
||||
val name: String,
|
||||
val badgeLabel: String,
|
||||
val signingKey: String,
|
||||
val contactWebsite: String,
|
||||
val contactDiscord: String?,
|
||||
val indexUrl: String,
|
||||
val isLegacy: Boolean,
|
||||
val extensionListUrl: String?,
|
||||
) : Node {
|
||||
constructor(row: ResultRow) : this(
|
||||
name = row[ExtensionStoreTable.name],
|
||||
badgeLabel = row[ExtensionStoreTable.badgeLabel],
|
||||
signingKey = row[ExtensionStoreTable.signingKey],
|
||||
contactWebsite = row[ExtensionStoreTable.contactWebsite],
|
||||
contactDiscord = row[ExtensionStoreTable.contactDiscord],
|
||||
indexUrl = row[ExtensionStoreTable.indexUrl],
|
||||
isLegacy = row[ExtensionStoreTable.isLegacy],
|
||||
extensionListUrl = row[ExtensionStoreTable.extensionListUrl],
|
||||
)
|
||||
|
||||
fun extensions(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<ExtensionNodeList> =
|
||||
dataFetchingEnvironment.getValueFromDataLoader<String, ExtensionNodeList>("ExtensionsForExtensionStore", indexUrl)
|
||||
}
|
||||
|
||||
data class ExtensionStoreNodeList(
|
||||
override val nodes: List<ExtensionStoreType>,
|
||||
override val edges: List<ExtensionStoreEdge>,
|
||||
override val pageInfo: PageInfo,
|
||||
override val totalCount: Int,
|
||||
) : NodeList() {
|
||||
data class ExtensionStoreEdge(
|
||||
override val cursor: Cursor,
|
||||
override val node: ExtensionStoreType,
|
||||
) : Edge()
|
||||
|
||||
companion object {
|
||||
fun List<ExtensionStoreType>.toNodeList(): ExtensionStoreNodeList =
|
||||
ExtensionStoreNodeList(
|
||||
nodes = this,
|
||||
edges = getEdges(),
|
||||
pageInfo =
|
||||
PageInfo(
|
||||
hasNextPage = false,
|
||||
hasPreviousPage = false,
|
||||
startCursor = Cursor(0.toString()),
|
||||
endCursor = Cursor(lastIndex.toString()),
|
||||
),
|
||||
totalCount = size,
|
||||
)
|
||||
|
||||
private fun List<ExtensionStoreType>.getEdges(): List<ExtensionStoreEdge> {
|
||||
if (isEmpty()) return emptyList()
|
||||
return listOf(
|
||||
ExtensionStoreEdge(
|
||||
cursor = Cursor("0"),
|
||||
node = first(),
|
||||
),
|
||||
ExtensionStoreEdge(
|
||||
cursor = Cursor(lastIndex.toString()),
|
||||
node = last(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
package suwayomi.tachidesk.graphql.types
|
||||
|
||||
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||
import com.expediagroup.graphql.generator.annotations.GraphQLDescription
|
||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||
import graphql.schema.DataFetchingEnvironment
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
@@ -16,33 +18,51 @@ import suwayomi.tachidesk.graphql.server.primitives.Node
|
||||
import suwayomi.tachidesk.graphql.server.primitives.NodeList
|
||||
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class ExtensionType(
|
||||
val storeIndexUrl: String?,
|
||||
@GraphQLDeprecated("Removed in extension api v1.6", ReplaceWith("storeIndexUrl"))
|
||||
val repo: String?,
|
||||
val apkName: String,
|
||||
@GraphQLDescription("This will be nullable in the future")
|
||||
val apkName: String?,
|
||||
val iconUrl: String,
|
||||
val name: String,
|
||||
val pkgName: String,
|
||||
val apkUrl: String?,
|
||||
val extensionLib: String?,
|
||||
val versionName: String,
|
||||
@GraphQLDeprecated(
|
||||
"Type was changed to Long, will be switched back to this variable name in the future.",
|
||||
ReplaceWith("versionCodeLong"),
|
||||
)
|
||||
val versionCode: Int,
|
||||
val versionCodeLong: Long,
|
||||
val lang: String,
|
||||
@GraphQLDeprecated("Removed in extension api v1.6", ReplaceWith("contentWarning"))
|
||||
val isNsfw: Boolean,
|
||||
val contentWarning: ContentWarning,
|
||||
val isInstalled: Boolean,
|
||||
val hasUpdate: Boolean,
|
||||
val isObsolete: Boolean,
|
||||
) : Node {
|
||||
constructor(row: ResultRow) : this(
|
||||
repo = row[ExtensionTable.repo],
|
||||
apkName = row[ExtensionTable.apkName],
|
||||
iconUrl = Extension.getExtensionIconUrl(row[ExtensionTable.apkName]),
|
||||
storeIndexUrl = row[ExtensionTable.storeIndexUrl],
|
||||
repo = row[ExtensionTable.storeIndexUrl],
|
||||
apkName = row[ExtensionTable.apkName].orEmpty(),
|
||||
iconUrl = Extension.proxyExtensionIconUrl(row[ExtensionTable.pkgName]),
|
||||
name = row[ExtensionTable.name],
|
||||
pkgName = row[ExtensionTable.pkgName],
|
||||
apkUrl = row[ExtensionTable.apkUrl],
|
||||
extensionLib = row[ExtensionTable.extensionLib],
|
||||
versionName = row[ExtensionTable.versionName],
|
||||
versionCode = row[ExtensionTable.versionCode],
|
||||
versionCode = row[ExtensionTable.versionCode].toInt(),
|
||||
versionCodeLong = row[ExtensionTable.versionCode],
|
||||
lang = row[ExtensionTable.lang],
|
||||
isNsfw = row[ExtensionTable.isNsfw],
|
||||
isNsfw = row[ExtensionTable.contentWarning] >= ContentWarning.MIXED.ordinal,
|
||||
contentWarning = ContentWarning.valueOf(row[ExtensionTable.contentWarning]),
|
||||
isInstalled = row[ExtensionTable.isInstalled],
|
||||
hasUpdate = row[ExtensionTable.hasUpdate],
|
||||
isObsolete = row[ExtensionTable.isObsolete],
|
||||
@@ -50,6 +70,9 @@ class ExtensionType(
|
||||
|
||||
fun source(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<SourceNodeList> =
|
||||
dataFetchingEnvironment.getValueFromDataLoader<String, SourceNodeList>("SourcesForExtensionDataLoader", pkgName)
|
||||
|
||||
fun extensionStore(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<ExtensionStoreType> =
|
||||
dataFetchingEnvironment.getValueFromDataLoader<String, ExtensionStoreType>("ExtensionStoreDataLoader", storeIndexUrl.orEmpty())
|
||||
}
|
||||
|
||||
data class ExtensionNodeList(
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
package suwayomi.tachidesk.graphql.types
|
||||
|
||||
import com.expediagroup.graphql.generator.annotations.GraphQLDeprecated
|
||||
import com.expediagroup.graphql.server.extensions.getValueFromDataLoader
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||
@@ -25,7 +26,7 @@ import suwayomi.tachidesk.manga.impl.Source.getSourcePreferencesRaw
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrStub
|
||||
import suwayomi.tachidesk.manga.model.dataclass.SourceDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionTable
|
||||
import suwayomi.tachidesk.manga.model.table.SourceTable
|
||||
import java.util.concurrent.CompletableFuture
|
||||
@@ -41,35 +42,29 @@ class SourceType(
|
||||
val id: Long,
|
||||
val name: String,
|
||||
val lang: String,
|
||||
val contentWarning: ContentWarning,
|
||||
val iconUrl: String,
|
||||
val supportsLatest: Boolean,
|
||||
val isConfigurable: Boolean,
|
||||
@GraphQLDeprecated("", ReplaceWith("contentWarning"))
|
||||
val isNsfw: Boolean,
|
||||
val displayName: String,
|
||||
val homeUrl: String?,
|
||||
@GraphQLDeprecated("", ReplaceWith("homeUrl"))
|
||||
val baseUrl: String?,
|
||||
) : Node {
|
||||
constructor(source: SourceDataClass) : this(
|
||||
id = source.id.toLong(),
|
||||
name = source.name,
|
||||
lang = source.lang,
|
||||
iconUrl = source.iconUrl,
|
||||
supportsLatest = source.supportsLatest,
|
||||
isConfigurable = source.isConfigurable,
|
||||
isNsfw = source.isNsfw,
|
||||
displayName = source.displayName,
|
||||
baseUrl = source.baseUrl,
|
||||
)
|
||||
|
||||
constructor(row: ResultRow, sourceExtension: ResultRow, catalogueSource: CatalogueSource) : this(
|
||||
id = row[SourceTable.id].value,
|
||||
name = row[SourceTable.name],
|
||||
lang = row[SourceTable.lang],
|
||||
iconUrl = Extension.getExtensionIconUrl(sourceExtension[ExtensionTable.apkName]),
|
||||
contentWarning = ContentWarning.valueOf(row[SourceTable.contentWarning]),
|
||||
iconUrl = Extension.proxyExtensionIconUrl(sourceExtension[ExtensionTable.pkgName]),
|
||||
supportsLatest = catalogueSource.supportsLatest,
|
||||
isConfigurable = catalogueSource is ConfigurableSource,
|
||||
isNsfw = row[SourceTable.isNsfw],
|
||||
isNsfw = row[SourceTable.contentWarning] >= ContentWarning.MIXED.ordinal,
|
||||
displayName = catalogueSource.toString(),
|
||||
baseUrl = catalogueSource.runCatching { (catalogueSource as? HttpSource)?.baseUrl }.getOrNull(),
|
||||
homeUrl = runCatching { (catalogueSource as? HttpSource)?.getHomeUrl() }.getOrNull(),
|
||||
baseUrl = runCatching { (catalogueSource as? HttpSource)?.baseUrl }.getOrNull(),
|
||||
)
|
||||
|
||||
fun manga(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<MangaNodeList> =
|
||||
|
||||
@@ -34,7 +34,7 @@ object MangaAPI {
|
||||
get("update/{pkgName}", ExtensionController.update)
|
||||
get("uninstall/{pkgName}", ExtensionController.uninstall)
|
||||
|
||||
get("icon/{apkName}", ExtensionController.icon)
|
||||
get("icon/{pkgName}", ExtensionController.icon)
|
||||
}
|
||||
|
||||
path("source") {
|
||||
|
||||
@@ -165,17 +165,17 @@ object ExtensionController {
|
||||
/** icon for extension named `apkName` */
|
||||
val icon =
|
||||
handler(
|
||||
pathParam<String>("apkName"),
|
||||
pathParam<String>("pkgName"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
summary("Extension icon")
|
||||
description("Icon for extension named `apkName`")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, apkName ->
|
||||
behaviorOf = { ctx, pkgName ->
|
||||
ctx.getAttribute(Attribute.TachideskUser).requireUser()
|
||||
ctx.future {
|
||||
future { Extension.getExtensionIcon(apkName) }
|
||||
future { Extension.getExtensionIcon(pkgName) }
|
||||
.thenApply {
|
||||
ctx.header("content-type", it.second)
|
||||
val httpCacheSeconds = 365.days.inWholeSeconds
|
||||
|
||||
@@ -55,7 +55,7 @@ object UpdateController {
|
||||
)
|
||||
|
||||
/**
|
||||
* Class made for handling return type in the documentation for [recentChapters],
|
||||
* Class made for handling return type in the documentation for [UpdateController.recentChapters],
|
||||
* since OpenApi cannot handle runtime generics.
|
||||
*/
|
||||
private class PagedMangaChapterListDataClass : PaginatedList<MangaChapterDataClass>(emptyList(), false)
|
||||
|
||||
@@ -117,12 +117,14 @@ object CategoryManga {
|
||||
|
||||
val transform: (ResultRow) -> MangaDataClass = {
|
||||
// Map the data from the result row to the MangaDataClass
|
||||
val dataClass = MangaTable.toDataClass(it)
|
||||
dataClass.lastReadAt = it[lastReadAt]
|
||||
dataClass.unreadCount = it[unreadCount]
|
||||
dataClass.downloadCount = it[downloadedCount]
|
||||
dataClass.chapterCount = it[chapterCount]
|
||||
dataClass
|
||||
MangaTable
|
||||
.toDataClass(it)
|
||||
.copy(
|
||||
lastReadAt = it[lastReadAt],
|
||||
unreadCount = it[unreadCount],
|
||||
downloadCount = it[downloadedCount],
|
||||
chapterCount = it[chapterCount],
|
||||
)
|
||||
}
|
||||
|
||||
return transaction {
|
||||
|
||||
@@ -7,16 +7,19 @@ package suwayomi.tachidesk.manga.impl
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterSanitizer.sanitize
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.github.reactivecircus.cache4k.Cache
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import org.jetbrains.exposed.v1.core.SortOrder
|
||||
import org.jetbrains.exposed.v1.core.and
|
||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
||||
@@ -32,7 +35,6 @@ import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.statements.toExecutable
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import org.jetbrains.exposed.v1.jdbc.update
|
||||
import suwayomi.tachidesk.manga.impl.Manga.getManga
|
||||
import suwayomi.tachidesk.manga.impl.download.DownloadManager
|
||||
import suwayomi.tachidesk.manga.impl.download.DownloadManager.EnqueueInput
|
||||
import suwayomi.tachidesk.manga.impl.track.Track
|
||||
@@ -50,7 +52,6 @@ import suwayomi.tachidesk.server.serverConfig
|
||||
import java.time.Instant
|
||||
import java.util.TreeSet
|
||||
import kotlin.math.max
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
||||
private fun List<ChapterDataClass>.removeDuplicates(currentChapter: ChapterDataClass): List<ChapterDataClass> =
|
||||
groupBy { it.chapterNumber }
|
||||
@@ -104,265 +105,277 @@ object Chapter {
|
||||
.associateBy({ it[ChapterTable.url] }, { it })
|
||||
}
|
||||
|
||||
val chapterIds = chapterList.map { dbChapterMap.getValue(it.url)[ChapterTable.id] }
|
||||
val chapterMetas = getChaptersMetaMaps(chapterIds.map { it.value })
|
||||
|
||||
return chapterList.mapIndexed { index, it ->
|
||||
|
||||
return chapterList.map {
|
||||
val dbChapter = dbChapterMap.getValue(it.url)
|
||||
|
||||
ChapterDataClass(
|
||||
id = dbChapter[ChapterTable.id].value,
|
||||
url = it.url,
|
||||
name = it.name,
|
||||
uploadDate = it.date_upload,
|
||||
chapterNumber = it.chapter_number,
|
||||
scanlator = it.scanlator,
|
||||
mangaId = mangaId,
|
||||
read = dbChapter[ChapterTable.isRead],
|
||||
bookmarked = dbChapter[ChapterTable.isBookmarked],
|
||||
lastPageRead = dbChapter[ChapterTable.lastPageRead],
|
||||
lastReadAt = dbChapter[ChapterTable.lastReadAt],
|
||||
index = chapterList.size - index,
|
||||
fetchedAt = dbChapter[ChapterTable.fetchedAt],
|
||||
realUrl = dbChapter[ChapterTable.realUrl],
|
||||
downloaded = dbChapter[ChapterTable.isDownloaded],
|
||||
pageCount = dbChapter[ChapterTable.pageCount],
|
||||
chapterCount = chapterList.size,
|
||||
lastModifiedAt = dbChapter[ChapterTable.lastModifiedAt],
|
||||
version = dbChapter[ChapterTable.version],
|
||||
meta = chapterMetas.getValue(dbChapter[ChapterTable.id].value),
|
||||
)
|
||||
ChapterTable.toDataClass(dbChapter)
|
||||
}
|
||||
}
|
||||
|
||||
val map: Cache<Int, Mutex> =
|
||||
Cache
|
||||
.Builder<Int, Mutex>()
|
||||
.expireAfterAccess(10.minutes)
|
||||
.build()
|
||||
|
||||
suspend fun fetchChapterList(mangaId: Int): List<SChapter> {
|
||||
val mutex = map.get(mangaId) { Mutex() }
|
||||
val mutex = Manga.mangaInfoMutex.get(mangaId) { Mutex() }
|
||||
val chapterList =
|
||||
mutex.withLock {
|
||||
val manga = getManga(mangaId)
|
||||
val source = getCatalogueSourceOrStub(manga.sourceId.toLong())
|
||||
|
||||
val sManga =
|
||||
SManga.create().apply {
|
||||
title = manga.title
|
||||
url = manga.url
|
||||
description = manga.description
|
||||
}
|
||||
|
||||
val currentLatestChapterNumber = Manga.getLatestChapter(mangaId)?.chapterNumber ?: 0f
|
||||
val numberOfCurrentChapters = getCountOfMangaChapters(mangaId)
|
||||
|
||||
val chapters = source.getChapterList(sManga)
|
||||
// it's possible that the source returns a list containing chapters with the same url
|
||||
// once such duplicated chapters have been added, they aren't being removed anymore as long as there is
|
||||
// a chapter with the same url in the fetched chapter list, even if the duplicated chapter itself
|
||||
// does not exist anymore on the source
|
||||
val uniqueChapters = chapters.distinctBy { it.url }
|
||||
|
||||
if (uniqueChapters.isEmpty()) {
|
||||
throw Exception("No chapters found")
|
||||
}
|
||||
|
||||
// Recognize number for new chapters.
|
||||
uniqueChapters.forEach { chapter ->
|
||||
(source as? HttpSource)?.prepareNewChapter(chapter, sManga)
|
||||
val chapterNumber = ChapterRecognition.parseChapterNumber(manga.title, chapter.name, chapter.chapter_number.toDouble())
|
||||
chapter.chapter_number = chapterNumber.toFloat()
|
||||
chapter.name = chapter.name.sanitize(manga.title)
|
||||
chapter.scanlator = chapter.scanlator?.ifBlank { null }?.trim()
|
||||
}
|
||||
|
||||
val now = Instant.now().epochSecond
|
||||
// Used to not set upload date of older chapters
|
||||
// to a higher value than newer chapters
|
||||
var maxSeenUploadDate = 0L
|
||||
|
||||
val chaptersInDb =
|
||||
val mangaEntry =
|
||||
transaction {
|
||||
ChapterTable
|
||||
.selectAll()
|
||||
.where { ChapterTable.manga eq mangaId }
|
||||
.map { ChapterTable.toDataClass(it) }
|
||||
.toList()
|
||||
MangaTable.selectAll().where { MangaTable.id eq mangaId }.first()
|
||||
}
|
||||
val source = getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference])
|
||||
|
||||
// new chapters after they have been added to the database for auto downloads
|
||||
val insertedChapters = mutableListOf<ChapterDataClass>()
|
||||
val chapters =
|
||||
Manga
|
||||
.fetchMangaAndChapters(
|
||||
mangaEntry = mangaEntry,
|
||||
source = source,
|
||||
fetchDetails = false,
|
||||
fetchChapters = true,
|
||||
).chapters
|
||||
|
||||
val chaptersToInsert = mutableListOf<ChapterDataClass>() // do not yet have an ID from the database
|
||||
val chaptersToUpdate = mutableListOf<ChapterDataClass>()
|
||||
|
||||
uniqueChapters.reversed().forEachIndexed { index, fetchedChapter ->
|
||||
val chapterEntry = chaptersInDb.find { it.url == fetchedChapter.url }
|
||||
|
||||
val chapterData =
|
||||
ChapterDataClass.fromSChapter(
|
||||
fetchedChapter,
|
||||
chapterEntry?.id ?: 0,
|
||||
index + 1,
|
||||
now,
|
||||
mangaId,
|
||||
runCatching {
|
||||
(source as? HttpSource)?.getChapterUrl(fetchedChapter)
|
||||
}.getOrNull(),
|
||||
)
|
||||
|
||||
if (chapterEntry == null) {
|
||||
val newChapterData =
|
||||
if (chapterData.uploadDate == 0L) {
|
||||
val altDateUpload = if (maxSeenUploadDate == 0L) now else maxSeenUploadDate
|
||||
chapterData.copy(uploadDate = altDateUpload)
|
||||
} else {
|
||||
maxSeenUploadDate = max(maxSeenUploadDate, chapterData.uploadDate)
|
||||
chapterData
|
||||
}
|
||||
chaptersToInsert.add(newChapterData)
|
||||
} else {
|
||||
val newChapterData =
|
||||
if (chapterData.uploadDate == 0L) {
|
||||
chapterData.copy(uploadDate = chapterEntry.uploadDate)
|
||||
} else {
|
||||
chapterData
|
||||
}
|
||||
chaptersToUpdate.add(newChapterData)
|
||||
}
|
||||
}
|
||||
|
||||
val deletedChapterNumbers = TreeSet<Float>()
|
||||
val deletedReadChapterNumbers = TreeSet<Float>()
|
||||
val deletedBookmarkedChapterNumbers = TreeSet<Float>()
|
||||
val deletedDownloadedChapterNumberToChapter = mutableMapOf<Float, ChapterDataClass>()
|
||||
val deletedChapterNumberDateFetchMap = mutableMapOf<Float, Long>()
|
||||
|
||||
// clear any orphaned/duplicate chapters that are in the db but not in `chapterList`
|
||||
val chapterUrls = uniqueChapters.map { it.url }.toSet()
|
||||
|
||||
val chaptersIdsToDelete =
|
||||
chaptersInDb.mapNotNull { dbChapter ->
|
||||
if (!chapterUrls.contains(dbChapter.url)) {
|
||||
if (dbChapter.read) deletedReadChapterNumbers.add(dbChapter.chapterNumber)
|
||||
if (dbChapter.bookmarked) deletedBookmarkedChapterNumbers.add(dbChapter.chapterNumber)
|
||||
if (dbChapter.downloaded) deletedDownloadedChapterNumberToChapter[dbChapter.chapterNumber] = dbChapter
|
||||
deletedChapterNumbers.add(dbChapter.chapterNumber)
|
||||
deletedChapterNumberDateFetchMap[dbChapter.chapterNumber] = dbChapter.fetchedAt
|
||||
dbChapter.id
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
transaction {
|
||||
// we got some clean up due
|
||||
if (chaptersIdsToDelete.isNotEmpty()) {
|
||||
DownloadManager.dequeue(chaptersIdsToDelete)
|
||||
PageTable.deleteWhere { chapter inList chaptersIdsToDelete }
|
||||
ChapterTable.deleteWhere { id inList chaptersIdsToDelete }
|
||||
}
|
||||
|
||||
if (chaptersToInsert.isNotEmpty()) {
|
||||
ChapterTable
|
||||
.batchInsert(chaptersToInsert) { chapter ->
|
||||
this[ChapterTable.url] = chapter.url
|
||||
this[ChapterTable.name] = chapter.name
|
||||
this[ChapterTable.date_upload] = chapter.uploadDate
|
||||
this[ChapterTable.chapter_number] = chapter.chapterNumber
|
||||
this[ChapterTable.scanlator] = chapter.scanlator
|
||||
this[ChapterTable.sourceOrder] = chapter.index
|
||||
this[ChapterTable.fetchedAt] = chapter.fetchedAt
|
||||
this[ChapterTable.manga] = chapter.mangaId
|
||||
this[ChapterTable.realUrl] = chapter.realUrl
|
||||
this[ChapterTable.isRead] = false
|
||||
this[ChapterTable.isBookmarked] = false
|
||||
this[ChapterTable.isDownloaded] = false
|
||||
this[ChapterTable.lastModifiedAt] = chapter.lastModifiedAt
|
||||
this[ChapterTable.version] = chapter.version
|
||||
this[ChapterTable.pageCount] = -1
|
||||
|
||||
// is recognized chapter number
|
||||
if (chapter.chapterNumber >= 0f && chapter.chapterNumber in deletedChapterNumbers) {
|
||||
this[ChapterTable.isRead] = chapter.chapterNumber in deletedReadChapterNumbers
|
||||
this[ChapterTable.isBookmarked] = chapter.chapterNumber in deletedBookmarkedChapterNumbers
|
||||
|
||||
// Try to use the fetch date of the original entry to not pollute 'Updates' tab
|
||||
deletedChapterNumberDateFetchMap[chapter.chapterNumber]?.let {
|
||||
this[ChapterTable.fetchedAt] = it
|
||||
}
|
||||
|
||||
deletedDownloadedChapterNumberToChapter[chapter.chapterNumber]?.let {
|
||||
val hasDownloadedPages = it.pageCount > 0
|
||||
val isSameName = it.name == chapter.name
|
||||
val isSameScanlator = it.scanlator == chapter.scanlator
|
||||
|
||||
// Only preserve download status for chapters with the same name and of the same scanlator; otherwise,
|
||||
// the downloaded files won't be found anyway
|
||||
val isDownloadPreservable = hasDownloadedPages && isSameName && isSameScanlator
|
||||
if (isDownloadPreservable) {
|
||||
this[ChapterTable.isDownloaded] = true
|
||||
this[ChapterTable.pageCount] = it.pageCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}.forEach { insertedChapters.add(ChapterTable.toDataClass(it)) }
|
||||
}
|
||||
|
||||
if (chaptersToUpdate.isNotEmpty()) {
|
||||
BatchUpdateStatement(ChapterTable)
|
||||
.apply {
|
||||
chaptersToUpdate.forEach {
|
||||
addBatch(EntityID(it.id, ChapterTable))
|
||||
|
||||
val currentChapter = chaptersInDb.find { dbChapter -> dbChapter.id == it.id }!!
|
||||
|
||||
this[ChapterTable.name] = it.name
|
||||
this[ChapterTable.date_upload] = it.uploadDate
|
||||
this[ChapterTable.chapter_number] = it.chapterNumber
|
||||
this[ChapterTable.scanlator] = it.scanlator
|
||||
this[ChapterTable.sourceOrder] = it.index
|
||||
this[ChapterTable.realUrl] = it.realUrl
|
||||
this[ChapterTable.lastModifiedAt] = it.lastModifiedAt
|
||||
this[ChapterTable.version] = it.version
|
||||
this[ChapterTable.isDownloaded] = currentChapter.downloaded
|
||||
this[ChapterTable.pageCount] = currentChapter.pageCount
|
||||
|
||||
if (!currentChapter.downloaded) {
|
||||
return@forEach
|
||||
}
|
||||
|
||||
val isSameScanlator = currentChapter.scanlator == it.scanlator
|
||||
val isSameName = currentChapter.name == it.name
|
||||
|
||||
val isDownloadPreservable = isSameName && isSameScanlator
|
||||
if (!isDownloadPreservable) {
|
||||
this[ChapterTable.isDownloaded] = false
|
||||
this[ChapterTable.pageCount] = -1
|
||||
}
|
||||
}
|
||||
}.toExecutable()
|
||||
.execute(this@transaction)
|
||||
}
|
||||
|
||||
MangaTable.update({ MangaTable.id eq mangaId }) {
|
||||
it[chaptersLastFetchedAt] = Instant.now().epochSecond
|
||||
}
|
||||
}
|
||||
|
||||
if (manga.inLibrary) {
|
||||
downloadNewChapters(mangaId, currentLatestChapterNumber, numberOfCurrentChapters, insertedChapters)
|
||||
}
|
||||
|
||||
uniqueChapters
|
||||
updateChapterListDatabase(mangaEntry, chapters, source)
|
||||
}
|
||||
|
||||
return chapterList
|
||||
}
|
||||
|
||||
fun updateChapterListDatabase(
|
||||
mangaEntry: ResultRow,
|
||||
chapters: List<SChapter>,
|
||||
source: CatalogueSource,
|
||||
): List<SChapter> {
|
||||
val currentLatestChapterNumber = Manga.getLatestChapter(mangaEntry[MangaTable.id].value)?.chapterNumber ?: 0f
|
||||
val numberOfCurrentChapters = getCountOfMangaChapters(mangaEntry[MangaTable.id].value)
|
||||
// it's possible that the source returns a list containing chapters with the same url
|
||||
// once such duplicated chapters have been added, they aren't being removed anymore as long as there is
|
||||
// a chapter with the same url in the fetched chapter list, even if the duplicated chapter itself
|
||||
// does not exist anymore on the source
|
||||
val uniqueChapters = chapters.distinctBy { it.url }
|
||||
|
||||
if (uniqueChapters.isEmpty()) {
|
||||
throw Exception("No chapters found")
|
||||
}
|
||||
|
||||
// Recognize number for new chapters.
|
||||
val sManga =
|
||||
SManga.create().apply {
|
||||
url = mangaEntry[MangaTable.url]
|
||||
title = mangaEntry[MangaTable.title]
|
||||
thumbnail_url = mangaEntry[MangaTable.thumbnail_url]
|
||||
artist = mangaEntry[MangaTable.artist]
|
||||
author = mangaEntry[MangaTable.author]
|
||||
description = mangaEntry[MangaTable.description]
|
||||
genre = mangaEntry[MangaTable.genre]
|
||||
status = mangaEntry[MangaTable.status]
|
||||
update_strategy = UpdateStrategy.valueOf(mangaEntry[MangaTable.updateStrategy])
|
||||
memo = Json.decodeFromString(mangaEntry[MangaTable.memo])
|
||||
initialized = mangaEntry[MangaTable.initialized]
|
||||
}
|
||||
uniqueChapters.forEach { chapter ->
|
||||
(source as? HttpSource)?.prepareNewChapter(chapter, sManga)
|
||||
val chapterNumber =
|
||||
ChapterRecognition.parseChapterNumber(
|
||||
mangaEntry[MangaTable.title],
|
||||
chapter.name,
|
||||
chapter.chapter_number.toDouble(),
|
||||
)
|
||||
chapter.chapter_number = chapterNumber.toFloat()
|
||||
chapter.name = chapter.name.sanitize(mangaEntry[MangaTable.title])
|
||||
chapter.scanlator = chapter.scanlator?.ifBlank { null }?.trim()
|
||||
}
|
||||
|
||||
val now = Instant.now().epochSecond
|
||||
// Used to not set upload date of older chapters
|
||||
// to a higher value than newer chapters
|
||||
var maxSeenUploadDate = 0L
|
||||
|
||||
val chaptersInDb =
|
||||
transaction {
|
||||
ChapterTable
|
||||
.selectAll()
|
||||
.where { ChapterTable.manga eq mangaEntry[MangaTable.id].value }
|
||||
.map { ChapterTable.toDataClass(it) }
|
||||
.toList()
|
||||
}
|
||||
|
||||
// new chapters after they have been added to the database for auto downloads
|
||||
val insertedChapterIds = mutableListOf<Int>()
|
||||
|
||||
val chaptersToInsert = mutableListOf<ChapterDataClass>() // do not yet have an ID from the database
|
||||
val chaptersToUpdate = mutableListOf<ChapterDataClass>()
|
||||
|
||||
uniqueChapters.reversed().forEachIndexed { index, fetchedChapter ->
|
||||
val chapterEntry = chaptersInDb.find { it.url == fetchedChapter.url }
|
||||
|
||||
val chapterData =
|
||||
ChapterDataClass.fromSChapter(
|
||||
fetchedChapter,
|
||||
chapterEntry?.id ?: 0,
|
||||
index + 1,
|
||||
now,
|
||||
mangaEntry[MangaTable.id].value,
|
||||
runCatching {
|
||||
(source as? HttpSource)?.getChapterUrl(fetchedChapter)
|
||||
}.getOrNull(),
|
||||
)
|
||||
|
||||
if (chapterEntry == null) {
|
||||
val newChapterData =
|
||||
if (chapterData.uploadDate == 0L) {
|
||||
val altDateUpload = if (maxSeenUploadDate == 0L) now else maxSeenUploadDate
|
||||
chapterData.copy(uploadDate = altDateUpload)
|
||||
} else {
|
||||
maxSeenUploadDate = max(maxSeenUploadDate, chapterData.uploadDate)
|
||||
chapterData
|
||||
}
|
||||
chaptersToInsert.add(newChapterData)
|
||||
} else {
|
||||
val newChapterData =
|
||||
if (chapterData.uploadDate == 0L) {
|
||||
chapterData.copy(uploadDate = chapterEntry.uploadDate)
|
||||
} else {
|
||||
chapterData
|
||||
}
|
||||
chaptersToUpdate.add(newChapterData)
|
||||
}
|
||||
}
|
||||
|
||||
val deletedChapterNumbers = TreeSet<Float>()
|
||||
val deletedReadChapterNumbers = TreeSet<Float>()
|
||||
val deletedBookmarkedChapterNumbers = TreeSet<Float>()
|
||||
val deletedDownloadedChapterNumberToChapter = mutableMapOf<Float, ChapterDataClass>()
|
||||
val deletedChapterNumberDateFetchMap = mutableMapOf<Float, Long>()
|
||||
|
||||
// clear any orphaned/duplicate chapters that are in the db but not in `chapterList`
|
||||
val chapterUrls = uniqueChapters.map { it.url }.toSet()
|
||||
|
||||
val chaptersIdsToDelete =
|
||||
chaptersInDb.mapNotNull { dbChapter ->
|
||||
if (!chapterUrls.contains(dbChapter.url)) {
|
||||
if (dbChapter.read) deletedReadChapterNumbers.add(dbChapter.chapterNumber)
|
||||
if (dbChapter.bookmarked) deletedBookmarkedChapterNumbers.add(dbChapter.chapterNumber)
|
||||
if (dbChapter.downloaded) deletedDownloadedChapterNumberToChapter[dbChapter.chapterNumber] = dbChapter
|
||||
deletedChapterNumbers.add(dbChapter.chapterNumber)
|
||||
deletedChapterNumberDateFetchMap[dbChapter.chapterNumber] = dbChapter.fetchedAt
|
||||
dbChapter.id
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
transaction {
|
||||
// we got some clean up due
|
||||
if (chaptersIdsToDelete.isNotEmpty()) {
|
||||
DownloadManager.dequeue(chaptersIdsToDelete)
|
||||
PageTable.deleteWhere { chapter inList chaptersIdsToDelete }
|
||||
ChapterTable.deleteWhere { id inList chaptersIdsToDelete }
|
||||
}
|
||||
|
||||
if (chaptersToInsert.isNotEmpty()) {
|
||||
ChapterTable
|
||||
.batchInsert(chaptersToInsert) { chapter ->
|
||||
this[ChapterTable.url] = chapter.url
|
||||
this[ChapterTable.name] = chapter.name
|
||||
this[ChapterTable.date_upload] = chapter.uploadDate
|
||||
this[ChapterTable.chapter_number] = chapter.chapterNumber
|
||||
this[ChapterTable.scanlator] = chapter.scanlator
|
||||
this[ChapterTable.sourceOrder] = chapter.index
|
||||
this[ChapterTable.fetchedAt] = chapter.fetchedAt
|
||||
this[ChapterTable.manga] = chapter.mangaId
|
||||
this[ChapterTable.realUrl] = chapter.realUrl
|
||||
this[ChapterTable.memo] = Json.encodeToString(chapter.memo)
|
||||
this[ChapterTable.isRead] = false
|
||||
this[ChapterTable.isBookmarked] = false
|
||||
this[ChapterTable.isDownloaded] = false
|
||||
this[ChapterTable.lastModifiedAt] = chapter.lastModifiedAt
|
||||
this[ChapterTable.version] = chapter.version
|
||||
this[ChapterTable.pageCount] = -1
|
||||
|
||||
// is recognized chapter number
|
||||
if (chapter.chapterNumber >= 0f && chapter.chapterNumber in deletedChapterNumbers) {
|
||||
this[ChapterTable.isRead] = chapter.chapterNumber in deletedReadChapterNumbers
|
||||
this[ChapterTable.isBookmarked] = chapter.chapterNumber in deletedBookmarkedChapterNumbers
|
||||
|
||||
// Try to use the fetch date of the original entry to not pollute 'Updates' tab
|
||||
deletedChapterNumberDateFetchMap[chapter.chapterNumber]?.let {
|
||||
this[ChapterTable.fetchedAt] = it
|
||||
}
|
||||
|
||||
deletedDownloadedChapterNumberToChapter[chapter.chapterNumber]?.let {
|
||||
val hasDownloadedPages = it.pageCount > 0
|
||||
val isSameName = it.name == chapter.name
|
||||
val isSameScanlator = it.scanlator == chapter.scanlator
|
||||
|
||||
// Only preserve download status for chapters with the same name and of the same scanlator; otherwise,
|
||||
// the downloaded files won't be found anyway
|
||||
val isDownloadPreservable = hasDownloadedPages && isSameName && isSameScanlator
|
||||
if (isDownloadPreservable) {
|
||||
this[ChapterTable.isDownloaded] = true
|
||||
this[ChapterTable.pageCount] = it.pageCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}.forEach { insertedChapterIds.add(it[ChapterTable.id].value) }
|
||||
}
|
||||
|
||||
if (chaptersToUpdate.isNotEmpty()) {
|
||||
BatchUpdateStatement(ChapterTable)
|
||||
.apply {
|
||||
chaptersToUpdate.forEach {
|
||||
addBatch(EntityID(it.id, ChapterTable))
|
||||
|
||||
val currentChapter = chaptersInDb.find { dbChapter -> dbChapter.id == it.id }!!
|
||||
|
||||
this[ChapterTable.name] = it.name
|
||||
this[ChapterTable.date_upload] = it.uploadDate
|
||||
this[ChapterTable.chapter_number] = it.chapterNumber
|
||||
this[ChapterTable.scanlator] = it.scanlator
|
||||
this[ChapterTable.sourceOrder] = it.index
|
||||
this[ChapterTable.realUrl] = it.realUrl
|
||||
this[ChapterTable.lastModifiedAt] = it.lastModifiedAt
|
||||
this[ChapterTable.version] = it.version
|
||||
this[ChapterTable.memo] = Json.encodeToString(it.memo)
|
||||
this[ChapterTable.isDownloaded] = currentChapter.downloaded
|
||||
this[ChapterTable.pageCount] = currentChapter.pageCount
|
||||
|
||||
if (!currentChapter.downloaded) {
|
||||
return@forEach
|
||||
}
|
||||
|
||||
val isSameScanlator = currentChapter.scanlator == it.scanlator
|
||||
val isSameName = currentChapter.name == it.name
|
||||
|
||||
val isDownloadPreservable = isSameName && isSameScanlator
|
||||
if (!isDownloadPreservable) {
|
||||
this[ChapterTable.isDownloaded] = false
|
||||
this[ChapterTable.pageCount] = -1
|
||||
}
|
||||
}
|
||||
}.toExecutable()
|
||||
.execute(this@transaction)
|
||||
}
|
||||
|
||||
MangaTable.update({ MangaTable.id eq mangaEntry[MangaTable.id].value }) {
|
||||
it[chaptersLastFetchedAt] = Instant.now().epochSecond
|
||||
}
|
||||
}
|
||||
|
||||
if (mangaEntry[MangaTable.inLibrary]) {
|
||||
// We have to query the inserted chapters to get the up-to-date data. I.e. "last_modified_at" is not returned by the insert statement, due to being set by a DB trigger
|
||||
val insertedChapters =
|
||||
transaction {
|
||||
ChapterTable.selectAll().where { ChapterTable.id inList insertedChapterIds }.map(
|
||||
ChapterTable::toDataClass,
|
||||
)
|
||||
}
|
||||
downloadNewChapters(
|
||||
mangaEntry[MangaTable.id].value,
|
||||
currentLatestChapterNumber,
|
||||
numberOfCurrentChapters,
|
||||
insertedChapters,
|
||||
)
|
||||
}
|
||||
|
||||
return uniqueChapters
|
||||
}
|
||||
|
||||
private fun downloadNewChapters(
|
||||
mangaId: Int,
|
||||
prevLatestChapterNumber: Float,
|
||||
@@ -611,7 +624,7 @@ object Chapter {
|
||||
.withDefault { emptyMap() }
|
||||
}
|
||||
|
||||
fun getChapterMetaMap(chapter: EntityID<Int>): Map<String, String> =
|
||||
fun getChapterMetaMap(chapter: Int): Map<String, String> =
|
||||
transaction {
|
||||
ChapterMetaTable
|
||||
.selectAll()
|
||||
|
||||
@@ -16,6 +16,7 @@ import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
import xyz.nulldev.androidcompat.util.SafePath
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
@@ -64,6 +65,11 @@ object ChapterDownloadHelper {
|
||||
chapterId: Int,
|
||||
): Pair<InputStream, Long> = provider(mangaId, chapterId).getAsArchiveStream()
|
||||
|
||||
fun getChapterArchiveSize(
|
||||
mangaId: Int,
|
||||
chapterId: Int,
|
||||
): Long = provider(mangaId, chapterId).getArchiveSize()
|
||||
|
||||
private fun getChapterWithCbzFileName(chapterId: Int): Pair<ChapterDataClass, String> =
|
||||
transaction {
|
||||
val row =
|
||||
@@ -71,13 +77,46 @@ object ChapterDownloadHelper {
|
||||
.select(ChapterTable.columns + MangaTable.columns)
|
||||
.where { ChapterTable.id eq chapterId }
|
||||
.firstOrNull() ?: throw IllegalArgumentException("ChapterId $chapterId not found")
|
||||
|
||||
val chapter = ChapterTable.toDataClass(row)
|
||||
val mangaTitle = row[MangaTable.title]
|
||||
val mangaTitle = row[MangaTable.title].trim()
|
||||
|
||||
val scanlatorPart = chapter.scanlator?.let { "[$it] " } ?: ""
|
||||
val fileName = "$mangaTitle - $scanlatorPart${chapter.name}.cbz"
|
||||
val scanlatorName = chapter.scanlator?.trim()?.takeIf { it.isNotEmpty() }
|
||||
val chapterName = chapter.name.trim().takeIf { it.isNotEmpty() }
|
||||
|
||||
Pair(chapter, fileName)
|
||||
val fileName =
|
||||
buildString {
|
||||
append(mangaTitle)
|
||||
append(" - ")
|
||||
|
||||
if (chapterName != null) {
|
||||
append(chapterName)
|
||||
} else if (chapter.chapterNumber >= 0f) {
|
||||
// chapterNumber is stored as Float, drop .0 for whole numbers.
|
||||
val formatNumber =
|
||||
if (chapter.chapterNumber % 1 == 0f) {
|
||||
chapter.chapterNumber.toInt().toString()
|
||||
} else {
|
||||
chapter.chapterNumber.toString()
|
||||
}
|
||||
append("#$formatNumber")
|
||||
} else {
|
||||
// Fallback when neither name nor valid chapter number exists
|
||||
append("#${chapter.index}")
|
||||
}
|
||||
|
||||
if (scanlatorName != null) {
|
||||
append(" [")
|
||||
append(scanlatorName)
|
||||
append("]")
|
||||
}
|
||||
append(".cbz")
|
||||
}
|
||||
|
||||
// Sanitize filename for OS compatibility
|
||||
val safeFileName = SafePath.buildValidFilename(fileName)
|
||||
|
||||
Pair(chapter, safeFileName)
|
||||
}
|
||||
|
||||
fun getCbzForDownload(
|
||||
|
||||
@@ -11,13 +11,20 @@ import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.HttpException
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.local.LocalSource
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.SMangaUpdate
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import io.github.oshai.kotlinlogging.KLogger
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.github.reactivecircus.cache4k.Cache
|
||||
import io.javalin.http.HttpStatus
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.CacheControl
|
||||
import okhttp3.Response
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
@@ -32,10 +39,7 @@ import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.statements.toExecutable
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import org.jetbrains.exposed.v1.jdbc.update
|
||||
import suwayomi.tachidesk.manga.impl.MangaList.proxyThumbnailUrl
|
||||
import suwayomi.tachidesk.manga.impl.Source.getSource
|
||||
import suwayomi.tachidesk.manga.impl.download.fileProvider.impl.MissingThumbnailException
|
||||
import suwayomi.tachidesk.manga.impl.track.Track
|
||||
import suwayomi.tachidesk.manga.impl.util.network.await
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrNull
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrStub
|
||||
@@ -47,10 +51,8 @@ import suwayomi.tachidesk.manga.impl.util.updateMangaDownloadDir
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ChapterDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.IncludeOrExclude
|
||||
import suwayomi.tachidesk.manga.model.dataclass.MangaDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.toGenreList
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaMetaTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaStatus
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
import suwayomi.tachidesk.server.ApplicationDirs
|
||||
@@ -59,10 +61,17 @@ import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.time.Instant
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
||||
private val logger = KotlinLogging.logger { }
|
||||
|
||||
object Manga {
|
||||
val mangaInfoMutex: Cache<Int, Mutex> =
|
||||
Cache
|
||||
.Builder<Int, Mutex>()
|
||||
.expireAfterAccess(10.minutes)
|
||||
.build()
|
||||
|
||||
suspend fun getManga(
|
||||
mangaId: Int,
|
||||
onlineFetch: Boolean = false,
|
||||
@@ -70,64 +79,118 @@ object Manga {
|
||||
var mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||
|
||||
return if (!onlineFetch && mangaEntry[MangaTable.initialized]) {
|
||||
getMangaDataClass(mangaId, mangaEntry)
|
||||
MangaTable.toDataClass(mangaEntry)
|
||||
} else { // initialize manga
|
||||
val sManga = fetchManga(mangaId) ?: return getMangaDataClass(mangaId, mangaEntry)
|
||||
updateMangaAndChapters(mangaId, updateChapters = false)
|
||||
|
||||
mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||
|
||||
MangaDataClass(
|
||||
id = mangaId,
|
||||
sourceId = mangaEntry[MangaTable.sourceReference].toString(),
|
||||
url = mangaEntry[MangaTable.url],
|
||||
title = mangaEntry[MangaTable.title],
|
||||
thumbnailUrl = proxyThumbnailUrl(mangaId),
|
||||
thumbnailUrlLastFetched = mangaEntry[MangaTable.thumbnailUrlLastFetched],
|
||||
initialized = true,
|
||||
artist = sManga.artist,
|
||||
author = sManga.author,
|
||||
description = sManga.description,
|
||||
genre = sManga.genre.toGenreList(),
|
||||
status = MangaStatus.valueOf(sManga.status).name,
|
||||
inLibrary = mangaEntry[MangaTable.inLibrary],
|
||||
inLibraryAt = mangaEntry[MangaTable.inLibraryAt],
|
||||
source = getSource(mangaEntry[MangaTable.sourceReference]),
|
||||
meta = getMangaMetaMap(mangaId),
|
||||
realUrl = mangaEntry[MangaTable.realUrl],
|
||||
lastFetchedAt = mangaEntry[MangaTable.lastFetchedAt],
|
||||
chaptersLastFetchedAt = mangaEntry[MangaTable.chaptersLastFetchedAt],
|
||||
updateStrategy = UpdateStrategy.valueOf(mangaEntry[MangaTable.updateStrategy]),
|
||||
freshData = true,
|
||||
trackers = Track.getTrackRecordsByMangaId(mangaId),
|
||||
lastModifiedAt = mangaEntry[MangaTable.lastModifiedAt],
|
||||
version = mangaEntry[MangaTable.version],
|
||||
)
|
||||
MangaTable.toDataClass(mangaEntry).copy(freshData = true)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun fetchManga(mangaId: Int): SManga? {
|
||||
val mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||
|
||||
val source =
|
||||
getCatalogueSourceOrNull(mangaEntry[MangaTable.sourceReference])
|
||||
?: return null
|
||||
suspend fun fetchMangaAndChapters(
|
||||
mangaEntry: ResultRow,
|
||||
source: CatalogueSource,
|
||||
fetchDetails: Boolean,
|
||||
fetchChapters: Boolean,
|
||||
): SMangaUpdate {
|
||||
val sManga =
|
||||
source.getMangaDetails(
|
||||
SManga.create().apply {
|
||||
url = mangaEntry[MangaTable.url]
|
||||
title = mangaEntry[MangaTable.title]
|
||||
thumbnail_url = mangaEntry[MangaTable.thumbnail_url]
|
||||
artist = mangaEntry[MangaTable.artist]
|
||||
author = mangaEntry[MangaTable.author]
|
||||
description = mangaEntry[MangaTable.description]
|
||||
genre = mangaEntry[MangaTable.genre]
|
||||
status = mangaEntry[MangaTable.status]
|
||||
update_strategy = UpdateStrategy.valueOf(mangaEntry[MangaTable.updateStrategy])
|
||||
},
|
||||
)
|
||||
SManga.create().apply {
|
||||
url = mangaEntry[MangaTable.url]
|
||||
title = mangaEntry[MangaTable.title]
|
||||
thumbnail_url = mangaEntry[MangaTable.thumbnail_url]
|
||||
artist = mangaEntry[MangaTable.artist]
|
||||
author = mangaEntry[MangaTable.author]
|
||||
description = mangaEntry[MangaTable.description]
|
||||
genre = mangaEntry[MangaTable.genre]
|
||||
status = mangaEntry[MangaTable.status]
|
||||
update_strategy = UpdateStrategy.valueOf(mangaEntry[MangaTable.updateStrategy])
|
||||
memo = Json.decodeFromString(mangaEntry[MangaTable.memo])
|
||||
initialized = mangaEntry[MangaTable.initialized]
|
||||
}
|
||||
val sChapters =
|
||||
transaction {
|
||||
ChapterTable
|
||||
.selectAll()
|
||||
.where { ChapterTable.manga eq mangaEntry[MangaTable.id] }
|
||||
.orderBy(ChapterTable.sourceOrder to SortOrder.DESC)
|
||||
.map {
|
||||
SChapter.create().apply {
|
||||
url = it[ChapterTable.url]
|
||||
name = it[ChapterTable.name]
|
||||
chapter_number = it[ChapterTable.chapter_number]
|
||||
scanlator = it[ChapterTable.scanlator]
|
||||
date_upload = it[ChapterTable.date_upload]
|
||||
memo = Json.decodeFromString(it[ChapterTable.memo])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return source.getMangaUpdate(
|
||||
sManga,
|
||||
sChapters,
|
||||
fetchDetails = fetchDetails,
|
||||
fetchChapters = fetchChapters,
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun fetchManga(mangaId: Int): SManga? {
|
||||
return mangaInfoMutex.get(mangaId) { Mutex() }.withLock {
|
||||
val mangaEntry =
|
||||
transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||
val source = getCatalogueSourceOrNull(mangaEntry[MangaTable.sourceReference]) ?: return null
|
||||
val sManga =
|
||||
fetchMangaAndChapters(
|
||||
mangaEntry,
|
||||
source,
|
||||
fetchDetails = true,
|
||||
fetchChapters = false,
|
||||
).manga
|
||||
|
||||
updateMangaDatabase(mangaEntry, source, sManga)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateMangaAndChapters(
|
||||
mangaId: Int,
|
||||
updateManga: Boolean = true,
|
||||
updateChapters: Boolean = true,
|
||||
) {
|
||||
mangaInfoMutex.get(mangaId) { Mutex() }.withLock {
|
||||
var mangaEntry =
|
||||
transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||
val source =
|
||||
getCatalogueSourceOrNull(mangaEntry[MangaTable.sourceReference])
|
||||
?: throw NullPointerException("Missing source ${mangaEntry[MangaTable.sourceReference]}")
|
||||
val mangaUpdate =
|
||||
fetchMangaAndChapters(
|
||||
mangaEntry,
|
||||
source,
|
||||
fetchDetails = updateManga,
|
||||
fetchChapters = updateChapters,
|
||||
)
|
||||
|
||||
if (updateManga) {
|
||||
updateMangaDatabase(mangaEntry, source, mangaUpdate.manga)
|
||||
mangaEntry =
|
||||
transaction {
|
||||
MangaTable.selectAll().where { MangaTable.id eq mangaId }.first()
|
||||
}
|
||||
}
|
||||
if (updateChapters) {
|
||||
Chapter.updateChapterListDatabase(mangaEntry, mangaUpdate.chapters, source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateMangaDatabase(
|
||||
mangaEntry: ResultRow,
|
||||
source: CatalogueSource,
|
||||
sManga: SManga,
|
||||
): SManga {
|
||||
transaction {
|
||||
MangaTable.update({ MangaTable.id eq mangaId }) {
|
||||
MangaTable.update({ MangaTable.id eq mangaEntry[MangaTable.id] }) {
|
||||
val remoteTitle =
|
||||
try {
|
||||
sManga.title
|
||||
@@ -152,7 +215,7 @@ object Manga {
|
||||
if (!sManga.thumbnail_url.isNullOrEmpty()) {
|
||||
it[MangaTable.thumbnail_url] = sManga.thumbnail_url
|
||||
it[MangaTable.thumbnailUrlLastFetched] = Instant.now().epochSecond
|
||||
clearThumbnail(mangaId)
|
||||
clearThumbnail(mangaEntry[MangaTable.id].value)
|
||||
}
|
||||
|
||||
it[MangaTable.realUrl] =
|
||||
@@ -213,45 +276,15 @@ object Manga {
|
||||
.orderBy(ChapterTable.sourceOrder to SortOrder.DESC)
|
||||
.firstOrNull { it[ChapterTable.isRead] }
|
||||
|
||||
mangaDaaClass.unreadCount = unreadCount
|
||||
mangaDaaClass.downloadCount = downloadCount
|
||||
mangaDaaClass.chapterCount = chapterCount
|
||||
mangaDaaClass.lastChapterRead = lastChapterRead?.let { ChapterTable.toDataClass(it) }
|
||||
|
||||
mangaDaaClass
|
||||
mangaDaaClass.copy(
|
||||
unreadCount = unreadCount,
|
||||
downloadCount = downloadCount,
|
||||
chapterCount = chapterCount,
|
||||
lastChapterRead = lastChapterRead?.let { ChapterTable.toDataClass(it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMangaDataClass(
|
||||
mangaId: Int,
|
||||
mangaEntry: ResultRow,
|
||||
) = MangaDataClass(
|
||||
id = mangaId,
|
||||
sourceId = mangaEntry[MangaTable.sourceReference].toString(),
|
||||
url = mangaEntry[MangaTable.url],
|
||||
title = mangaEntry[MangaTable.title],
|
||||
thumbnailUrl = proxyThumbnailUrl(mangaId),
|
||||
thumbnailUrlLastFetched = mangaEntry[MangaTable.thumbnailUrlLastFetched],
|
||||
initialized = true,
|
||||
artist = mangaEntry[MangaTable.artist],
|
||||
author = mangaEntry[MangaTable.author],
|
||||
description = mangaEntry[MangaTable.description],
|
||||
genre = mangaEntry[MangaTable.genre].toGenreList(),
|
||||
status = MangaStatus.valueOf(mangaEntry[MangaTable.status]).name,
|
||||
inLibrary = mangaEntry[MangaTable.inLibrary],
|
||||
inLibraryAt = mangaEntry[MangaTable.inLibraryAt],
|
||||
source = getSource(mangaEntry[MangaTable.sourceReference]),
|
||||
meta = getMangaMetaMap(mangaId),
|
||||
realUrl = mangaEntry[MangaTable.realUrl],
|
||||
lastFetchedAt = mangaEntry[MangaTable.lastFetchedAt],
|
||||
chaptersLastFetchedAt = mangaEntry[MangaTable.chaptersLastFetchedAt],
|
||||
updateStrategy = UpdateStrategy.valueOf(mangaEntry[MangaTable.updateStrategy]),
|
||||
freshData = false,
|
||||
trackers = Track.getTrackRecordsByMangaId(mangaId),
|
||||
lastModifiedAt = mangaEntry[MangaTable.lastModifiedAt],
|
||||
version = mangaEntry[MangaTable.version],
|
||||
)
|
||||
|
||||
fun getMangaMetaMap(mangaId: Int): Map<String, String> =
|
||||
transaction {
|
||||
MangaMetaTable
|
||||
|
||||
@@ -9,6 +9,7 @@ package suwayomi.tachidesk.manga.impl
|
||||
|
||||
import eu.kanade.tachiyomi.source.local.LocalSource
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.v1.core.and
|
||||
import org.jetbrains.exposed.v1.core.dao.id.EntityID
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
@@ -75,6 +76,7 @@ object MangaList {
|
||||
this[MangaTable.status] = it.status
|
||||
this[MangaTable.thumbnail_url] = it.thumbnail_url
|
||||
this[MangaTable.updateStrategy] = it.update_strategy.name
|
||||
this[MangaTable.memo] = Json.encodeToString(it.memo)
|
||||
|
||||
this[MangaTable.sourceReference] = sourceId
|
||||
}.associate { Pair(it[MangaTable.url], it[MangaTable.id].value) }
|
||||
@@ -103,6 +105,7 @@ object MangaList {
|
||||
this[MangaTable.status] = sManga.status
|
||||
this[MangaTable.thumbnail_url] = sManga.thumbnail_url ?: manga[MangaTable.thumbnail_url]
|
||||
this[MangaTable.updateStrategy] = sManga.update_strategy.name
|
||||
this[MangaTable.memo] = Json.encodeToString(sManga.memo)
|
||||
if (!sManga.thumbnail_url.isNullOrEmpty() && manga[MangaTable.thumbnail_url] != sManga.thumbnail_url) {
|
||||
this[MangaTable.thumbnailUrlLastFetched] = Instant.now().epochSecond
|
||||
Manga.clearThumbnail(manga[MangaTable.id].value)
|
||||
|
||||
@@ -25,10 +25,11 @@ import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.statements.toExecutable
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.manga.impl.Source.preferenceScreenMap
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension.getExtensionIconUrl
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension.proxyExtensionIconUrl
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrNull
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.getCatalogueSourceOrStub
|
||||
import suwayomi.tachidesk.manga.impl.util.source.GetCatalogueSource.unregisterCatalogueSource
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
import suwayomi.tachidesk.manga.model.dataclass.SourceDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionTable
|
||||
import suwayomi.tachidesk.manga.model.table.SourceMetaTable
|
||||
@@ -49,10 +50,10 @@ object Source {
|
||||
id = it[SourceTable.id].value.toString(),
|
||||
name = it[SourceTable.name],
|
||||
lang = it[SourceTable.lang],
|
||||
iconUrl = getExtensionIconUrl(sourceExtension[ExtensionTable.apkName]),
|
||||
iconUrl = proxyExtensionIconUrl(sourceExtension[ExtensionTable.pkgName]),
|
||||
supportsLatest = catalogueSource.supportsLatest,
|
||||
isConfigurable = catalogueSource is ConfigurableSource,
|
||||
isNsfw = it[SourceTable.isNsfw],
|
||||
isNsfw = it[SourceTable.contentWarning] >= ContentWarning.MIXED.ordinal,
|
||||
displayName = catalogueSource.toString(),
|
||||
baseUrl = runCatching { (catalogueSource as? HttpSource)?.baseUrl }.getOrNull(),
|
||||
)
|
||||
@@ -70,13 +71,10 @@ object Source {
|
||||
id = sourceId.toString(),
|
||||
name = source[SourceTable.name],
|
||||
lang = source[SourceTable.lang],
|
||||
iconUrl =
|
||||
getExtensionIconUrl(
|
||||
extension[ExtensionTable.apkName],
|
||||
),
|
||||
iconUrl = proxyExtensionIconUrl(extension[ExtensionTable.pkgName]),
|
||||
supportsLatest = catalogueSource.supportsLatest,
|
||||
isConfigurable = catalogueSource is ConfigurableSource,
|
||||
isNsfw = source[SourceTable.isNsfw],
|
||||
isNsfw = source[SourceTable.contentWarning] >= ContentWarning.MIXED.ordinal,
|
||||
displayName = catalogueSource.toString(),
|
||||
baseUrl = runCatching { (catalogueSource as? HttpSource)?.baseUrl }.getOrNull(),
|
||||
)
|
||||
|
||||
@@ -148,13 +148,11 @@ object ProtoBackupExport : ProtoBackupBase() {
|
||||
|
||||
fun createBackup(flags: BackupFlags): InputStream {
|
||||
// Create root object
|
||||
|
||||
val backupMangas = BackupMangaHandler.backup(flags)
|
||||
|
||||
val backup: Backup =
|
||||
transaction {
|
||||
val backupMangas = BackupMangaHandler.backup(flags)
|
||||
Backup(
|
||||
BackupMangaHandler.backup(flags),
|
||||
backupMangas,
|
||||
BackupCategoryHandler.backup(flags),
|
||||
BackupSourceHandler.backup(backupMangas, flags),
|
||||
BackupGlobalMetaHandler.backup(flags),
|
||||
|
||||
@@ -8,6 +8,7 @@ package suwayomi.tachidesk.manga.impl.backup.proto.handlers
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import org.jetbrains.exposed.v1.core.SortOrder
|
||||
import org.jetbrains.exposed.v1.core.and
|
||||
@@ -38,7 +39,6 @@ import suwayomi.tachidesk.manga.model.dataclass.TrackRecordDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import suwayomi.tachidesk.manga.model.table.MangaStatus
|
||||
import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
import suwayomi.tachidesk.server.database.dbTransaction
|
||||
import java.util.Date
|
||||
import kotlin.math.max
|
||||
@@ -77,6 +77,8 @@ object BackupMangaHandler {
|
||||
updateStrategy = UpdateStrategy.valueOf(mangaRow[MangaTable.updateStrategy]),
|
||||
lastModifiedAt = mangaRow[MangaTable.lastModifiedAt],
|
||||
version = mangaRow[MangaTable.version],
|
||||
initialized = mangaRow[MangaTable.initialized],
|
||||
memo = Json.encodeToString(mangaRow[MangaTable.memo]).encodeToByteArray(),
|
||||
)
|
||||
|
||||
val mangaId = mangaRow[MangaTable.id].value
|
||||
@@ -92,31 +94,31 @@ object BackupMangaHandler {
|
||||
.selectAll()
|
||||
.where { ChapterTable.manga eq mangaId }
|
||||
.orderBy(ChapterTable.sourceOrder to SortOrder.DESC)
|
||||
.map {
|
||||
ChapterTable.toDataClass(it)
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
|
||||
if (flags.includeChapters) {
|
||||
val chapterToMeta = Chapter.getChaptersMetaMaps(chapters.map { it.id })
|
||||
val chapterToMeta =
|
||||
Chapter.getChaptersMetaMaps(chapters.map { it[ChapterTable.id].value })
|
||||
|
||||
backupManga.chapters =
|
||||
chapters.map {
|
||||
BackupChapter(
|
||||
it.url,
|
||||
it.name,
|
||||
it.scanlator,
|
||||
it.read,
|
||||
it.bookmarked,
|
||||
it.lastPageRead,
|
||||
it.fetchedAt.seconds.inWholeMilliseconds,
|
||||
it.uploadDate,
|
||||
it.chapterNumber,
|
||||
chapters.size - it.index,
|
||||
it.lastModifiedAt,
|
||||
it.version,
|
||||
url = it[ChapterTable.url],
|
||||
name = it[ChapterTable.name],
|
||||
scanlator = it[ChapterTable.scanlator],
|
||||
read = it[ChapterTable.isRead],
|
||||
bookmark = it[ChapterTable.isBookmarked],
|
||||
lastPageRead = it[ChapterTable.lastPageRead],
|
||||
dateFetch = it[ChapterTable.fetchedAt].seconds.inWholeMilliseconds,
|
||||
dateUpload = it[ChapterTable.date_upload],
|
||||
chapterNumber = it[ChapterTable.chapter_number],
|
||||
sourceOrder = chapters.size - it[ChapterTable.sourceOrder],
|
||||
lastModifiedAt = it[ChapterTable.lastModifiedAt],
|
||||
version = it[ChapterTable.version],
|
||||
).apply {
|
||||
if (flags.includeClientData) {
|
||||
this.meta = chapterToMeta[it.id] ?: emptyMap()
|
||||
this.meta = chapterToMeta[it[ChapterTable.id].value] ?: emptyMap()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,10 +126,10 @@ object BackupMangaHandler {
|
||||
if (flags.includeHistory) {
|
||||
backupManga.history =
|
||||
chapters.mapNotNull {
|
||||
if (it.lastReadAt > 0) {
|
||||
if (it[ChapterTable.lastReadAt] > 0) {
|
||||
BackupHistory(
|
||||
url = it.url,
|
||||
lastRead = it.lastReadAt.seconds.inWholeMilliseconds,
|
||||
url = it[ChapterTable.url],
|
||||
lastRead = it[ChapterTable.lastReadAt].seconds.inWholeMilliseconds,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -239,6 +241,7 @@ object BackupMangaHandler {
|
||||
|
||||
it[lastModifiedAt] = manga.lastModifiedAt
|
||||
it[version] = manga.version
|
||||
it[memo] = manga.memo.decodeToString()
|
||||
}.value
|
||||
} else {
|
||||
val dbMangaId = dbManga[MangaTable.id].value
|
||||
@@ -261,6 +264,7 @@ object BackupMangaHandler {
|
||||
|
||||
it[lastModifiedAt] = manga.lastModifiedAt
|
||||
it[version] = manga.version
|
||||
it[memo] = manga.memo.decodeToString()
|
||||
}
|
||||
|
||||
dbMangaId
|
||||
@@ -352,6 +356,7 @@ object BackupMangaHandler {
|
||||
|
||||
this[ChapterTable.lastModifiedAt] = chapter.lastModifiedAt
|
||||
this[ChapterTable.version] = chapter.version
|
||||
this[ChapterTable.memo] = chapter.memo.decodeToString()
|
||||
}.map { it[ChapterTable.id].value }
|
||||
} else {
|
||||
emptyList()
|
||||
|
||||
@@ -2,6 +2,7 @@ package suwayomi.tachidesk.manga.impl.backup.proto.models
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.protobuf.ProtoNumber
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.JsonObjectEmptyBytes
|
||||
|
||||
@Serializable
|
||||
data class BackupChapter(
|
||||
@@ -22,6 +23,7 @@ data class BackupChapter(
|
||||
// syncyomi
|
||||
@ProtoNumber(11) var lastModifiedAt: Long = 0,
|
||||
@ProtoNumber(12) var version: Long = 0,
|
||||
@ProtoNumber(13) var memo: ByteArray = JsonObjectEmptyBytes,
|
||||
// suwayomi
|
||||
@ProtoNumber(9000) var meta: Map<String, String> = emptyMap(),
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ package suwayomi.tachidesk.manga.impl.backup.proto.models
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.protobuf.ProtoNumber
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.JsonObjectEmptyBytes
|
||||
|
||||
@Serializable
|
||||
data class BackupManga(
|
||||
@@ -37,6 +38,8 @@ data class BackupManga(
|
||||
// syncyomi
|
||||
@ProtoNumber(106) var lastModifiedAt: Long = 0,
|
||||
@ProtoNumber(109) var version: Long = 0,
|
||||
@ProtoNumber(111) var initialized: Boolean = false,
|
||||
@ProtoNumber(13) var memo: ByteArray = JsonObjectEmptyBytes,
|
||||
// suwayomi
|
||||
@ProtoNumber(9000) var meta: Map<String, String> = emptyMap(),
|
||||
)
|
||||
|
||||
@@ -31,6 +31,88 @@ import suwayomi.tachidesk.manga.model.table.PageTable
|
||||
import suwayomi.tachidesk.manga.model.table.toDataClass
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
||||
/**
|
||||
* Updates chapter download status and page count in the database if they differ from the file system.
|
||||
*/
|
||||
fun updateChapterPersistence(
|
||||
chapterId: Int,
|
||||
isMarkedAsDownloaded: Boolean,
|
||||
dbPageCount: Int,
|
||||
downloadPageCount: Int,
|
||||
lastPageRead: Int,
|
||||
logger: KLogger,
|
||||
): Boolean {
|
||||
if (isMarkedAsDownloaded && dbPageCount == downloadPageCount) {
|
||||
return false
|
||||
}
|
||||
|
||||
return transaction {
|
||||
var needsUpdate = false
|
||||
if (!isMarkedAsDownloaded) {
|
||||
logger.debug { "mark as downloaded" }
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
it[isDownloaded] = true
|
||||
}
|
||||
needsUpdate = true
|
||||
}
|
||||
|
||||
if (dbPageCount != downloadPageCount) {
|
||||
logger.debug { "use page count of downloaded chapter" }
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
it[pageCount] = downloadPageCount
|
||||
it[ChapterTable.lastPageRead] = lastPageRead.coerceAtMost(downloadPageCount - 1).coerceAtLeast(0)
|
||||
}
|
||||
needsUpdate = true
|
||||
}
|
||||
needsUpdate
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun refreshChapterPageList(
|
||||
mangaId: Int,
|
||||
chapterId: Int,
|
||||
existingChapterEntry: ResultRow? = null,
|
||||
): Int {
|
||||
val mutex = mutexByChapterId.get(chapterId) { Mutex() }
|
||||
return mutex.withLock {
|
||||
val chapterEntry = existingChapterEntry ?: transaction { ChapterTable.selectAll().where { ChapterTable.id eq chapterId }.first() }
|
||||
val mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||
val source = getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference])
|
||||
|
||||
val pageList =
|
||||
source
|
||||
.getPageList(
|
||||
SChapter.create().apply {
|
||||
url = chapterEntry[ChapterTable.url]
|
||||
name = chapterEntry[ChapterTable.name]
|
||||
scanlator = chapterEntry[ChapterTable.scanlator]
|
||||
chapter_number = chapterEntry[ChapterTable.chapter_number]
|
||||
date_upload = chapterEntry[ChapterTable.date_upload]
|
||||
},
|
||||
).mapIndexed { index, page -> Page(index, page.url, page.imageUrl, page.uri) }
|
||||
|
||||
transaction {
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
it[isDownloaded] = false
|
||||
}
|
||||
|
||||
PageTable.deleteWhere { PageTable.chapter eq chapterId }
|
||||
PageTable.batchInsert(pageList) { page ->
|
||||
this[PageTable.index] = page.index
|
||||
this[PageTable.url] = page.url
|
||||
this[PageTable.imageUrl] = page.imageUrl
|
||||
this[PageTable.chapter] = chapterId
|
||||
}
|
||||
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
it[pageCount] = pageList.size
|
||||
it[lastPageRead] = chapterEntry[ChapterTable.lastPageRead].coerceAtMost(pageList.size - 1).coerceAtLeast(0)
|
||||
}
|
||||
}
|
||||
pageList.size
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getChapterDownloadReady(
|
||||
chapterId: Int? = null,
|
||||
chapterIndex: Int? = null,
|
||||
@@ -68,56 +150,31 @@ private class ChapterForDownload(
|
||||
suspend fun asDownloadReady(): ChapterDataClass {
|
||||
val log = KotlinLogging.logger("${logger.name}::asDownloadReady")
|
||||
|
||||
val downloadPageCount =
|
||||
try {
|
||||
ChapterDownloadHelper.getImageCount(mangaId, chapterId)
|
||||
} catch (_: Exception) {
|
||||
0
|
||||
}
|
||||
val downloadPageCount = runCatching { ChapterDownloadHelper.getImageCount(mangaId, chapterId) }.getOrDefault(0)
|
||||
val isMarkedAsDownloaded = chapterEntry[ChapterTable.isDownloaded]
|
||||
val dbPageCount = chapterEntry[ChapterTable.pageCount]
|
||||
val doesDownloadExist = downloadPageCount != 0
|
||||
val doPageCountsMatch = dbPageCount == downloadPageCount
|
||||
|
||||
log.debug { "isMarkedAsDownloaded= $isMarkedAsDownloaded, dbPageCount= $dbPageCount, downloadPageCount= $downloadPageCount" }
|
||||
|
||||
return if (!doesDownloadExist) {
|
||||
log.debug { "reset download status and fetch page list" }
|
||||
updateDownloadStatusAndPageList(false)
|
||||
refreshChapterPageList(mangaId, chapterId, chapterEntry)
|
||||
chapterEntry = freshChapterEntry(optChapterId = chapterId)
|
||||
ChapterTable.toDataClass(chapterEntry)
|
||||
} else {
|
||||
transaction {
|
||||
var needsUpdate = false
|
||||
|
||||
if (!isMarkedAsDownloaded) {
|
||||
log.debug { "mark as downloaded" }
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
it[isDownloaded] = true
|
||||
}
|
||||
needsUpdate = true
|
||||
}
|
||||
|
||||
if (!doPageCountsMatch) {
|
||||
log.debug { "use page count of downloaded chapter" }
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
it[pageCount] = downloadPageCount
|
||||
it[lastPageRead] = chapterEntry[ChapterTable.lastPageRead].coerceAtMost(downloadPageCount - 1).coerceAtLeast(0)
|
||||
}
|
||||
needsUpdate = true
|
||||
}
|
||||
|
||||
// Return updated chapter data
|
||||
val updatedRow =
|
||||
ChapterTable
|
||||
.selectAll()
|
||||
.where { ChapterTable.id eq chapterId }
|
||||
.first()
|
||||
|
||||
if (needsUpdate) {
|
||||
chapterEntry = updatedRow
|
||||
}
|
||||
|
||||
ChapterTable.toDataClass(updatedRow)
|
||||
if (updateChapterPersistence(
|
||||
chapterId,
|
||||
isMarkedAsDownloaded,
|
||||
dbPageCount,
|
||||
downloadPageCount,
|
||||
chapterEntry[ChapterTable.lastPageRead],
|
||||
log,
|
||||
)
|
||||
) {
|
||||
chapterEntry = freshChapterEntry(optChapterId = chapterId)
|
||||
}
|
||||
ChapterTable.toDataClass(chapterEntry)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,59 +207,4 @@ private class ChapterForDownload(
|
||||
}
|
||||
}.first()
|
||||
}
|
||||
|
||||
private suspend fun updateDownloadStatusAndPageList(downloaded: Boolean): ChapterDataClass {
|
||||
val mutex = mutexByChapterId.get(chapterId) { Mutex() }
|
||||
return mutex.withLock {
|
||||
val pageList = fetchPageList()
|
||||
|
||||
transaction {
|
||||
// Update download status
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
it[isDownloaded] = downloaded
|
||||
}
|
||||
|
||||
// Clear existing pages and insert new ones
|
||||
PageTable.deleteWhere { PageTable.chapter eq chapterId }
|
||||
PageTable.batchInsert(pageList) { page ->
|
||||
this[PageTable.index] = page.index
|
||||
this[PageTable.url] = page.url
|
||||
this[PageTable.imageUrl] = page.imageUrl
|
||||
this[PageTable.chapter] = chapterId
|
||||
}
|
||||
|
||||
// Update page count
|
||||
ChapterTable.update({ ChapterTable.id eq chapterId }) {
|
||||
it[pageCount] = pageList.size
|
||||
it[lastPageRead] = chapterEntry[ChapterTable.lastPageRead].coerceAtMost(pageList.size - 1).coerceAtLeast(0)
|
||||
}
|
||||
|
||||
// Get updated chapter data
|
||||
val updatedRow =
|
||||
ChapterTable
|
||||
.selectAll()
|
||||
.where { ChapterTable.id eq chapterId }
|
||||
.first()
|
||||
|
||||
chapterEntry = updatedRow
|
||||
ChapterTable.toDataClass(updatedRow)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun fetchPageList(): List<Page> {
|
||||
val mangaEntry = transaction { MangaTable.selectAll().where { MangaTable.id eq mangaId }.first() }
|
||||
val source = getCatalogueSourceOrStub(mangaEntry[MangaTable.sourceReference])
|
||||
|
||||
return source
|
||||
.getPageList(
|
||||
SChapter.create().apply {
|
||||
url = chapterEntry[ChapterTable.url]
|
||||
name = chapterEntry[ChapterTable.name]
|
||||
scanlator = chapterEntry[ChapterTable.scanlator]
|
||||
chapter_number = chapterEntry[ChapterTable.chapter_number]
|
||||
date_upload = chapterEntry[ChapterTable.date_upload]
|
||||
},
|
||||
).mapIndexed { index, page -> Page(index, page.url, page.imageUrl, page.uri) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.SourceFactory
|
||||
import eu.kanade.tachiyomi.source.local.LocalSource
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import net.dongliu.apk.parser.ApkFile
|
||||
import net.dongliu.apk.parser.bean.Icon
|
||||
@@ -23,15 +24,17 @@ import okio.source
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.jdbc.deleteWhere
|
||||
import org.jetbrains.exposed.v1.jdbc.insert
|
||||
import org.jetbrains.exposed.v1.jdbc.select
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import org.jetbrains.exposed.v1.jdbc.update
|
||||
import suwayomi.tachidesk.manga.impl.extension.ExtensionsList.extensionTableAsDataClass
|
||||
import suwayomi.tachidesk.manga.impl.extension.github.ExtensionGithubApi
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.EXTENSION_FEATURE
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.LIB_VERSION_MAX
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.LIB_VERSION_MIN
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.METADATA_CONTENT_WARNING
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.METADATA_EXTENSION_LIB
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.METADATA_NAME
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.METADATA_NSFW
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.METADATA_SOURCE_CLASS
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.dex2jar
|
||||
@@ -62,18 +65,20 @@ object Extension {
|
||||
|
||||
suspend fun installExtension(pkgName: String): Int {
|
||||
logger.debug { "Installing $pkgName" }
|
||||
val extensionRecord = extensionTableAsDataClass().first { it.pkgName == pkgName }
|
||||
val apkUrl =
|
||||
transaction {
|
||||
ExtensionTable
|
||||
.select(ExtensionTable.apkUrl)
|
||||
.where { ExtensionTable.pkgName eq pkgName }
|
||||
.firstOrNull()
|
||||
?.get(ExtensionTable.apkUrl)
|
||||
} ?: throw NullPointerException("Could not find extension $pkgName")
|
||||
|
||||
return installAPK {
|
||||
val apkURL =
|
||||
ExtensionGithubApi.getApkUrl(
|
||||
extensionRecord.repo ?: throw NullPointerException("Could not find extension repo"),
|
||||
extensionRecord.apkName,
|
||||
)
|
||||
val apkName = Uri.parse(apkURL).lastPathSegment!!
|
||||
val apkName = Uri.parse(apkUrl).lastPathSegment!!
|
||||
val apkSavePath = "${applicationDirs.extensionsRoot}/$apkName"
|
||||
// download apk file
|
||||
downloadAPKFile(apkURL, apkSavePath)
|
||||
downloadAPKFile(apkUrl, apkSavePath)
|
||||
|
||||
apkSavePath
|
||||
}
|
||||
@@ -148,7 +153,10 @@ object Extension {
|
||||
// throw Exception("This apk is not a signed with the official tachiyomi signature")
|
||||
// }
|
||||
|
||||
val isNsfw = packageInfo.applicationInfo.metaData.getString(METADATA_NSFW) == "1"
|
||||
var contentWarning = packageInfo.applicationInfo.metaData.getInt(METADATA_CONTENT_WARNING)
|
||||
if (contentWarning == 0) {
|
||||
contentWarning = packageInfo.applicationInfo.metaData.getInt(METADATA_NSFW)
|
||||
}
|
||||
|
||||
val className =
|
||||
packageInfo.packageName + packageInfo.applicationInfo.metaData.getString(METADATA_SOURCE_CLASS)
|
||||
@@ -181,9 +189,16 @@ object Extension {
|
||||
}
|
||||
|
||||
val extensionName =
|
||||
packageInfo.applicationInfo.nonLocalizedLabel
|
||||
.toString()
|
||||
.substringAfter("Tachiyomi: ")
|
||||
packageInfo.applicationInfo.metaData.getString(METADATA_NAME)
|
||||
?: packageInfo.applicationInfo.nonLocalizedLabel
|
||||
.toString()
|
||||
.substringAfter("Tachiyomi: ")
|
||||
|
||||
val extensionLibVersion =
|
||||
packageInfo.applicationInfo.metaData
|
||||
.getString(METADATA_EXTENSION_LIB)
|
||||
.takeUnless { it == "0" }
|
||||
?: packageInfo.versionName.substringBeforeLast('.')
|
||||
|
||||
// update extension info
|
||||
transaction {
|
||||
@@ -193,9 +208,10 @@ object Extension {
|
||||
it[name] = extensionName
|
||||
it[this.pkgName] = packageInfo.packageName
|
||||
it[versionName] = packageInfo.versionName
|
||||
it[versionCode] = packageInfo.versionCode
|
||||
it[versionCode] = packageInfo.versionCode.toLong()
|
||||
it[extensionLib] = extensionLibVersion
|
||||
it[lang] = extensionLang
|
||||
it[this.isNsfw] = isNsfw
|
||||
it[this.contentWarning] = contentWarning
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +220,7 @@ object Extension {
|
||||
it[this.isInstalled] = true
|
||||
it[this.classFQName] = className
|
||||
it[versionName] = packageInfo.versionName
|
||||
it[versionCode] = packageInfo.versionCode
|
||||
it[versionCode] = packageInfo.versionCode.toLong()
|
||||
}
|
||||
|
||||
val extensionId =
|
||||
@@ -220,7 +236,7 @@ object Extension {
|
||||
it[name] = httpSource.name
|
||||
it[lang] = httpSource.lang
|
||||
it[extension] = extensionId
|
||||
it[SourceTable.isNsfw] = isNsfw
|
||||
it[this.contentWarning] = contentWarning
|
||||
}
|
||||
logger.debug { "Installed source ${httpSource.name} (${httpSource.lang}) with id:${httpSource.id}" }
|
||||
}
|
||||
@@ -343,7 +359,9 @@ object Extension {
|
||||
logger.debug { "Uninstalling $pkgName" }
|
||||
|
||||
val extensionRecord = transaction { ExtensionTable.selectAll().where { ExtensionTable.pkgName eq pkgName }.first() }
|
||||
val fileNameWithoutType = extensionRecord[ExtensionTable.apkName].substringBefore(".apk")
|
||||
val fileNameWithoutType =
|
||||
extensionRecord[ExtensionTable.apkName]?.substringBefore(".apk")
|
||||
?: throw NullPointerException("Missing $pkgName apkName")
|
||||
val jarPath = "${applicationDirs.extensionsRoot}/$fileNameWithoutType.jar"
|
||||
val sources =
|
||||
transaction {
|
||||
@@ -359,6 +377,7 @@ object Extension {
|
||||
ExtensionTable.update({ ExtensionTable.pkgName eq pkgName }) {
|
||||
it[isInstalled] = false
|
||||
it[hasUpdate] = false
|
||||
it[apkName] = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,8 +404,7 @@ object Extension {
|
||||
it[versionName] = targetExtension.versionName
|
||||
it[versionCode] = targetExtension.versionCode
|
||||
it[lang] = targetExtension.lang
|
||||
it[isNsfw] = targetExtension.isNsfw
|
||||
it[apkName] = targetExtension.apkName
|
||||
it[contentWarning] = targetExtension.contentWarning.ordinal
|
||||
it[iconUrl] = targetExtension.iconUrl
|
||||
it[hasUpdate] = false
|
||||
}
|
||||
@@ -394,17 +412,21 @@ object Extension {
|
||||
return installExtension(pkgName)
|
||||
}
|
||||
|
||||
suspend fun getExtensionIcon(apkName: String): Pair<InputStream, String> {
|
||||
val iconUrl =
|
||||
if (apkName == "localSource") {
|
||||
""
|
||||
} else {
|
||||
transaction { ExtensionTable.selectAll().where { ExtensionTable.apkName eq apkName }.first() }[ExtensionTable.iconUrl]
|
||||
}
|
||||
|
||||
suspend fun getExtensionIcon(pkgName: String): Pair<InputStream, String> {
|
||||
val cacheSaveDir = "${applicationDirs.extensionsRoot}/icon"
|
||||
|
||||
return getImageResponse(cacheSaveDir, apkName) {
|
||||
if (pkgName == LocalSource::class.java.`package`.name) {
|
||||
return getImageResponse(cacheSaveDir, "localSource") {
|
||||
network.client
|
||||
.newCall(GET("", cache = CacheControl.FORCE_NETWORK))
|
||||
.await()
|
||||
}
|
||||
}
|
||||
|
||||
val iconUrl =
|
||||
transaction { ExtensionTable.selectAll().where { ExtensionTable.pkgName eq pkgName }.first() }[ExtensionTable.iconUrl]
|
||||
|
||||
return getImageResponse(cacheSaveDir, pkgName) {
|
||||
network.client
|
||||
.newCall(
|
||||
GET(iconUrl, cache = CacheControl.FORCE_NETWORK),
|
||||
@@ -412,5 +434,5 @@ object Extension {
|
||||
}
|
||||
}
|
||||
|
||||
fun getExtensionIconUrl(apkName: String): String = "/api/v1/extension/icon/$apkName"
|
||||
fun proxyExtensionIconUrl(pkgName: String): String = "/api/v1/extension/icon/$pkgName"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
package suwayomi.tachidesk.manga.impl.extension
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.serialization.decodeFromByteArray
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.okio.decodeFromBufferedSource
|
||||
import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import okio.BufferedSource
|
||||
import okio.buffer
|
||||
import okio.gzip
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.inList
|
||||
import org.jetbrains.exposed.v1.jdbc.deleteWhere
|
||||
import org.jetbrains.exposed.v1.jdbc.insert
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import org.jetbrains.exposed.v1.jdbc.update
|
||||
import suwayomi.tachidesk.manga.impl.extension.github.NetworkExtensionStore
|
||||
import suwayomi.tachidesk.manga.impl.extension.github.NetworkLegacyExtension
|
||||
import suwayomi.tachidesk.manga.impl.extension.github.NetworkLegacyExtensionRepo
|
||||
import suwayomi.tachidesk.manga.impl.extension.github.toExtensionInfo
|
||||
import suwayomi.tachidesk.manga.impl.extension.github.toExtensionInfos
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionInfo
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionStore
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionStoreTable
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
|
||||
object ExtensionStoreService {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
val network: NetworkHelper by injectLazy()
|
||||
val protoBuf: ProtoBuf by injectLazy()
|
||||
val json: Json by injectLazy()
|
||||
|
||||
suspend fun fetch(indexUrl: String): ExtensionStore {
|
||||
var updatedIndexUrl: String = indexUrl
|
||||
return try {
|
||||
val response = network.client.newCall(GET(updatedIndexUrl)).awaitSuccess()
|
||||
response.body.source().decompressIfGzipped().use { source ->
|
||||
val networkStore =
|
||||
when (source.peek().readByte()) {
|
||||
// "[..."
|
||||
0x5B.toByte() -> {
|
||||
run {
|
||||
if (!indexUrl.endsWith("/index.min.json")) {
|
||||
throw IllegalArgumentException("Provided legacy store url is not valid")
|
||||
}
|
||||
updatedIndexUrl = indexUrl.replace("/index.min.json", "/repo.json")
|
||||
network.client.newCall(GET(updatedIndexUrl)).awaitSuccess().body.source().use {
|
||||
json.decodeFromBufferedSource<NetworkLegacyExtensionRepo>(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// "{..."
|
||||
0x7B.toByte() -> {
|
||||
try {
|
||||
json.decodeFromBufferedSource<NetworkLegacyExtensionRepo>(source.peek())
|
||||
} catch (_: IllegalArgumentException) {
|
||||
json.decodeFromBufferedSource<NetworkExtensionStore>(source)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
protoBuf.decodeFromByteArray<NetworkExtensionStore>(source.readByteArray())
|
||||
}
|
||||
}
|
||||
|
||||
if (networkStore is NetworkLegacyExtensionRepo && networkStore.indexV2 != null) {
|
||||
return fetch(networkStore.indexV2)
|
||||
}
|
||||
|
||||
networkStore.toExtensionStore(updatedIndexUrl)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (e is CancellationException) throw e
|
||||
logger.error(e) { "Failed to fetch extension store '$indexUrl'" }
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
fun upsert(store: ExtensionStore) {
|
||||
transaction {
|
||||
val existing =
|
||||
ExtensionStoreTable
|
||||
.selectAll()
|
||||
.where { ExtensionStoreTable.indexUrl eq store.indexUrl }
|
||||
.firstOrNull()
|
||||
|
||||
if (existing == null) {
|
||||
ExtensionStoreTable.insert {
|
||||
it[name] = store.name
|
||||
it[badgeLabel] = store.badgeLabel
|
||||
it[signingKey] = store.signingKey
|
||||
it[contactWebsite] = store.contact.website
|
||||
it[contactDiscord] = store.contact.discord
|
||||
it[indexUrl] = store.indexUrl
|
||||
it[isLegacy] = store.isLegacy
|
||||
it[extensionListUrl] = store.extensionListUrl
|
||||
}
|
||||
} else {
|
||||
ExtensionStoreTable.update({ ExtensionStoreTable.indexUrl eq store.indexUrl }) {
|
||||
it[name] = store.name
|
||||
it[badgeLabel] = store.badgeLabel
|
||||
it[signingKey] = store.signingKey
|
||||
it[contactWebsite] = store.contact.website
|
||||
it[contactDiscord] = store.contact.discord
|
||||
it[isLegacy] = store.isLegacy
|
||||
it[extensionListUrl] = store.extensionListUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getAndRefresh(): List<ExtensionStore> {
|
||||
val stores =
|
||||
transaction {
|
||||
ExtensionStoreTable.selectAll().toList()
|
||||
}
|
||||
var needsPrefUpdate = false
|
||||
val updateStores =
|
||||
stores.mapNotNull { storeRow ->
|
||||
val oldIndexUrl = storeRow[ExtensionStoreTable.indexUrl]
|
||||
val oldName = storeRow[ExtensionStoreTable.name]
|
||||
try {
|
||||
val store = fetch(oldIndexUrl)
|
||||
if (store.indexUrl != oldIndexUrl) {
|
||||
transaction {
|
||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq oldIndexUrl }
|
||||
}
|
||||
needsPrefUpdate = true
|
||||
}
|
||||
upsert(store)
|
||||
store
|
||||
} catch (e: Exception) {
|
||||
logger.warn(e) { "Failed to fetch extension store '$oldName ($oldIndexUrl)'" }
|
||||
null
|
||||
}
|
||||
}
|
||||
if (needsPrefUpdate) syncDbToPrefs()
|
||||
return updateStores
|
||||
}
|
||||
|
||||
fun syncDbToPrefs() {
|
||||
val dbStores =
|
||||
transaction {
|
||||
ExtensionStoreTable
|
||||
.selectAll()
|
||||
.map { it[ExtensionStoreTable.indexUrl] }
|
||||
.toSet()
|
||||
}
|
||||
|
||||
val currentPrefs = serverConfig.extensionStores.value.toSet()
|
||||
val toAdd = dbStores - currentPrefs
|
||||
val toRemove = currentPrefs - dbStores
|
||||
|
||||
if (toAdd.isNotEmpty()) {
|
||||
serverConfig.extensionStores.value = (serverConfig.extensionStores.value + toAdd).distinct()
|
||||
}
|
||||
|
||||
if (toRemove.isNotEmpty()) {
|
||||
serverConfig.extensionStores.value = serverConfig.extensionStores.value.filterNot { it in toRemove }
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun syncPrefsToDb() {
|
||||
val prefUrls = serverConfig.extensionStores.value.toSet()
|
||||
|
||||
val dbStores =
|
||||
transaction {
|
||||
ExtensionStoreTable.selectAll().associateBy { it[ExtensionStoreTable.indexUrl] }
|
||||
}
|
||||
|
||||
val toAdd = prefUrls - dbStores.keys
|
||||
val toRemove = (dbStores.keys - prefUrls).toMutableSet()
|
||||
var needsPrefUpdate = toRemove.isNotEmpty()
|
||||
|
||||
toAdd.forEach { url ->
|
||||
try {
|
||||
val store = fetch(url)
|
||||
if (store.indexUrl != url) {
|
||||
transaction {
|
||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl eq url }
|
||||
}
|
||||
needsPrefUpdate = true
|
||||
toRemove -= store.indexUrl
|
||||
}
|
||||
upsert(store)
|
||||
} catch (e: Exception) {
|
||||
logger.warn(e) { "Failed to sync preference store '$url' to database" }
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove.isNotEmpty()) {
|
||||
transaction {
|
||||
ExtensionStoreTable.deleteWhere { ExtensionStoreTable.indexUrl inList toRemove.toList() }
|
||||
}
|
||||
}
|
||||
if (needsPrefUpdate) {
|
||||
syncDbToPrefs()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getExtensions(store: ExtensionStore): List<ExtensionInfo> {
|
||||
val extensions =
|
||||
if (store.extensionListUrl != null) {
|
||||
val response = network.client.newCall(GET(store.extensionListUrl)).awaitSuccess()
|
||||
response.body.source().decompressIfGzipped().use { source ->
|
||||
when (source.peek().readByte()) {
|
||||
// "{..."
|
||||
0x7B.toByte() -> {
|
||||
json.decodeFromBufferedSource<NetworkExtensionStore.ExtensionList>(source)
|
||||
}
|
||||
|
||||
else -> {
|
||||
protoBuf.decodeFromByteArray<NetworkExtensionStore.ExtensionList>(
|
||||
source.readByteArray(),
|
||||
)
|
||||
}
|
||||
}.toExtensionInfos(store)
|
||||
}
|
||||
} else if (!store.isLegacy) {
|
||||
val response = network.client.newCall(GET(store.indexUrl)).awaitSuccess()
|
||||
response.body.source().decompressIfGzipped().use { source ->
|
||||
when (source.peek().readByte()) {
|
||||
// "{..."
|
||||
0x7B.toByte() -> json.decodeFromBufferedSource<NetworkExtensionStore>(source)
|
||||
|
||||
else -> protoBuf.decodeFromByteArray<NetworkExtensionStore>(source.readByteArray())
|
||||
}.extensionList!!
|
||||
.toExtensionInfos(store)
|
||||
}
|
||||
} else {
|
||||
val storeBaseUrl = store.indexUrl.removeSuffix("/repo.json")
|
||||
val response = network.client.newCall(GET("$storeBaseUrl/index.min.json")).awaitSuccess()
|
||||
response.body.source().use { source ->
|
||||
json
|
||||
.decodeFromBufferedSource<List<NetworkLegacyExtension>>(source)
|
||||
.map { it.toExtensionInfo(store, storeBaseUrl) }
|
||||
}
|
||||
}
|
||||
return extensions
|
||||
}
|
||||
|
||||
private fun BufferedSource.decompressIfGzipped(): BufferedSource {
|
||||
val isGzip =
|
||||
peek().use { peeked ->
|
||||
try {
|
||||
peeked.readShort().toInt() == 0x1f8b
|
||||
} catch (_: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
return if (isGzip) gzip().buffer() else this
|
||||
}
|
||||
}
|
||||
@@ -21,12 +21,11 @@ import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.statements.toExecutable
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import org.jetbrains.exposed.v1.jdbc.update
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension.getExtensionIconUrl
|
||||
import suwayomi.tachidesk.manga.impl.extension.github.ExtensionGithubApi
|
||||
import suwayomi.tachidesk.manga.impl.extension.github.OnlineExtension
|
||||
import suwayomi.tachidesk.manga.impl.extension.Extension.proxyExtensionIconUrl
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionInfo
|
||||
import suwayomi.tachidesk.manga.model.table.ExtensionTable
|
||||
import suwayomi.tachidesk.server.serverConfig
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@@ -34,23 +33,23 @@ object ExtensionsList {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
var lastUpdateCheck: Long = 0
|
||||
var updateMap = ConcurrentHashMap<String, OnlineExtension>()
|
||||
var updateMap = ConcurrentHashMap<String, ExtensionInfo>()
|
||||
|
||||
suspend fun fetchExtensions() {
|
||||
// update if 60 seconds has passed or requested offline and database is empty
|
||||
val extensions =
|
||||
serverConfig.extensionRepos.value.map { repo ->
|
||||
kotlin
|
||||
.runCatching {
|
||||
ExtensionGithubApi.findExtensions(repo.repoUrlReplace())
|
||||
}.onFailure {
|
||||
logger.warn(it) {
|
||||
"Failed to fetch extensions for repo: $repo"
|
||||
}
|
||||
}
|
||||
val allExtensions = mutableListOf<ExtensionInfo>()
|
||||
|
||||
ExtensionStoreService.getAndRefresh().forEach { store ->
|
||||
try {
|
||||
val extensions = ExtensionStoreService.getExtensions(store)
|
||||
allExtensions.addAll(extensions)
|
||||
} catch (e: Exception) {
|
||||
logger.warn(e) {
|
||||
"Failed to fetch extensions for store: ${store.indexUrl}"
|
||||
}
|
||||
}
|
||||
val foundExtensions = extensions.mapNotNull { it.getOrNull() }.flatten()
|
||||
updateExtensionDatabase(foundExtensions)
|
||||
}
|
||||
|
||||
updateExtensionDatabase(allExtensions)
|
||||
}
|
||||
|
||||
suspend fun fetchExtensionsCached() {
|
||||
@@ -74,25 +73,25 @@ object ExtensionsList {
|
||||
transaction {
|
||||
ExtensionTable.selectAll().filter { it[ExtensionTable.name] != LocalSource.EXTENSION_NAME }.map {
|
||||
ExtensionDataClass(
|
||||
it[ExtensionTable.repo],
|
||||
it[ExtensionTable.apkName],
|
||||
getExtensionIconUrl(it[ExtensionTable.apkName]),
|
||||
it[ExtensionTable.name],
|
||||
it[ExtensionTable.pkgName],
|
||||
it[ExtensionTable.versionName],
|
||||
it[ExtensionTable.versionCode],
|
||||
it[ExtensionTable.lang],
|
||||
it[ExtensionTable.isNsfw],
|
||||
it[ExtensionTable.isInstalled],
|
||||
it[ExtensionTable.hasUpdate],
|
||||
it[ExtensionTable.isObsolete],
|
||||
repo = it[ExtensionTable.storeIndexUrl],
|
||||
apkName = it[ExtensionTable.apkName].orEmpty(),
|
||||
iconUrl = proxyExtensionIconUrl(it[ExtensionTable.pkgName]),
|
||||
name = it[ExtensionTable.name],
|
||||
pkgName = it[ExtensionTable.pkgName],
|
||||
versionName = it[ExtensionTable.versionName],
|
||||
versionCode = it[ExtensionTable.versionCode].toInt(),
|
||||
lang = it[ExtensionTable.lang],
|
||||
isNsfw = it[ExtensionTable.contentWarning] >= ContentWarning.MIXED.ordinal,
|
||||
installed = it[ExtensionTable.isInstalled],
|
||||
hasUpdate = it[ExtensionTable.hasUpdate],
|
||||
obsolete = it[ExtensionTable.isObsolete],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val updateExtensionDatabaseMutex = Mutex()
|
||||
|
||||
private suspend fun updateExtensionDatabase(foundExtensions: List<OnlineExtension>) {
|
||||
private suspend fun updateExtensionDatabase(foundExtensions: List<ExtensionInfo>) {
|
||||
updateExtensionDatabaseMutex.withLock {
|
||||
transaction {
|
||||
val uniqueExtensions =
|
||||
@@ -106,10 +105,10 @@ object ExtensionsList {
|
||||
.selectAll()
|
||||
.toList()
|
||||
.associateBy { it[ExtensionTable.pkgName] }
|
||||
val extensionsToUpdate = mutableListOf<Pair<OnlineExtension, ResultRow>>()
|
||||
val extensionsToInsert = mutableListOf<OnlineExtension>()
|
||||
val extensionsToUpdate = mutableListOf<Pair<ExtensionInfo, ResultRow>>()
|
||||
val extensionsToInsert = mutableListOf<ExtensionInfo>()
|
||||
val extensionsToDelete =
|
||||
installedExtensions.filter { it.value[ExtensionTable.repo] != null }.mapNotNull { (pkgName, extension) ->
|
||||
installedExtensions.filter { it.value[ExtensionTable.storeIndexUrl] != null }.mapNotNull { (pkgName, extension) ->
|
||||
extension.takeUnless { uniqueExtensions.any { it.pkgName == pkgName } }
|
||||
}
|
||||
uniqueExtensions.forEach {
|
||||
@@ -132,7 +131,7 @@ object ExtensionsList {
|
||||
addBatch(EntityID(extensionRecord[ExtensionTable.id].value, ExtensionTable))
|
||||
// Always update icon url and repo
|
||||
this[ExtensionTable.iconUrl] = foundExtension.iconUrl
|
||||
this[ExtensionTable.repo] = foundExtension.repo
|
||||
this[ExtensionTable.storeIndexUrl] = foundExtension.storeIndexUrl
|
||||
|
||||
// add these because batch updates need matching columns
|
||||
this[ExtensionTable.hasUpdate] = extensionRecord[ExtensionTable.hasUpdate]
|
||||
@@ -168,13 +167,14 @@ object ExtensionsList {
|
||||
extensionsToFullyUpdate.forEach { (foundExtension, extensionRecord) ->
|
||||
addBatch(EntityID(extensionRecord[ExtensionTable.id].value, ExtensionTable))
|
||||
// extension is not installed, so we can overwrite the data without a care
|
||||
this[ExtensionTable.repo] = foundExtension.repo
|
||||
this[ExtensionTable.storeIndexUrl] = foundExtension.storeIndexUrl
|
||||
this[ExtensionTable.name] = foundExtension.name
|
||||
this[ExtensionTable.extensionLib] = foundExtension.extensionLib
|
||||
this[ExtensionTable.versionName] = foundExtension.versionName
|
||||
this[ExtensionTable.versionCode] = foundExtension.versionCode
|
||||
this[ExtensionTable.lang] = foundExtension.lang
|
||||
this[ExtensionTable.isNsfw] = foundExtension.isNsfw
|
||||
this[ExtensionTable.apkName] = foundExtension.apkName
|
||||
this[ExtensionTable.contentWarning] = foundExtension.contentWarning.ordinal
|
||||
this[ExtensionTable.apkUrl] = foundExtension.apkUrl
|
||||
this[ExtensionTable.iconUrl] = foundExtension.iconUrl
|
||||
}
|
||||
}.toExecutable()
|
||||
@@ -183,14 +183,15 @@ object ExtensionsList {
|
||||
}
|
||||
if (extensionsToInsert.isNotEmpty()) {
|
||||
ExtensionTable.batchInsert(extensionsToInsert) { foundExtension ->
|
||||
this[ExtensionTable.repo] = foundExtension.repo
|
||||
this[ExtensionTable.storeIndexUrl] = foundExtension.storeIndexUrl
|
||||
this[ExtensionTable.name] = foundExtension.name
|
||||
this[ExtensionTable.pkgName] = foundExtension.pkgName
|
||||
this[ExtensionTable.extensionLib] = foundExtension.extensionLib
|
||||
this[ExtensionTable.versionName] = foundExtension.versionName
|
||||
this[ExtensionTable.versionCode] = foundExtension.versionCode
|
||||
this[ExtensionTable.lang] = foundExtension.lang
|
||||
this[ExtensionTable.isNsfw] = foundExtension.isNsfw
|
||||
this[ExtensionTable.apkName] = foundExtension.apkName
|
||||
this[ExtensionTable.contentWarning] = foundExtension.contentWarning.ordinal
|
||||
this[ExtensionTable.apkUrl] = foundExtension.apkUrl
|
||||
this[ExtensionTable.iconUrl] = foundExtension.iconUrl
|
||||
}
|
||||
}
|
||||
@@ -215,16 +216,4 @@ object ExtensionsList {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.repoUrlReplace(): String =
|
||||
if (contains("github")) {
|
||||
replace(repoMatchRegex) {
|
||||
"https://raw.githubusercontent.com/${it.groupValues[2]}/${it.groupValues[3]}/" +
|
||||
(it.groupValues.getOrNull(4)?.ifBlank { null } ?: "repo") +
|
||||
"/" +
|
||||
(it.groupValues.getOrNull(5)?.ifBlank { null } ?: "index.min.json")
|
||||
}
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package suwayomi.tachidesk.manga.impl.extension.github
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionStore
|
||||
|
||||
interface BaseNetworkExtensionStore {
|
||||
fun toExtensionStore(indexUrl: String): ExtensionStore
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
package suwayomi.tachidesk.manga.impl.extension.github
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import eu.kanade.tachiyomi.network.parseAs
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.LIB_VERSION_MAX
|
||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.LIB_VERSION_MIN
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
object ExtensionGithubApi {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
@Serializable
|
||||
private data class ExtensionJsonObject(
|
||||
val name: String,
|
||||
val pkg: String,
|
||||
val apk: String,
|
||||
val lang: String,
|
||||
val code: Int,
|
||||
val version: String,
|
||||
val nsfw: Int,
|
||||
val hasReadme: Int = 0,
|
||||
val hasChangelog: Int = 0,
|
||||
val sources: List<ExtensionSourceJsonObject>?,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
private data class ExtensionSourceJsonObject(
|
||||
val name: String,
|
||||
val lang: String,
|
||||
val id: Long,
|
||||
val baseUrl: String,
|
||||
)
|
||||
|
||||
suspend fun findExtensions(repo: String): List<OnlineExtension> {
|
||||
val response =
|
||||
client.newCall(GET(repo)).awaitSuccess()
|
||||
|
||||
return with(json) {
|
||||
response
|
||||
.parseAs<List<ExtensionJsonObject>>()
|
||||
.toExtensions(repo.substringBeforeLast('/') + '/')
|
||||
}
|
||||
}
|
||||
|
||||
fun getApkUrl(
|
||||
repo: String,
|
||||
apkName: String,
|
||||
): String = "${repo}apk/$apkName"
|
||||
|
||||
private val client by lazy {
|
||||
val network: NetworkHelper by injectLazy()
|
||||
network.client
|
||||
.newBuilder()
|
||||
.addNetworkInterceptor { chain ->
|
||||
val originalResponse = chain.proceed(chain.request())
|
||||
originalResponse
|
||||
.newBuilder()
|
||||
.header("Content-Type", "application/json")
|
||||
.build()
|
||||
}.build()
|
||||
}
|
||||
|
||||
private fun List<ExtensionJsonObject>.toExtensions(repo: String): List<OnlineExtension> =
|
||||
this
|
||||
.filter {
|
||||
val libVersion = it.version.substringBeforeLast('.').toDouble()
|
||||
libVersion in LIB_VERSION_MIN..LIB_VERSION_MAX
|
||||
}.map {
|
||||
OnlineExtension(
|
||||
repo = repo,
|
||||
name = it.name.substringAfter("Tachiyomi: "),
|
||||
pkgName = it.pkg,
|
||||
versionName = it.version,
|
||||
versionCode = it.code,
|
||||
lang = it.lang,
|
||||
isNsfw = it.nsfw == 1,
|
||||
hasReadme = it.hasReadme == 1,
|
||||
hasChangelog = it.hasChangelog == 1,
|
||||
sources = it.sources?.toExtensionSources() ?: emptyList(),
|
||||
apkName = it.apk,
|
||||
iconUrl = "${repo}icon/${it.pkg}.png",
|
||||
)
|
||||
}
|
||||
|
||||
private fun List<ExtensionSourceJsonObject>.toExtensionSources(): List<OnlineExtensionSource> =
|
||||
this.map {
|
||||
OnlineExtensionSource(
|
||||
name = it.name,
|
||||
lang = it.lang,
|
||||
id = it.id,
|
||||
baseUrl = it.baseUrl,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package suwayomi.tachidesk.manga.impl.extension.github
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonNames
|
||||
import kotlinx.serialization.protobuf.ProtoNumber
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionInfo
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionSource
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionStore
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@Serializable
|
||||
data class NetworkExtensionStore(
|
||||
@ProtoNumber(1) val name: String,
|
||||
@ProtoNumber(2) val badgeLabel: String,
|
||||
@ProtoNumber(3) val signingKey: String,
|
||||
@ProtoNumber(4) val contact: Contact,
|
||||
@ProtoNumber(101) val extensionList: ExtensionList?,
|
||||
@ProtoNumber(102) val extensionListUrl: String?,
|
||||
) : BaseNetworkExtensionStore {
|
||||
@Serializable
|
||||
data class Contact(
|
||||
@ProtoNumber(1) val website: String,
|
||||
@ProtoNumber(2) val discord: String?,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class ExtensionList(
|
||||
@ProtoNumber(1) val extensions: List<Extension>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Extension(
|
||||
@ProtoNumber(1) val name: String,
|
||||
@ProtoNumber(2) val packageName: String,
|
||||
@ProtoNumber(3) val resources: Resources,
|
||||
@ProtoNumber(4) val extensionLib: String,
|
||||
@ProtoNumber(5) val versionCode: Long,
|
||||
@ProtoNumber(6) val versionName: String,
|
||||
@ProtoNumber(7) val contentWarning: ContentWarning,
|
||||
@ProtoNumber(8) val sources: List<Source>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Resources(
|
||||
@ProtoNumber(1) val apkUrl: String,
|
||||
@ProtoNumber(2) val iconUrl: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Source(
|
||||
@ProtoNumber(1) val id: Long,
|
||||
@ProtoNumber(2) val name: String,
|
||||
@ProtoNumber(3) val language: String,
|
||||
@ProtoNumber(4) val homeUrl: String = "",
|
||||
@ProtoNumber(5) val mirrorUrls: List<String> = emptyList(),
|
||||
// @ProtoNumber(6) val contentWarning: ContentWarning = ContentWarning.SAFE,
|
||||
@ProtoNumber(7) val message: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
enum class ContentWarning {
|
||||
@ProtoNumber(0)
|
||||
@JsonNames("CONTENT_WARNING_UNSPECIFIED")
|
||||
UNSPECIFIED,
|
||||
|
||||
@ProtoNumber(1)
|
||||
@JsonNames("CONTENT_WARNING_SAFE")
|
||||
SAFE,
|
||||
|
||||
@ProtoNumber(2)
|
||||
@JsonNames("CONTENT_WARNING_MIXED")
|
||||
MIXED,
|
||||
|
||||
@ProtoNumber(3)
|
||||
@JsonNames("CONTENT_WARNING_NSFW")
|
||||
NSFW,
|
||||
}
|
||||
|
||||
override fun toExtensionStore(indexUrl: String): ExtensionStore =
|
||||
ExtensionStore(
|
||||
indexUrl = indexUrl,
|
||||
name = name,
|
||||
badgeLabel = badgeLabel,
|
||||
signingKey = signingKey,
|
||||
contact =
|
||||
ExtensionStore.Contact(
|
||||
website = contact.website,
|
||||
discord = contact.discord,
|
||||
),
|
||||
isLegacy = false,
|
||||
extensionListUrl = extensionListUrl,
|
||||
)
|
||||
}
|
||||
|
||||
fun NetworkExtensionStore.ExtensionList.toExtensionInfos(store: ExtensionStore): List<ExtensionInfo> =
|
||||
extensions.map { extension ->
|
||||
val lang = extension.sources.map { it.language }.toSet()
|
||||
ExtensionInfo(
|
||||
storeIndexUrl = store.indexUrl,
|
||||
name = extension.name,
|
||||
pkgName = extension.packageName,
|
||||
apkUrl = extension.resources.apkUrl,
|
||||
iconUrl = extension.resources.iconUrl,
|
||||
extensionLib = extension.extensionLib,
|
||||
versionCode = extension.versionCode,
|
||||
versionName = extension.versionName,
|
||||
lang = if (lang.size == 1) lang.first() else "all",
|
||||
contentWarning =
|
||||
when (extension.contentWarning) {
|
||||
NetworkExtensionStore.ContentWarning.SAFE,
|
||||
NetworkExtensionStore.ContentWarning.UNSPECIFIED,
|
||||
-> ContentWarning.SAFE
|
||||
|
||||
NetworkExtensionStore.ContentWarning.MIXED -> ContentWarning.MIXED
|
||||
|
||||
NetworkExtensionStore.ContentWarning.NSFW -> ContentWarning.NSFW
|
||||
},
|
||||
sources =
|
||||
extension.sources.map { source ->
|
||||
ExtensionSource(
|
||||
id = source.id,
|
||||
name = source.name,
|
||||
lang = source.language,
|
||||
homeUrl = source.homeUrl,
|
||||
message = source.message,
|
||||
contentWarning =
|
||||
when (extension.contentWarning) { // todo source.contentWarning
|
||||
NetworkExtensionStore.ContentWarning.SAFE,
|
||||
NetworkExtensionStore.ContentWarning.UNSPECIFIED,
|
||||
-> ContentWarning.SAFE
|
||||
|
||||
NetworkExtensionStore.ContentWarning.MIXED -> ContentWarning.MIXED
|
||||
|
||||
NetworkExtensionStore.ContentWarning.NSFW -> ContentWarning.NSFW
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package suwayomi.tachidesk.manga.impl.extension.github
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.Serializable
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ContentWarning
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionInfo
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionSource
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionStore
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@Serializable
|
||||
data class NetworkLegacyExtension(
|
||||
val name: String,
|
||||
val pkg: String,
|
||||
val apk: String,
|
||||
val lang: String,
|
||||
val version: String,
|
||||
val code: Long,
|
||||
val nsfw: Int,
|
||||
val sources: List<Source>? = null,
|
||||
) {
|
||||
@Serializable
|
||||
data class Source(
|
||||
val id: Long,
|
||||
val lang: String,
|
||||
val name: String,
|
||||
val baseUrl: String,
|
||||
)
|
||||
}
|
||||
|
||||
fun NetworkLegacyExtension.toExtensionInfo(
|
||||
store: ExtensionStore,
|
||||
storeBaseUrl: String,
|
||||
): ExtensionInfo =
|
||||
ExtensionInfo(
|
||||
storeIndexUrl = store.indexUrl,
|
||||
name = name.substringAfter("Tachiyomi: "),
|
||||
pkgName = pkg,
|
||||
apkUrl = "$storeBaseUrl/apk/$apk",
|
||||
iconUrl = "$storeBaseUrl/icon/$pkg.png",
|
||||
extensionLib = version.substringBeforeLast('.'),
|
||||
versionCode = code,
|
||||
versionName = version,
|
||||
lang = lang,
|
||||
contentWarning = if (nsfw == 1) ContentWarning.MIXED else ContentWarning.SAFE,
|
||||
sources =
|
||||
if (sources.isNullOrEmpty()) {
|
||||
listOf(
|
||||
ExtensionSource(
|
||||
id = 0,
|
||||
name = name,
|
||||
lang = lang,
|
||||
homeUrl = "",
|
||||
message = null,
|
||||
contentWarning = if (nsfw == 1) ContentWarning.MIXED else ContentWarning.SAFE,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
sources.map { source ->
|
||||
ExtensionSource(
|
||||
id = source.id,
|
||||
name = source.name,
|
||||
lang = source.lang,
|
||||
homeUrl = source.baseUrl,
|
||||
message = null,
|
||||
contentWarning = if (nsfw == 1) ContentWarning.MIXED else ContentWarning.SAFE,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
package suwayomi.tachidesk.manga.impl.extension.github
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ExtensionStore
|
||||
|
||||
@Serializable
|
||||
data class NetworkLegacyExtensionRepo(
|
||||
@SerialName("index_v2") val indexV2: String?,
|
||||
val meta: Meta,
|
||||
) : BaseNetworkExtensionStore {
|
||||
@Serializable
|
||||
data class Meta(
|
||||
val name: String,
|
||||
val shortName: String?,
|
||||
val website: String,
|
||||
val signingKeyFingerprint: String,
|
||||
)
|
||||
|
||||
override fun toExtensionStore(indexUrl: String): ExtensionStore =
|
||||
ExtensionStore(
|
||||
indexUrl = indexUrl,
|
||||
name = meta.name,
|
||||
badgeLabel = meta.shortName ?: meta.name,
|
||||
signingKey = meta.signingKeyFingerprint,
|
||||
contact =
|
||||
ExtensionStore.Contact(
|
||||
website = meta.website,
|
||||
discord = null,
|
||||
),
|
||||
isLegacy = true,
|
||||
extensionListUrl = null,
|
||||
)
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package suwayomi.tachidesk.manga.impl.extension.github
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
data class OnlineExtensionSource(
|
||||
val name: String,
|
||||
val lang: String,
|
||||
val id: Long,
|
||||
val baseUrl: String,
|
||||
)
|
||||
|
||||
data class OnlineExtension(
|
||||
val repo: String,
|
||||
val name: String,
|
||||
val pkgName: String,
|
||||
val apkName: String,
|
||||
val lang: String,
|
||||
val versionCode: Int,
|
||||
val versionName: String,
|
||||
val isNsfw: Boolean,
|
||||
val hasReadme: Boolean,
|
||||
val hasChangelog: Boolean,
|
||||
val sources: List<OnlineExtensionSource>,
|
||||
val iconUrl: String,
|
||||
)
|
||||
@@ -127,29 +127,36 @@ object KoreaderSyncService {
|
||||
}
|
||||
|
||||
val mangaId = chapterRow[ChapterTable.manga].value
|
||||
val isDownloaded = chapterRow[ChapterTable.isDownloaded]
|
||||
val checksumMethod = serverConfig.koreaderSyncChecksumMethod.value
|
||||
|
||||
val newHash =
|
||||
when (checksumMethod) {
|
||||
KoreaderSyncChecksumMethod.BINARY -> {
|
||||
logger.debug { "[KOSYNC HASH] No hash for chapterId=$chapterId. Generating from downloaded content." }
|
||||
try {
|
||||
// Always create a CBZ in memory if it doesn't exist
|
||||
val (stream, _) = ChapterDownloadHelper.getArchiveStreamWithSize(mangaId, chapterId)
|
||||
// Write the stream to a temp file for partial hashing
|
||||
val tempFile = File.createTempFile("kosync-hash-", ".cbz")
|
||||
// Only generate binary hash if the chapter is downloaded to avoid fetching missing files
|
||||
if (isDownloaded) {
|
||||
logger.debug { "[KOSYNC HASH] No hash for chapterId=$chapterId. Generating from downloaded content." }
|
||||
try {
|
||||
tempFile.outputStream().use { fos ->
|
||||
stream.use { it.copyTo(fos) }
|
||||
// Always create a CBZ in memory if it doesn't exist
|
||||
val (stream, _) = ChapterDownloadHelper.getArchiveStreamWithSize(mangaId, chapterId)
|
||||
// Write the stream to a temp file for partial hashing
|
||||
val tempFile = File.createTempFile("kosync-hash-", ".cbz")
|
||||
try {
|
||||
tempFile.outputStream().use { fos ->
|
||||
stream.use { it.copyTo(fos) }
|
||||
}
|
||||
// Use the same hashing method as for downloads
|
||||
KoreaderHelper.hashContents(tempFile)
|
||||
} finally {
|
||||
// Always delete the temp file
|
||||
tempFile.delete()
|
||||
}
|
||||
// Use the same hashing method as for downloads
|
||||
KoreaderHelper.hashContents(tempFile)
|
||||
} finally {
|
||||
// Always delete the temp file
|
||||
tempFile.delete()
|
||||
} catch (e: Exception) {
|
||||
logger.warn(e) { "[KOSYNC HASH] Failed to generate archive stream for chapterId=$chapterId." }
|
||||
null
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logger.warn(e) { "[KOSYNC HASH] Failed to generate archive stream for chapterId=$chapterId." }
|
||||
} else {
|
||||
logger.debug { "[KOSYNC HASH] Skipping binary hash for chapterId=$chapterId because it is not downloaded." }
|
||||
null
|
||||
}
|
||||
}
|
||||
@@ -175,7 +182,7 @@ object KoreaderSyncService {
|
||||
}
|
||||
logger.info { "[KOSYNC HASH] Generated and saved new hash for chapterId=$chapterId" }
|
||||
} else {
|
||||
logger.warn { "[KOSYNC HASH] Hashing failed for chapterId=$chapterId." }
|
||||
logger.warn { "[KOSYNC HASH] Hashing failed or skipped for chapterId=$chapterId." }
|
||||
}
|
||||
newHash
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import kotlinx.coroutines.sync.withPermit
|
||||
import suwayomi.tachidesk.global.impl.sync.SyncManager
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.impl.CategoryManga
|
||||
import suwayomi.tachidesk.manga.impl.Chapter
|
||||
import suwayomi.tachidesk.manga.impl.Manga
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.IncludeOrExclude
|
||||
@@ -311,10 +310,10 @@ class Updater : IUpdater {
|
||||
tracker[job.manga.id] =
|
||||
try {
|
||||
logger.info { "Updating ${job.manga}" }
|
||||
if (serverConfig.updateMangas.value || !job.manga.initialized) {
|
||||
Manga.getManga(job.manga.id, true)
|
||||
}
|
||||
Chapter.getChapterList(job.manga.id, true)
|
||||
Manga.updateMangaAndChapters(
|
||||
job.manga.id,
|
||||
updateManga = serverConfig.updateMangas.value || !job.manga.initialized,
|
||||
)
|
||||
job.copy(status = JobStatus.COMPLETE)
|
||||
} catch (e: Exception) {
|
||||
logger.error(e) { "Error while updating ${job.manga}" }
|
||||
|
||||
@@ -40,8 +40,13 @@ object PackageTools {
|
||||
const val METADATA_SOURCE_CLASS = "tachiyomi.extension.class"
|
||||
const val METADATA_SOURCE_FACTORY = "tachiyomi.extension.factory"
|
||||
const val METADATA_NSFW = "tachiyomi.extension.nsfw"
|
||||
|
||||
const val METADATA_NAME = "tachiyomix.name"
|
||||
const val METADATA_EXTENSION_LIB = "tachiyomix.extensionLib"
|
||||
const val METADATA_CONTENT_WARNING = "tachiyomix.contentWarning"
|
||||
|
||||
const val LIB_VERSION_MIN = 1.3
|
||||
const val LIB_VERSION_MAX = 1.5
|
||||
const val LIB_VERSION_MAX = 1.6
|
||||
|
||||
/**
|
||||
* Convert dex to jar, a wrapper for the dex2jar library
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package suwayomi.tachidesk.manga.impl.util.lang
|
||||
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
val JsonObjectEmpty = JsonObject(emptyMap())
|
||||
|
||||
val JsonObjectEmptyBytes = byteArrayOf(0x7B, 0x7D)
|
||||
|
||||
val JsonObject.Companion.EMPTY: JsonObject
|
||||
inline get() = JsonObjectEmpty
|
||||
@@ -45,7 +45,9 @@ object GetCatalogueSource {
|
||||
ExtensionTable.selectAll().where { ExtensionTable.id eq extensionId }.first()
|
||||
}
|
||||
|
||||
val apkName = extensionRecord[ExtensionTable.apkName]
|
||||
val apkName =
|
||||
extensionRecord[ExtensionTable.apkName]
|
||||
?: throw NullPointerException("Missing apkName")
|
||||
val className = extensionRecord[ExtensionTable.classFQName]
|
||||
val jarName = apkName.substringBefore(".apk") + ".jar"
|
||||
val jarPath = "${applicationDirs.extensionsRoot}/$jarName"
|
||||
|
||||
@@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.SMangaUpdate
|
||||
import rx.Observable
|
||||
|
||||
open class StubSource(
|
||||
@@ -23,9 +24,17 @@ open class StubSource(
|
||||
override val name: String
|
||||
get() = id.toString()
|
||||
|
||||
override suspend fun getPopularManga(page: Int): MangasPage = throw getSourceNotInstalledException()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getPopularManga"))
|
||||
override fun fetchPopularManga(page: Int): Observable<MangasPage> = Observable.error(getSourceNotInstalledException())
|
||||
|
||||
override suspend fun getSearchManga(
|
||||
page: Int,
|
||||
query: String,
|
||||
filters: FilterList,
|
||||
): MangasPage = throw getSourceNotInstalledException()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getSearchManga"))
|
||||
override fun fetchSearchManga(
|
||||
page: Int,
|
||||
@@ -33,17 +42,28 @@ open class StubSource(
|
||||
filters: FilterList,
|
||||
): Observable<MangasPage> = Observable.error(getSourceNotInstalledException())
|
||||
|
||||
override suspend fun getLatestUpdates(page: Int): MangasPage = throw getSourceNotInstalledException()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getLatestUpdates"))
|
||||
override fun fetchLatestUpdates(page: Int): Observable<MangasPage> = Observable.error(getSourceNotInstalledException())
|
||||
|
||||
override fun getFilterList(): FilterList = FilterList()
|
||||
|
||||
override suspend fun getMangaUpdate(
|
||||
manga: SManga,
|
||||
chapters: List<SChapter>,
|
||||
fetchDetails: Boolean,
|
||||
fetchChapters: Boolean,
|
||||
): SMangaUpdate = throw getSourceNotInstalledException()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getMangaDetails"))
|
||||
override fun fetchMangaDetails(manga: SManga): Observable<SManga> = Observable.error(getSourceNotInstalledException())
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getChapterList"))
|
||||
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> = Observable.error(getSourceNotInstalledException())
|
||||
|
||||
override suspend fun getPageList(chapter: SChapter): List<Page> = throw getSourceNotInstalledException()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getPageList"))
|
||||
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> = Observable.error(getSourceNotInstalledException())
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ object ImageResponse {
|
||||
/**
|
||||
* Get a cached image response
|
||||
*
|
||||
* Note: The caller should also call [clearCachedImage] when appropriate
|
||||
* Note: The caller should also call [ImageResponse.clearCachedImage] when appropriate
|
||||
*
|
||||
* @param cacheSavePath where to save the cached image. Caller should decide to use perma cache or temp cache (OS temp dir)
|
||||
* @param fileName what the saved cache file should be named
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package suwayomi.tachidesk.manga.model.dataclass
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
@@ -18,7 +19,7 @@ enum class IncludeOrExclude(
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun fromValue(value: Int) = IncludeOrExclude.values().find { it.value == value } ?: UNSET
|
||||
fun fromValue(value: Int) = entries.find { it.value == value } ?: UNSET
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +28,19 @@ data class CategoryDataClass(
|
||||
val order: Int,
|
||||
val name: String,
|
||||
val default: Boolean,
|
||||
val size: Int,
|
||||
val includeInUpdate: IncludeOrExclude,
|
||||
val includeInDownload: IncludeOrExclude,
|
||||
val version: Long,
|
||||
val uid: Long,
|
||||
val lastModifiedAt: Long,
|
||||
val meta: Map<String, String> = emptyMap(),
|
||||
)
|
||||
) {
|
||||
@Deprecated("Remove with V1 Api")
|
||||
val size: Int by lazy {
|
||||
Category.getCategorySize(id)
|
||||
}
|
||||
|
||||
@Deprecated("Remove with V1 Api")
|
||||
val meta: Map<String, String> by lazy {
|
||||
Category.getCategoryMetaMap(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package suwayomi.tachidesk.manga.model.dataclass
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.manga.impl.Chapter.getChapterMetaMap
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.EMPTY
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
@@ -36,12 +44,10 @@ data class ChapterDataClass(
|
||||
val downloaded: Boolean,
|
||||
/** used to construct pages in the front-end */
|
||||
val pageCount: Int = -1,
|
||||
/** total chapter count, used to calculate if there's a next and prev chapter */
|
||||
val chapterCount: Int? = null,
|
||||
val lastModifiedAt: Long = 0,
|
||||
val version: Long = 0,
|
||||
/** used to store client specific values */
|
||||
val meta: Map<String, String> = emptyMap(),
|
||||
@JsonIgnore
|
||||
val memo: JsonObject = JsonObject.EMPTY,
|
||||
) {
|
||||
companion object {
|
||||
fun fromSChapter(
|
||||
@@ -59,6 +65,7 @@ data class ChapterDataClass(
|
||||
uploadDate = sChapter.date_upload,
|
||||
chapterNumber = sChapter.chapter_number,
|
||||
scanlator = sChapter.scanlator,
|
||||
memo = sChapter.memo,
|
||||
index = index,
|
||||
fetchedAt = fetchedAt,
|
||||
realUrl = realUrl,
|
||||
@@ -70,4 +77,20 @@ data class ChapterDataClass(
|
||||
downloaded = false,
|
||||
)
|
||||
}
|
||||
|
||||
@Deprecated("Remove with V1 Api")
|
||||
val chapterCount: Int by lazy {
|
||||
transaction {
|
||||
ChapterTable
|
||||
.selectAll()
|
||||
.where { ChapterTable.manga eq mangaId }
|
||||
.count()
|
||||
.toInt()
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Remove with V1 Api")
|
||||
val meta: Map<String, String> by lazy {
|
||||
getChapterMetaMap(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package suwayomi.tachidesk.manga.model.dataclass
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
data class ExtensionInfo(
|
||||
val storeIndexUrl: String,
|
||||
val name: String,
|
||||
val pkgName: String,
|
||||
val apkUrl: String,
|
||||
val iconUrl: String,
|
||||
val extensionLib: String,
|
||||
val versionCode: Long,
|
||||
val versionName: String,
|
||||
val lang: String,
|
||||
val contentWarning: ContentWarning,
|
||||
val sources: List<ExtensionSource>,
|
||||
)
|
||||
|
||||
data class ExtensionSource(
|
||||
val id: Long,
|
||||
val name: String,
|
||||
val lang: String,
|
||||
val homeUrl: String,
|
||||
val message: String?,
|
||||
val contentWarning: ContentWarning,
|
||||
)
|
||||
|
||||
enum class ContentWarning {
|
||||
SAFE,
|
||||
MIXED,
|
||||
NSFW,
|
||||
;
|
||||
|
||||
companion object {
|
||||
fun valueOf(contentWarning: Int) = entries.find { it.ordinal == contentWarning } ?: SAFE
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package suwayomi.tachidesk.manga.model.dataclass
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
data class ExtensionStore(
|
||||
val indexUrl: String,
|
||||
val name: String,
|
||||
val badgeLabel: String,
|
||||
val signingKey: String,
|
||||
val contact: Contact,
|
||||
val isLegacy: Boolean,
|
||||
val extensionListUrl: String?,
|
||||
) {
|
||||
data class Contact(
|
||||
val website: String,
|
||||
val discord: String?,
|
||||
)
|
||||
}
|
||||
@@ -7,7 +7,11 @@ package suwayomi.tachidesk.manga.model.dataclass
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import suwayomi.tachidesk.manga.impl.Manga.getMangaMetaMap
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.EMPTY
|
||||
import suwayomi.tachidesk.manga.impl.util.lang.trimAll
|
||||
import suwayomi.tachidesk.manga.model.table.MangaStatus
|
||||
import java.time.Instant
|
||||
@@ -28,25 +32,30 @@ data class MangaDataClass(
|
||||
val inLibrary: Boolean = false,
|
||||
val inLibraryAt: Long = 0,
|
||||
val source: SourceDataClass? = null,
|
||||
/** meta data for clients */
|
||||
val meta: Map<String, String> = emptyMap(),
|
||||
val realUrl: String? = null,
|
||||
var lastFetchedAt: Long? = 0,
|
||||
var chaptersLastFetchedAt: Long? = 0,
|
||||
var updateStrategy: UpdateStrategy = UpdateStrategy.ALWAYS_UPDATE,
|
||||
val lastFetchedAt: Long? = 0,
|
||||
val chaptersLastFetchedAt: Long? = 0,
|
||||
val updateStrategy: UpdateStrategy = UpdateStrategy.ALWAYS_UPDATE,
|
||||
val freshData: Boolean = false,
|
||||
var unreadCount: Long? = null,
|
||||
var downloadCount: Long? = null,
|
||||
var chapterCount: Long? = null,
|
||||
var lastReadAt: Long? = null,
|
||||
var lastChapterRead: ChapterDataClass? = null,
|
||||
val unreadCount: Long? = null,
|
||||
val downloadCount: Long? = null,
|
||||
val chapterCount: Long? = null,
|
||||
val lastReadAt: Long? = null,
|
||||
val lastChapterRead: ChapterDataClass? = null,
|
||||
val age: Long? = if (lastFetchedAt == null) 0 else Instant.now().epochSecond.minus(lastFetchedAt),
|
||||
val chaptersAge: Long? = if (chaptersLastFetchedAt == null) null else Instant.now().epochSecond.minus(chaptersLastFetchedAt),
|
||||
val trackers: List<MangaTrackerDataClass>? = null,
|
||||
val lastModifiedAt: Long = 0,
|
||||
val version: Long = 0,
|
||||
@JsonIgnore
|
||||
val memo: JsonObject = JsonObject.EMPTY,
|
||||
) {
|
||||
override fun toString(): String = "\"$title\" (id= $id) (sourceId= $sourceId)"
|
||||
|
||||
@Deprecated("Remove with V1 Api")
|
||||
val meta: Map<String, String> by lazy {
|
||||
getMangaMetaMap(id)
|
||||
}
|
||||
}
|
||||
|
||||
data class PagedMangaListDataClass(
|
||||
|
||||
@@ -9,7 +9,6 @@ package suwayomi.tachidesk.manga.model.table
|
||||
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.IncludeOrExclude
|
||||
|
||||
@@ -28,15 +27,13 @@ object CategoryTable : IntIdTable() {
|
||||
|
||||
fun CategoryTable.toDataClass(categoryEntry: ResultRow) =
|
||||
CategoryDataClass(
|
||||
categoryEntry[id].value,
|
||||
categoryEntry[order],
|
||||
categoryEntry[name],
|
||||
categoryEntry[isDefault],
|
||||
Category.getCategorySize(categoryEntry[id].value),
|
||||
IncludeOrExclude.fromValue(categoryEntry[includeInUpdate]),
|
||||
IncludeOrExclude.fromValue(categoryEntry[includeInDownload]),
|
||||
categoryEntry[version],
|
||||
categoryEntry[uid],
|
||||
categoryEntry[lastModifiedAt],
|
||||
Category.getCategoryMetaMap(categoryEntry[id].value),
|
||||
id = categoryEntry[id].value,
|
||||
order = categoryEntry[order],
|
||||
name = categoryEntry[name],
|
||||
default = categoryEntry[isDefault],
|
||||
includeInUpdate = IncludeOrExclude.fromValue(categoryEntry[includeInUpdate]),
|
||||
includeInDownload = IncludeOrExclude.fromValue(categoryEntry[includeInDownload]),
|
||||
version = categoryEntry[version],
|
||||
uid = categoryEntry[uid],
|
||||
lastModifiedAt = categoryEntry[lastModifiedAt],
|
||||
)
|
||||
|
||||
@@ -7,15 +7,13 @@ package suwayomi.tachidesk.manga.model.table
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.v1.core.ReferenceOption
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import suwayomi.tachidesk.manga.impl.Chapter.getChapterMetaMap
|
||||
import suwayomi.tachidesk.manga.model.dataclass.ChapterDataClass
|
||||
import suwayomi.tachidesk.manga.model.table.columns.truncatingVarchar
|
||||
import suwayomi.tachidesk.manga.model.table.columns.unlimitedVarchar
|
||||
|
||||
object ChapterTable : IntIdTable() {
|
||||
val url = varchar("url", 2048)
|
||||
@@ -46,47 +44,29 @@ object ChapterTable : IntIdTable() {
|
||||
val lastModifiedAt = long("last_modified_at").default(0)
|
||||
val version = long("version").default(0)
|
||||
val isSyncing = bool("is_syncing").default(false)
|
||||
|
||||
val memo = unlimitedVarchar("memo")
|
||||
}
|
||||
|
||||
fun ChapterTable.toDataClass(
|
||||
chapterEntry: ResultRow,
|
||||
includeChapterCount: Boolean = true,
|
||||
includeChapterMeta: Boolean = true,
|
||||
) = ChapterDataClass(
|
||||
id = chapterEntry[id].value,
|
||||
url = chapterEntry[url],
|
||||
name = chapterEntry[name],
|
||||
uploadDate = chapterEntry[date_upload],
|
||||
chapterNumber = chapterEntry[chapter_number],
|
||||
scanlator = chapterEntry[scanlator],
|
||||
mangaId = chapterEntry[manga].value,
|
||||
read = chapterEntry[isRead],
|
||||
bookmarked = chapterEntry[isBookmarked],
|
||||
lastPageRead = chapterEntry[lastPageRead],
|
||||
lastReadAt = chapterEntry[lastReadAt],
|
||||
index = chapterEntry[sourceOrder],
|
||||
fetchedAt = chapterEntry[fetchedAt],
|
||||
realUrl = chapterEntry[realUrl],
|
||||
downloaded = chapterEntry[isDownloaded],
|
||||
pageCount = chapterEntry[pageCount],
|
||||
chapterCount =
|
||||
if (includeChapterCount) {
|
||||
transaction {
|
||||
ChapterTable
|
||||
.selectAll()
|
||||
.where { manga eq chapterEntry[manga].value }
|
||||
.count()
|
||||
.toInt()
|
||||
}
|
||||
} else {
|
||||
null
|
||||
},
|
||||
meta =
|
||||
if (includeChapterMeta) {
|
||||
getChapterMetaMap(chapterEntry[id])
|
||||
} else {
|
||||
emptyMap()
|
||||
},
|
||||
lastModifiedAt = chapterEntry[lastModifiedAt],
|
||||
version = chapterEntry[version],
|
||||
)
|
||||
fun ChapterTable.toDataClass(chapterEntry: ResultRow) =
|
||||
ChapterDataClass(
|
||||
id = chapterEntry[id].value,
|
||||
url = chapterEntry[url],
|
||||
name = chapterEntry[name],
|
||||
uploadDate = chapterEntry[date_upload],
|
||||
chapterNumber = chapterEntry[chapter_number],
|
||||
scanlator = chapterEntry[scanlator],
|
||||
mangaId = chapterEntry[manga].value,
|
||||
read = chapterEntry[isRead],
|
||||
bookmarked = chapterEntry[isBookmarked],
|
||||
lastPageRead = chapterEntry[lastPageRead],
|
||||
lastReadAt = chapterEntry[lastReadAt],
|
||||
index = chapterEntry[sourceOrder],
|
||||
fetchedAt = chapterEntry[fetchedAt],
|
||||
realUrl = chapterEntry[realUrl],
|
||||
downloaded = chapterEntry[isDownloaded],
|
||||
pageCount = chapterEntry[pageCount],
|
||||
lastModifiedAt = chapterEntry[lastModifiedAt],
|
||||
version = chapterEntry[version],
|
||||
memo = Json.decodeFromString(chapterEntry[memo]),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package suwayomi.tachidesk.manga.model.table
|
||||
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
||||
|
||||
object ExtensionStoreTable : IntIdTable() {
|
||||
val indexUrl = varchar("index_url", 2048).uniqueIndex()
|
||||
val name = varchar("name", 256)
|
||||
val badgeLabel = varchar("badge_label", 32)
|
||||
val signingKey = varchar("signing_key", 512)
|
||||
val contactWebsite = varchar("contact_website", 2048)
|
||||
val contactDiscord = varchar("contact_discord", 2048).nullable()
|
||||
val isLegacy = bool("is_legacy").default(false)
|
||||
val extensionListUrl = varchar("extension_list_url", 2048).nullable()
|
||||
}
|
||||
@@ -10,8 +10,8 @@ package suwayomi.tachidesk.manga.model.table
|
||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
||||
|
||||
object ExtensionTable : IntIdTable() {
|
||||
val apkName = varchar("apk_name", 1024)
|
||||
val repo = varchar("repo", 1024).nullable()
|
||||
val apkName = varchar("apk_name", 1024).nullable()
|
||||
val storeIndexUrl = varchar("store_index_url", 2048).nullable().index()
|
||||
|
||||
// default is the local source icon from tachiyomi
|
||||
@Suppress("ktlint:standard:max-line-length")
|
||||
@@ -23,10 +23,12 @@ object ExtensionTable : IntIdTable() {
|
||||
|
||||
val name = varchar("name", 128)
|
||||
val pkgName = varchar("pkg_name", 128)
|
||||
val apkUrl = varchar("apk_url", 2048)
|
||||
val extensionLib = varchar("extension_lib", 16).nullable()
|
||||
val versionName = varchar("version_name", 16)
|
||||
val versionCode = integer("version_code")
|
||||
val versionCode = long("version_code")
|
||||
val lang = varchar("lang", 32)
|
||||
val isNsfw = bool("is_nsfw")
|
||||
val contentWarning = integer("content_warning")
|
||||
|
||||
val isInstalled = bool("is_installed").default(false)
|
||||
val hasUpdate = bool("has_update").default(false)
|
||||
|
||||
@@ -9,13 +9,12 @@ package suwayomi.tachidesk.manga.model.table
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.UpdateStrategy
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.v1.core.ResultRow
|
||||
import org.jetbrains.exposed.v1.core.dao.id.IntIdTable
|
||||
import suwayomi.tachidesk.manga.impl.Manga.getMangaMetaMap
|
||||
import suwayomi.tachidesk.manga.impl.MangaList.proxyThumbnailUrl
|
||||
import suwayomi.tachidesk.manga.model.dataclass.MangaDataClass
|
||||
import suwayomi.tachidesk.manga.model.dataclass.toGenreList
|
||||
import suwayomi.tachidesk.manga.model.table.MangaStatus.Companion
|
||||
import suwayomi.tachidesk.manga.model.table.columns.truncatingVarchar
|
||||
import suwayomi.tachidesk.manga.model.table.columns.unlimitedVarchar
|
||||
|
||||
@@ -50,39 +49,33 @@ object MangaTable : IntIdTable() {
|
||||
val lastModifiedAt = long("last_modified_at").default(0)
|
||||
val version = long("version").default(0)
|
||||
val isSyncing = bool("is_syncing").default(false)
|
||||
val memo = unlimitedVarchar("memo")
|
||||
}
|
||||
|
||||
fun MangaTable.toDataClass(
|
||||
mangaEntry: ResultRow,
|
||||
includeMangaMeta: Boolean = true,
|
||||
) = MangaDataClass(
|
||||
id = mangaEntry[this.id].value,
|
||||
sourceId = mangaEntry[sourceReference].toString(),
|
||||
url = mangaEntry[url],
|
||||
title = mangaEntry[title],
|
||||
thumbnailUrl = proxyThumbnailUrl(mangaEntry[this.id].value),
|
||||
thumbnailUrlLastFetched = mangaEntry[thumbnailUrlLastFetched],
|
||||
initialized = mangaEntry[initialized],
|
||||
artist = mangaEntry[artist],
|
||||
author = mangaEntry[author],
|
||||
description = mangaEntry[description],
|
||||
genre = mangaEntry[genre].toGenreList(),
|
||||
status = Companion.valueOf(mangaEntry[status]).name,
|
||||
inLibrary = mangaEntry[inLibrary],
|
||||
inLibraryAt = mangaEntry[inLibraryAt],
|
||||
meta =
|
||||
if (includeMangaMeta) {
|
||||
getMangaMetaMap(mangaEntry[id].value)
|
||||
} else {
|
||||
emptyMap()
|
||||
},
|
||||
realUrl = mangaEntry[realUrl],
|
||||
lastFetchedAt = mangaEntry[lastFetchedAt],
|
||||
chaptersLastFetchedAt = mangaEntry[chaptersLastFetchedAt],
|
||||
updateStrategy = UpdateStrategy.valueOf(mangaEntry[updateStrategy]),
|
||||
lastModifiedAt = mangaEntry[lastModifiedAt],
|
||||
version = mangaEntry[version],
|
||||
)
|
||||
fun MangaTable.toDataClass(mangaEntry: ResultRow) =
|
||||
MangaDataClass(
|
||||
id = mangaEntry[this.id].value,
|
||||
sourceId = mangaEntry[sourceReference].toString(),
|
||||
url = mangaEntry[url],
|
||||
title = mangaEntry[title],
|
||||
thumbnailUrl = proxyThumbnailUrl(mangaEntry[this.id].value),
|
||||
thumbnailUrlLastFetched = mangaEntry[thumbnailUrlLastFetched],
|
||||
initialized = mangaEntry[initialized],
|
||||
artist = mangaEntry[artist],
|
||||
author = mangaEntry[author],
|
||||
description = mangaEntry[description],
|
||||
genre = mangaEntry[genre].toGenreList(),
|
||||
status = MangaStatus.valueOf(mangaEntry[status]).name,
|
||||
inLibrary = mangaEntry[inLibrary],
|
||||
inLibraryAt = mangaEntry[inLibraryAt],
|
||||
realUrl = mangaEntry[realUrl],
|
||||
lastFetchedAt = mangaEntry[lastFetchedAt],
|
||||
chaptersLastFetchedAt = mangaEntry[chaptersLastFetchedAt],
|
||||
updateStrategy = UpdateStrategy.valueOf(mangaEntry[updateStrategy]),
|
||||
lastModifiedAt = mangaEntry[lastModifiedAt],
|
||||
version = mangaEntry[version],
|
||||
memo = Json.decodeFromString(mangaEntry[memo]),
|
||||
)
|
||||
|
||||
enum class MangaStatus(
|
||||
val value: Int,
|
||||
|
||||
@@ -14,5 +14,5 @@ object SourceTable : IdTable<Long>() {
|
||||
val name = varchar("name", 128)
|
||||
val lang = varchar("lang", 32)
|
||||
val extension = reference("extension", ExtensionTable)
|
||||
val isNsfw = bool("is_nsfw").default(false)
|
||||
val contentWarning = integer("content_warning").default(0)
|
||||
}
|
||||
|
||||
@@ -13,18 +13,22 @@ object OpdsAPI {
|
||||
// OPDS Search Description Feed
|
||||
get("search", OpdsV1Controller.searchFeed)
|
||||
|
||||
// --- Main Navigation Feeds ---
|
||||
|
||||
// Explore Navigation Feed
|
||||
get("explore", OpdsV1Controller.exploreSourcesFeed)
|
||||
|
||||
// Reading History Acquisition Feed
|
||||
get("history", OpdsV1Controller.historyFeed)
|
||||
|
||||
// Library Updates Acquisition Feed
|
||||
get("library-updates", OpdsV1Controller.libraryUpdatesFeed)
|
||||
|
||||
// --- Library-Specific Feeds ---
|
||||
// --- Remote Catalog Exploration ---
|
||||
// List of available online sources
|
||||
get("explore", OpdsV1Controller.exploreSourcesFeed)
|
||||
|
||||
// Browse series from a specific online source
|
||||
path("explore/source/{sourceId}") {
|
||||
get(OpdsV1Controller.exploreSourceFeed)
|
||||
}
|
||||
|
||||
// --- Library Navigation Feeds ---
|
||||
path("library") {
|
||||
// All Series in Library / Search Results Feed (Acquisition)
|
||||
get("series", OpdsV1Controller.seriesFeed)
|
||||
@@ -32,11 +36,6 @@ object OpdsAPI {
|
||||
// Library Sources Navigation Feed
|
||||
get("sources", OpdsV1Controller.librarySourcesFeed)
|
||||
|
||||
// Library Source-Specific Series Acquisition Feed
|
||||
path("source/{sourceId}") {
|
||||
get(OpdsV1Controller.librarySourceFeed)
|
||||
}
|
||||
|
||||
// Library Categories Navigation Feed
|
||||
get("categories", OpdsV1Controller.categoriesFeed)
|
||||
|
||||
@@ -50,26 +49,10 @@ object OpdsAPI {
|
||||
get("languages", OpdsV1Controller.languagesFeed)
|
||||
}
|
||||
|
||||
// --- Explore-Specific Feeds ---
|
||||
|
||||
// All Sources Navigation Feed (Explore)
|
||||
get("sources", OpdsV1Controller.exploreSourcesFeed)
|
||||
|
||||
// Source-Specific Series Acquisition Feed (Explore)
|
||||
// --- Library Series Filters ---
|
||||
// Source-Specific Series Acquisition Feed (Library)
|
||||
path("source/{sourceId}") {
|
||||
get(OpdsV1Controller.exploreSourceFeed)
|
||||
}
|
||||
|
||||
// --- Item-Specific Feeds (Apply to both Library and Explore contexts) ---
|
||||
|
||||
// Series Chapters Acquisition Feed
|
||||
path("series/{seriesId}/chapters") {
|
||||
get(OpdsV1Controller.seriesChaptersFeed)
|
||||
}
|
||||
|
||||
// Chapter Metadata Acquisition Feed
|
||||
path("series/{seriesId}/chapter/{chapterIndex}/metadata") {
|
||||
get(OpdsV1Controller.chapterMetadataFeed)
|
||||
get(OpdsV1Controller.librarySourceFeed)
|
||||
}
|
||||
|
||||
// Category-Specific Series Acquisition Feed (Library)
|
||||
@@ -91,6 +74,16 @@ object OpdsAPI {
|
||||
path("language/{langCode}") {
|
||||
get(OpdsV1Controller.languageFeed)
|
||||
}
|
||||
|
||||
// --- Item Specific Feeds ---
|
||||
// Series Chapters Acquisition Feed
|
||||
path("series/{seriesId}/chapters") {
|
||||
get(OpdsV1Controller.seriesChaptersFeed)
|
||||
}
|
||||
// Chapter Metadata Acquisition Feed
|
||||
path("series/{seriesId}/chapter/{chapterIndex}/metadata") {
|
||||
get(OpdsV1Controller.chapterMetadataFeed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,21 +32,21 @@ object OpdsV1Controller {
|
||||
*/
|
||||
private fun getLibraryFeed(
|
||||
ctx: Context,
|
||||
pageNum: Int?,
|
||||
locale: Locale,
|
||||
criteria: OpdsMangaFilter,
|
||||
isSearch: Boolean,
|
||||
pageNum: Int,
|
||||
) {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, ctx.queryParam("lang"))
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getLibraryFeed(
|
||||
criteria = criteria,
|
||||
baseUrl = BASE_URL,
|
||||
pageNum = pageNum ?: 1,
|
||||
sort = criteria.sort,
|
||||
filter = criteria.filter,
|
||||
locale = locale,
|
||||
isSearch = isSearch,
|
||||
BASE_URL,
|
||||
locale,
|
||||
criteria,
|
||||
isSearch,
|
||||
pageNum,
|
||||
criteria.sort,
|
||||
criteria.filter,
|
||||
)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
@@ -94,7 +94,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getHistoryFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getHistoryFeed(BASE_URL, locale, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -139,6 +139,7 @@ object OpdsV1Controller {
|
||||
/**
|
||||
* Serves an acquisition feed for all series in the library or search results.
|
||||
* This endpoint handles both general library browsing and specific search queries.
|
||||
* This is the ONLY feed that extracts all the cross-filters from the context.
|
||||
*/
|
||||
val seriesFeed =
|
||||
handler(
|
||||
@@ -157,29 +158,14 @@ object OpdsV1Controller {
|
||||
val opdsSearchCriteria = OpdsSearchCriteria(query, author, title)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getSearchFeed(opdsSearchCriteria, BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getSearchFeed(BASE_URL, locale, opdsSearchCriteria, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val criteria =
|
||||
OpdsMangaFilter(
|
||||
sourceId = ctx.queryParam("source_id")?.toLongOrNull(),
|
||||
categoryId = ctx.queryParam("category_id")?.toIntOrNull(),
|
||||
statusId = ctx.queryParam("status_id")?.toIntOrNull(),
|
||||
genre = ctx.queryParam("genre"),
|
||||
langCode = ctx.queryParam("lang_code"),
|
||||
sort = ctx.queryParam("sort"),
|
||||
filter = ctx.queryParam("filter"),
|
||||
primaryFilter = PrimaryFilterType.NONE,
|
||||
)
|
||||
getLibraryFeed(
|
||||
ctx,
|
||||
pageNumber,
|
||||
criteria,
|
||||
isSearch = false,
|
||||
)
|
||||
val criteria = OpdsMangaFilter.fromContext(ctx, PrimaryFilterType.NONE)
|
||||
getLibraryFeed(ctx, locale, criteria, false, pageNumber ?: 1)
|
||||
}
|
||||
},
|
||||
withResults = { httpCode(HttpStatus.OK) },
|
||||
@@ -203,7 +189,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getExploreSourcesFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getExploreSourcesFeed(BASE_URL, locale, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -230,7 +216,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getLibrarySourcesFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getLibrarySourcesFeed(BASE_URL, locale, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -257,7 +243,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getCategoriesFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getCategoriesFeed(BASE_URL, locale, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -284,7 +270,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getGenresFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getGenresFeed(BASE_URL, locale, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -298,6 +284,7 @@ object OpdsV1Controller {
|
||||
*/
|
||||
val statusesFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
@@ -305,12 +292,12 @@ object OpdsV1Controller {
|
||||
description("Navigation feed listing series publication statuses for the library.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, lang ->
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
ctx.getAttribute(Attribute.TachideskUser).requireUserWithBasicFallback(ctx)
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getStatusFeed(BASE_URL, 1, locale)
|
||||
OpdsFeedBuilder.getStatusFeed(BASE_URL, locale, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -324,6 +311,7 @@ object OpdsV1Controller {
|
||||
*/
|
||||
val languagesFeed =
|
||||
handler(
|
||||
queryParam<Int?>("pageNumber"),
|
||||
queryParam<String?>("lang"),
|
||||
documentWith = {
|
||||
withOperation {
|
||||
@@ -331,12 +319,12 @@ object OpdsV1Controller {
|
||||
description("Navigation feed listing available content languages for series in the library.")
|
||||
}
|
||||
},
|
||||
behaviorOf = { ctx, lang ->
|
||||
behaviorOf = { ctx, pageNumber, lang ->
|
||||
ctx.getAttribute(Attribute.TachideskUser).requireUserWithBasicFallback(ctx)
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getLanguagesFeed(BASE_URL, locale)
|
||||
OpdsFeedBuilder.getLanguagesFeed(BASE_URL, locale, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -363,7 +351,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getLibraryUpdatesFeed(BASE_URL, pageNumber ?: 1, locale)
|
||||
OpdsFeedBuilder.getLibraryUpdatesFeed(BASE_URL, locale, pageNumber ?: 1)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -392,7 +380,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getExploreSourceFeed(sourceId, BASE_URL, pageNumber ?: 1, sort ?: "popular", locale)
|
||||
OpdsFeedBuilder.getExploreSourceFeed(BASE_URL, locale, sourceId, pageNumber ?: 1, sort ?: "popular")
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -425,8 +413,9 @@ object OpdsV1Controller {
|
||||
documentWith = { withOperation { summary("OPDS Library Source Specific Series Feed") } },
|
||||
behaviorOf = { ctx, sourceId ->
|
||||
ctx.getAttribute(Attribute.TachideskUser).requireUserWithBasicFallback(ctx)
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, ctx.queryParam("lang"))
|
||||
val criteria = buildCriteriaFromContext(ctx, OpdsMangaFilter(sourceId = sourceId, primaryFilter = PrimaryFilterType.SOURCE))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria, isSearch = false)
|
||||
getLibraryFeed(ctx, locale, criteria, false, ctx.queryParam("pageNumber")?.toIntOrNull() ?: 1)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -443,9 +432,10 @@ object OpdsV1Controller {
|
||||
documentWith = { withOperation { summary("OPDS Category Specific Series Feed") } },
|
||||
behaviorOf = { ctx, categoryId ->
|
||||
ctx.getAttribute(Attribute.TachideskUser).requireUserWithBasicFallback(ctx)
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, ctx.queryParam("lang"))
|
||||
val criteria =
|
||||
buildCriteriaFromContext(ctx, OpdsMangaFilter(categoryId = categoryId, primaryFilter = PrimaryFilterType.CATEGORY))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria, isSearch = false)
|
||||
getLibraryFeed(ctx, locale, criteria, false, ctx.queryParam("pageNumber")?.toIntOrNull() ?: 1)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -462,8 +452,9 @@ object OpdsV1Controller {
|
||||
documentWith = { withOperation { summary("OPDS Genre Specific Series Feed") } },
|
||||
behaviorOf = { ctx, genre ->
|
||||
ctx.getAttribute(Attribute.TachideskUser).requireUserWithBasicFallback(ctx)
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, ctx.queryParam("lang"))
|
||||
val criteria = buildCriteriaFromContext(ctx, OpdsMangaFilter(genre = genre, primaryFilter = PrimaryFilterType.GENRE))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria, isSearch = false)
|
||||
getLibraryFeed(ctx, locale, criteria, false, ctx.queryParam("pageNumber")?.toIntOrNull() ?: 1)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -480,8 +471,9 @@ object OpdsV1Controller {
|
||||
documentWith = { withOperation { summary("OPDS Status Specific Series Feed") } },
|
||||
behaviorOf = { ctx, statusId ->
|
||||
ctx.getAttribute(Attribute.TachideskUser).requireUserWithBasicFallback(ctx)
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, ctx.queryParam("lang"))
|
||||
val criteria = buildCriteriaFromContext(ctx, OpdsMangaFilter(statusId = statusId, primaryFilter = PrimaryFilterType.STATUS))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria, isSearch = false)
|
||||
getLibraryFeed(ctx, locale, criteria, false, ctx.queryParam("pageNumber")?.toIntOrNull() ?: 1)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -503,9 +495,10 @@ object OpdsV1Controller {
|
||||
},
|
||||
behaviorOf = { ctx, langCode ->
|
||||
ctx.getAttribute(Attribute.TachideskUser).requireUserWithBasicFallback(ctx)
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, ctx.queryParam("lang"))
|
||||
val criteria =
|
||||
buildCriteriaFromContext(ctx, OpdsMangaFilter(langCode = langCode, primaryFilter = PrimaryFilterType.LANGUAGE))
|
||||
getLibraryFeed(ctx, ctx.queryParam("pageNumber")?.toIntOrNull(), criteria, isSearch = false)
|
||||
getLibraryFeed(ctx, locale, criteria, false, ctx.queryParam("pageNumber")?.toIntOrNull() ?: 1)
|
||||
},
|
||||
withResults = {
|
||||
httpCode(HttpStatus.OK)
|
||||
@@ -534,7 +527,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getSeriesChaptersFeed(seriesId, BASE_URL, pageNumber ?: 1, sort, filter, locale)
|
||||
OpdsFeedBuilder.getSeriesChaptersFeed(BASE_URL, locale, seriesId, pageNumber ?: 1, sort, filter)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
@@ -565,7 +558,7 @@ object OpdsV1Controller {
|
||||
val locale: Locale = LocalizationHelper.ctxToLocale(ctx, lang)
|
||||
ctx.future {
|
||||
future {
|
||||
OpdsFeedBuilder.getChapterMetadataFeed(seriesId, chapterIndex, BASE_URL, locale)
|
||||
OpdsFeedBuilder.getChapterMetadataFeed(BASE_URL, locale, seriesId, chapterIndex)
|
||||
}.thenApply { xml ->
|
||||
ctx.contentType(OPDS_MIME).result(xml)
|
||||
}
|
||||
|
||||
@@ -12,4 +12,6 @@ data class OpdsChapterListAcqEntry(
|
||||
val lastReadAt: Long,
|
||||
val sourceOrder: Int,
|
||||
val pageCount: Int, // Can be -1 if not known
|
||||
val downloaded: Boolean,
|
||||
val cbzFileSize: Long? = null,
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ data class OpdsChapterMetadataAcqEntry(
|
||||
val mangaId: Int,
|
||||
val name: String,
|
||||
val uploadDate: Long,
|
||||
val chapterNumber: Float, // Added to fallback chapter titles
|
||||
val scanlator: String?,
|
||||
val read: Boolean,
|
||||
val lastPageRead: Int,
|
||||
@@ -13,4 +14,5 @@ data class OpdsChapterMetadataAcqEntry(
|
||||
val downloaded: Boolean,
|
||||
val pageCount: Int,
|
||||
val url: String?,
|
||||
val cbzFileSize: Long? = null,
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ data class OpdsHistoryAcqEntry(
|
||||
val mangaTitle: String,
|
||||
val mangaAuthor: String?,
|
||||
val mangaId: Int,
|
||||
val mangaTotalChapters: Long,
|
||||
val mangaSourceLang: String?,
|
||||
val mangaThumbnailUrl: String?,
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ data class OpdsLibraryUpdateAcqEntry(
|
||||
val mangaTitle: String,
|
||||
val mangaAuthor: String?,
|
||||
val mangaId: Int,
|
||||
val mangaTotalChapters: Long,
|
||||
val mangaSourceLang: String?,
|
||||
val mangaThumbnailUrl: String?,
|
||||
)
|
||||
|
||||
@@ -5,4 +5,5 @@ data class OpdsMangaDetails( // Kept name, it's specific enough
|
||||
val title: String,
|
||||
val thumbnailUrl: String?,
|
||||
val author: String?, // Added for chapter entry authors
|
||||
val totalChapters: Long, // Added to determine if it's a oneshot
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package suwayomi.tachidesk.opds.dto
|
||||
|
||||
import io.javalin.http.Context
|
||||
import suwayomi.tachidesk.opds.util.OpdsStringUtil.encodeForOpdsURL
|
||||
|
||||
/**
|
||||
@@ -69,4 +70,24 @@ data class OpdsMangaFilter(
|
||||
"genre" -> this.copy(genre = value)
|
||||
else -> this
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Creates an OpdsMangaFilter directly from the Javalin Context, capturing all cross-filters.
|
||||
*/
|
||||
fun fromContext(
|
||||
ctx: Context,
|
||||
primaryFilter: PrimaryFilterType = PrimaryFilterType.NONE,
|
||||
): OpdsMangaFilter =
|
||||
OpdsMangaFilter(
|
||||
sourceId = ctx.queryParam("source_id")?.toLongOrNull(),
|
||||
categoryId = ctx.queryParam("category_id")?.toIntOrNull(),
|
||||
statusId = ctx.queryParam("status_id")?.toIntOrNull(),
|
||||
genre = ctx.queryParam("genre"),
|
||||
langCode = ctx.queryParam("lang_code"),
|
||||
sort = ctx.queryParam("sort"),
|
||||
filter = ctx.queryParam("filter"),
|
||||
primaryFilter = primaryFilter,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,145 +16,131 @@ import kotlin.math.ceil
|
||||
*/
|
||||
class FeedBuilderInternal(
|
||||
private val baseUrl: String,
|
||||
private val locale: Locale,
|
||||
private val idPath: String,
|
||||
private val title: String,
|
||||
private val locale: Locale,
|
||||
private val feedType: String,
|
||||
private val pageNum: Int? = 1,
|
||||
private val pageNum: Int? = null,
|
||||
private val explicitQueryParams: String? = null,
|
||||
private val currentSort: String? = null,
|
||||
private val currentFilter: String? = null,
|
||||
private val isSearchFeed: Boolean = false,
|
||||
) {
|
||||
private val opdsItemsPerPageBounded: Int
|
||||
get() = serverConfig.opdsItemsPerPage.value
|
||||
|
||||
private val feedAuthor = OpdsAuthorXml("Suwayomi", "https://suwayomi.org/")
|
||||
private val feedGeneratedAt: String = OpdsDateUtil.formatCurrentInstantForOpds()
|
||||
|
||||
var totalResults: Long = 0
|
||||
var icon: String? = null
|
||||
val links = mutableListOf<OpdsLinkXml>()
|
||||
val entries = mutableListOf<OpdsEntryXml>()
|
||||
|
||||
private fun buildUrlWithParams(
|
||||
baseHrefPath: String,
|
||||
page: Int?,
|
||||
): String {
|
||||
val sb = StringBuilder("$baseUrl/$baseHrefPath")
|
||||
val queryParamsList = mutableListOf<String>()
|
||||
private fun buildUrlWithParams(page: Int? = pageNum): String {
|
||||
val queryParams =
|
||||
listOfNotNull(
|
||||
explicitQueryParams?.takeIf(String::isNotBlank),
|
||||
page?.let { "pageNumber=$it" },
|
||||
currentSort?.let { "sort=$it" },
|
||||
currentFilter?.let { "filter=$it" },
|
||||
"lang=${locale.toLanguageTag()}",
|
||||
).joinToString("&")
|
||||
|
||||
explicitQueryParams?.takeIf { it.isNotBlank() }?.let { queryParamsList.add(it) }
|
||||
page?.let { queryParamsList.add("pageNumber=$it") }
|
||||
currentSort?.let { queryParamsList.add("sort=$it") }
|
||||
currentFilter?.let { queryParamsList.add("filter=$it") }
|
||||
queryParamsList.add("lang=${locale.toLanguageTag()}")
|
||||
|
||||
if (queryParamsList.isNotEmpty()) {
|
||||
sb.append("?").append(queryParamsList.joinToString("&"))
|
||||
}
|
||||
return sb.toString()
|
||||
return "$baseUrl/$idPath" + if (queryParams.isNotEmpty()) "?$queryParams" else ""
|
||||
}
|
||||
|
||||
fun build(): OpdsFeedXml {
|
||||
val selfLinkHref = buildUrlWithParams(idPath, if (pageNum != null) pageNum else null)
|
||||
val feedLinks = mutableListOf<OpdsLinkXml>()
|
||||
feedLinks.addAll(this.links)
|
||||
|
||||
feedLinks.add(
|
||||
OpdsLinkXml(OpdsConstants.LINK_REL_SELF, selfLinkHref, feedType, MR.strings.opds_linktitle_self_feed.localized(locale)),
|
||||
)
|
||||
feedLinks.add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_START,
|
||||
"$baseUrl?lang=${locale.toLanguageTag()}",
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
MR.strings.opds_linktitle_catalog_root.localized(locale),
|
||||
),
|
||||
)
|
||||
feedLinks.add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_SEARCH,
|
||||
"$baseUrl/search?lang=${locale.toLanguageTag()}",
|
||||
OpdsConstants.TYPE_OPENSEARCH_DESCRIPTION,
|
||||
MR.strings.opds_linktitle_search_catalog.localized(locale),
|
||||
),
|
||||
)
|
||||
|
||||
// Add pagination links if needed
|
||||
if (pageNum != null) {
|
||||
val totalPages = ceil(totalResults.toDouble() / opdsItemsPerPageBounded).toInt()
|
||||
|
||||
if (totalPages > 1) {
|
||||
val currentPage = pageNum.coerceAtLeast(1)
|
||||
|
||||
// Always add 'first' link when there are multiple pages
|
||||
feedLinks.add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_FIRST,
|
||||
buildUrlWithParams(idPath, 1),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_first_page.localized(locale),
|
||||
),
|
||||
)
|
||||
|
||||
// Add 'prev' link if not on first page
|
||||
if (currentPage > 1) {
|
||||
feedLinks.add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_PREV,
|
||||
buildUrlWithParams(idPath, currentPage - 1),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_previous_page.localized(locale),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// Add 'next' link if not on last page
|
||||
if (currentPage < totalPages) {
|
||||
feedLinks.add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_NEXT,
|
||||
buildUrlWithParams(idPath, currentPage + 1),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_next_page.localized(locale),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// Always add 'last' link when there are multiple pages
|
||||
feedLinks.add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_LAST,
|
||||
buildUrlWithParams(idPath, totalPages),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_last_page.localized(locale),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val urnParams = mutableListOf<String>()
|
||||
urnParams.add(locale.toLanguageTag())
|
||||
pageNum?.let { urnParams.add("page$it") }
|
||||
explicitQueryParams?.let { urnParams.add(it.replace("&", ":").replace("=", "_")) }
|
||||
currentSort?.let { urnParams.add("sort_$it") }
|
||||
currentFilter?.let { urnParams.add("filter_$it") }
|
||||
val urnSuffix = if (urnParams.isNotEmpty()) ":${urnParams.joinToString(":")}" else ""
|
||||
|
||||
val showOpenSearchFields = isSearchFeed && pageNum != null && totalResults > 0
|
||||
val itemsPerPage = serverConfig.opdsItemsPerPage.value
|
||||
val showOpenSearch = isSearchFeed && pageNum != null && totalResults > 0
|
||||
val urnSuffix =
|
||||
listOfNotNull(
|
||||
locale.toLanguageTag(),
|
||||
pageNum?.let { "page$it" },
|
||||
explicitQueryParams?.replace("&", ":")?.replace("=", "_"),
|
||||
currentSort?.let { "sort_$it" },
|
||||
currentFilter?.let { "filter_$it" },
|
||||
).joinToString(":")
|
||||
|
||||
return OpdsFeedXml(
|
||||
id = "urn:suwayomi:feed:${idPath.replace('/',':')}$urnSuffix",
|
||||
id = "urn:suwayomi:feed:${idPath.replace('/', ':')}${if (urnSuffix.isNotEmpty()) ":$urnSuffix" else ""}",
|
||||
title = title,
|
||||
updated = feedGeneratedAt,
|
||||
updated = OpdsDateUtil.formatCurrentInstantForOpds(),
|
||||
icon = icon,
|
||||
author = feedAuthor,
|
||||
links = feedLinks,
|
||||
author = OpdsAuthorXml("Suwayomi", "https://suwayomi.org/"),
|
||||
links =
|
||||
buildList {
|
||||
addAll(this@FeedBuilderInternal.links)
|
||||
add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_SELF,
|
||||
buildUrlWithParams(),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_self_feed.localized(locale),
|
||||
),
|
||||
)
|
||||
add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_START,
|
||||
"$baseUrl?lang=${locale.toLanguageTag()}",
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
MR.strings.opds_linktitle_catalog_root.localized(locale),
|
||||
),
|
||||
)
|
||||
add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_SEARCH,
|
||||
"$baseUrl/search?lang=${locale.toLanguageTag()}",
|
||||
OpdsConstants.TYPE_OPENSEARCH_DESCRIPTION,
|
||||
MR.strings.opds_linktitle_search_catalog.localized(locale),
|
||||
),
|
||||
)
|
||||
|
||||
if (pageNum != null) {
|
||||
val totalPages = ceil(totalResults.toDouble() / itemsPerPage).toInt()
|
||||
if (totalPages > 1) {
|
||||
val currentPage = pageNum.coerceAtLeast(1)
|
||||
add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_FIRST,
|
||||
buildUrlWithParams(1),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_first_page.localized(locale),
|
||||
),
|
||||
)
|
||||
if (currentPage >
|
||||
1
|
||||
) {
|
||||
add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_PREV,
|
||||
buildUrlWithParams(currentPage - 1),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_previous_page.localized(locale),
|
||||
),
|
||||
)
|
||||
}
|
||||
if (currentPage <
|
||||
totalPages
|
||||
) {
|
||||
add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_NEXT,
|
||||
buildUrlWithParams(currentPage + 1),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_next_page.localized(locale),
|
||||
),
|
||||
)
|
||||
}
|
||||
add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_LAST,
|
||||
buildUrlWithParams(totalPages),
|
||||
feedType,
|
||||
MR.strings.opds_linktitle_last_page.localized(locale),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
entries = entries,
|
||||
totalResults = totalResults.takeIf { showOpenSearchFields },
|
||||
itemsPerPage = if (showOpenSearchFields) opdsItemsPerPageBounded else null,
|
||||
startIndex = if (showOpenSearchFields) ((pageNum - 1) * opdsItemsPerPageBounded) + 1 else null,
|
||||
totalResults = totalResults.takeIf { showOpenSearch },
|
||||
itemsPerPage = itemsPerPage.takeIf { showOpenSearch },
|
||||
startIndex = if (showOpenSearch && pageNum != null) ((pageNum - 1) * itemsPerPage) + 1 else null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package suwayomi.tachidesk.opds.impl
|
||||
|
||||
import dev.icerock.moko.resources.StringResource
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import suwayomi.tachidesk.i18n.MR
|
||||
import suwayomi.tachidesk.manga.impl.ChapterDownloadHelper
|
||||
import suwayomi.tachidesk.manga.impl.MangaList.proxyThumbnailUrl
|
||||
import suwayomi.tachidesk.manga.impl.sync.KoreaderSyncService
|
||||
import suwayomi.tachidesk.manga.model.table.MangaStatus
|
||||
@@ -93,15 +90,15 @@ object OpdsEntryBuilder {
|
||||
|
||||
/**
|
||||
* Converts a manga data object into a full OPDS acquisition entry.
|
||||
* @param entry The manga data object.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param locale The locale for localization.
|
||||
* @param entry The manga data object.
|
||||
* @return An [OpdsEntryXml] object representing the manga.
|
||||
*/
|
||||
fun mangaAcqEntryToEntry(
|
||||
entry: OpdsMangaAcqEntry,
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
entry: OpdsMangaAcqEntry,
|
||||
): OpdsEntryXml {
|
||||
val displayThumbnailUrl = entry.thumbnailUrl?.let { proxyThumbnailUrl(entry.id) }
|
||||
val categoryScheme = if (entry.inLibrary) "$baseUrl/library/genres" else "$baseUrl/genres"
|
||||
@@ -152,40 +149,151 @@ object OpdsEntryBuilder {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the display title for a chapter, ensuring an empty name falls back to
|
||||
* a generic "Chapter X" or "Oneshot" to keep the OPDS feed clean and usable.
|
||||
*/
|
||||
private fun resolveChapterTitle(
|
||||
chapterName: String,
|
||||
chapterNumber: Float,
|
||||
sourceOrder: Int,
|
||||
totalChapters: Long,
|
||||
locale: Locale,
|
||||
): String {
|
||||
val trimmedName = chapterName.trim()
|
||||
if (trimmedName.isNotEmpty()) {
|
||||
return trimmedName
|
||||
}
|
||||
return if (totalChapters <= 1L) {
|
||||
MR.strings.opds_chapter_title_oneshot.localized(locale)
|
||||
} else {
|
||||
val formatNumber =
|
||||
if (chapterNumber >= 0f) {
|
||||
if (chapterNumber % 1 == 0f) chapterNumber.toInt().toString() else chapterNumber.toString()
|
||||
} else {
|
||||
sourceOrder.toString()
|
||||
}
|
||||
MR.strings.opds_chapter_title_fallback.localized(locale, formatNumber)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an OPDS entry for a chapter, including acquisition and streaming links.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param locale The locale for localization.
|
||||
* @param chapter The chapter data object.
|
||||
* @param manga The parent manga's details.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param addMangaTitle Whether to prepend the manga title to the entry title.
|
||||
* @param locale The locale for localization.
|
||||
* @param skipMetadataFeed Whether to skip the metadata feed.
|
||||
* @return An [OpdsEntryXml] object for the chapter.
|
||||
*/
|
||||
suspend fun createChapterListEntry(
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
chapter: OpdsChapterListAcqEntry,
|
||||
manga: OpdsMangaDetails,
|
||||
baseUrl: String,
|
||||
addMangaTitle: Boolean,
|
||||
locale: Locale,
|
||||
skipMetadataFeed: Boolean,
|
||||
): OpdsEntryXml {
|
||||
var effectiveLastPageRead = chapter.lastPageRead
|
||||
var effectiveLastReadAt = chapter.lastReadAt
|
||||
|
||||
if (skipMetadataFeed) {
|
||||
val syncResult = KoreaderSyncService.checkAndPullProgress(chapter.id)
|
||||
|
||||
// If sync strategy dictates an update (e.g. KEEP_REMOTE), use remote data.
|
||||
// If sync strategy is PROMPT (isConflict=true), we ignore it here (effectively KEEP_LOCAL/DISABLED)
|
||||
// because we cannot show a prompt in the chapter list feed.
|
||||
if (syncResult != null && syncResult.shouldUpdate) {
|
||||
effectiveLastPageRead = syncResult.pageRead
|
||||
effectiveLastReadAt = syncResult.timestamp
|
||||
}
|
||||
}
|
||||
|
||||
val statusKey =
|
||||
when {
|
||||
chapter.downloaded -> MR.strings.opds_chapter_status_downloaded
|
||||
chapter.read -> MR.strings.opds_chapter_status_read
|
||||
chapter.lastPageRead > 0 -> MR.strings.opds_chapter_status_in_progress
|
||||
effectiveLastPageRead > 0 -> MR.strings.opds_chapter_status_in_progress
|
||||
else -> MR.strings.opds_chapter_status_unread
|
||||
}
|
||||
val titlePrefix = statusKey.localized(locale)
|
||||
val entryTitle = titlePrefix + (if (addMangaTitle) " ${manga.title}:" else "") + " ${chapter.name}"
|
||||
val chapterName = resolveChapterTitle(chapter.name, chapter.chapterNumber, chapter.sourceOrder, manga.totalChapters, locale)
|
||||
val entryTitle = titlePrefix + (if (addMangaTitle) " ${manga.title}:" else "") + " $chapterName"
|
||||
val details =
|
||||
buildString {
|
||||
append(MR.strings.opds_chapter_details_base.localized(locale, manga.title, chapter.name))
|
||||
append(MR.strings.opds_chapter_details_base.localized(locale, manga.title, chapterName))
|
||||
chapter.scanlator?.takeIf { it.isNotBlank() }?.let {
|
||||
append(MR.strings.opds_chapter_details_scanlator.localized(locale, it))
|
||||
}
|
||||
if (chapter.pageCount > 0) {
|
||||
append(MR.strings.opds_chapter_details_progress.localized(locale, chapter.lastPageRead, chapter.pageCount))
|
||||
append(MR.strings.opds_chapter_details_progress.localized(locale, effectiveLastPageRead, chapter.pageCount))
|
||||
}
|
||||
}
|
||||
|
||||
val links = mutableListOf<OpdsLinkXml>()
|
||||
|
||||
if (skipMetadataFeed) {
|
||||
// Provide Acquisition Link (Download CBZ) if downloaded
|
||||
if (chapter.downloaded) {
|
||||
links.add(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_ACQUISITION_OPEN_ACCESS,
|
||||
"/api/v1/chapter/${chapter.id}/download?markAsRead=${serverConfig.opdsMarkAsReadOnDownload.value}",
|
||||
serverConfig.opdsCbzMimetype.value.mediaType,
|
||||
MR.strings.opds_linktitle_download_cbz.localized(locale),
|
||||
length = chapter.cbzFileSize,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// Provide Stream Link (OPDS-PSE) if page count is known
|
||||
if (chapter.pageCount > 0) {
|
||||
val basePageHref =
|
||||
"/api/v1/manga/${manga.id}/chapter/${chapter.sourceOrder}/page/{pageNumber}" +
|
||||
"?updateProgress=${serverConfig.opdsEnablePageReadProgress.value}&opds=true"
|
||||
|
||||
val titleRes =
|
||||
if (effectiveLastPageRead > 0) {
|
||||
MR.strings.opds_linktitle_stream_pages_continue
|
||||
} else {
|
||||
MR.strings.opds_linktitle_stream_pages_start
|
||||
}
|
||||
|
||||
links.add(
|
||||
OpdsLinkXml(
|
||||
rel = OpdsConstants.LINK_REL_PSE_STREAM,
|
||||
href = basePageHref,
|
||||
type = OpdsConstants.TYPE_IMAGE_JPEG,
|
||||
title = titleRes.localized(locale),
|
||||
pseCount = chapter.pageCount,
|
||||
pseLastRead = effectiveLastPageRead.takeIf { it > 0 },
|
||||
pseLastReadDate = effectiveLastReadAt.takeIf { it > 0 }?.let { OpdsDateUtil.formatEpochMillisForOpds(it * 1000) },
|
||||
),
|
||||
)
|
||||
|
||||
// Page 0 Cover
|
||||
links.add(
|
||||
OpdsLinkXml(
|
||||
rel = OpdsConstants.LINK_REL_IMAGE,
|
||||
href = "/api/v1/manga/${manga.id}/chapter/${chapter.sourceOrder}/page/0",
|
||||
type = OpdsConstants.TYPE_IMAGE_JPEG,
|
||||
title = MR.strings.opds_linktitle_chapter_cover.localized(locale),
|
||||
),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// Link to Metadata Feed
|
||||
links.add(
|
||||
OpdsLinkXml(
|
||||
rel = OpdsConstants.LINK_REL_SUBSECTION,
|
||||
href = "$baseUrl/series/${manga.id}/chapter/${chapter.sourceOrder}/metadata?lang=${locale.toLanguageTag()}",
|
||||
type = OpdsConstants.TYPE_ATOM_XML_ENTRY_PROFILE_OPDS,
|
||||
title = MR.strings.opds_linktitle_view_chapter_details.localized(locale),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return OpdsEntryXml(
|
||||
id = "urn:suwayomi:chapter:${chapter.id}",
|
||||
title = entryTitle,
|
||||
@@ -196,33 +304,25 @@ object OpdsEntryBuilder {
|
||||
chapter.scanlator?.takeIf { it.isNotBlank() }?.let { OpdsAuthorXml(name = it) },
|
||||
),
|
||||
summary = OpdsSummaryXml(value = details),
|
||||
link =
|
||||
listOf(
|
||||
OpdsLinkXml(
|
||||
rel = OpdsConstants.LINK_REL_SUBSECTION,
|
||||
href = "$baseUrl/series/${manga.id}/chapter/${chapter.sourceOrder}/metadata?lang=${locale.toLanguageTag()}",
|
||||
type = OpdsConstants.TYPE_ATOM_XML_ENTRY_PROFILE_OPDS,
|
||||
title = MR.strings.opds_linktitle_view_chapter_details.localized(locale),
|
||||
),
|
||||
),
|
||||
link = links,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates one or two OPDS entries for a chapter, handling synchronization conflicts internally.
|
||||
*
|
||||
* @param chapter The chapter metadata object.
|
||||
* @param manga The parent manga's details.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param locale The locale for localization.
|
||||
* @param chapter The chapter metadata object.
|
||||
* @param manga The parent manga's details.
|
||||
* @return A `Pair` where the first element is the primary entry (always present) and the
|
||||
* second is an optional entry representing the remote progress in case of a conflict.
|
||||
*/
|
||||
suspend fun createChapterMetadataEntries(
|
||||
chapter: OpdsChapterMetadataAcqEntry,
|
||||
manga: OpdsMangaDetails,
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
chapter: OpdsChapterMetadataAcqEntry,
|
||||
manga: OpdsMangaDetails,
|
||||
): Pair<OpdsEntryXml, OpdsEntryXml?> {
|
||||
// Check remote progress before building the entry
|
||||
val syncResult = KoreaderSyncService.checkAndPullProgress(chapter.id)
|
||||
@@ -234,20 +334,20 @@ object OpdsEntryBuilder {
|
||||
// Generate two entries: one for local progress and another for remote.
|
||||
val localEntry =
|
||||
buildSingleChapterMetadataEntry(
|
||||
chapter,
|
||||
manga,
|
||||
baseUrl,
|
||||
locale,
|
||||
chapter,
|
||||
manga,
|
||||
progressSource = ProgressSource.Local(chapter.lastPageRead, chapter.lastReadAt),
|
||||
isConflict = true,
|
||||
)
|
||||
|
||||
val remoteEntry =
|
||||
buildSingleChapterMetadataEntry(
|
||||
chapter,
|
||||
manga,
|
||||
baseUrl,
|
||||
locale,
|
||||
chapter,
|
||||
manga,
|
||||
progressSource = ProgressSource.Remote(syncResult!!.pageRead, syncResult.timestamp, syncResult.device),
|
||||
isConflict = true,
|
||||
)
|
||||
@@ -263,10 +363,10 @@ object OpdsEntryBuilder {
|
||||
|
||||
val mainEntry =
|
||||
buildSingleChapterMetadataEntry(
|
||||
chapter,
|
||||
manga,
|
||||
baseUrl,
|
||||
locale,
|
||||
chapter,
|
||||
manga,
|
||||
progressSource = progressSource,
|
||||
isConflict = false,
|
||||
)
|
||||
@@ -297,10 +397,10 @@ object OpdsEntryBuilder {
|
||||
* Helper function to build a single OpdsEntryXml for a chapter.
|
||||
*/
|
||||
private suspend fun buildSingleChapterMetadataEntry(
|
||||
chapter: OpdsChapterMetadataAcqEntry,
|
||||
manga: OpdsMangaDetails,
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
chapter: OpdsChapterMetadataAcqEntry,
|
||||
manga: OpdsMangaDetails,
|
||||
progressSource: ProgressSource,
|
||||
isConflict: Boolean,
|
||||
): OpdsEntryXml {
|
||||
@@ -337,14 +437,7 @@ object OpdsEntryBuilder {
|
||||
}
|
||||
|
||||
val entryTitle = "$titlePrefix ${chapter.name}"
|
||||
val cbzFileSize =
|
||||
if (chapter.downloaded) {
|
||||
withContext(Dispatchers.IO) {
|
||||
runCatching { ChapterDownloadHelper.getArchiveStreamWithSize(manga.id, chapter.id).second }.getOrNull()
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val cbzFileSize = chapter.cbzFileSize
|
||||
|
||||
val links = mutableListOf<OpdsLinkXml>()
|
||||
chapter.url?.let {
|
||||
@@ -449,8 +542,8 @@ object OpdsEntryBuilder {
|
||||
fun addSourceSortFacets(
|
||||
feedBuilder: FeedBuilderInternal,
|
||||
baseUrl: String,
|
||||
currentSort: String,
|
||||
locale: Locale,
|
||||
currentSort: String,
|
||||
) {
|
||||
val sortGroup = MR.strings.opds_facetgroup_sort_order.localized(locale)
|
||||
val addFacet = { href: String, titleKey: StringResource, isActive: Boolean ->
|
||||
@@ -475,9 +568,9 @@ object OpdsEntryBuilder {
|
||||
fun addChapterSortAndFilterFacets(
|
||||
feedBuilder: FeedBuilderInternal,
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
currentSort: String,
|
||||
currentFilter: String,
|
||||
locale: Locale,
|
||||
filterCounts: Map<String, Long>? = null,
|
||||
) {
|
||||
val sortGroup = MR.strings.opds_facetgroup_sort_order.localized(locale)
|
||||
@@ -554,15 +647,15 @@ object OpdsEntryBuilder {
|
||||
fun addLibraryFacets(
|
||||
feedBuilder: FeedBuilderInternal,
|
||||
baseUrl: String,
|
||||
activeFilters: OpdsMangaFilter,
|
||||
locale: Locale,
|
||||
activeFilters: OpdsMangaFilter,
|
||||
) {
|
||||
val currentSort = activeFilters.sort ?: "alpha_asc"
|
||||
val currentFilter = activeFilters.filter ?: "all"
|
||||
|
||||
val sortGroup = MR.strings.opds_facetgroup_sort_order.localized(locale)
|
||||
val filterGroup = MR.strings.opds_facetgroup_filter_content.localized(locale)
|
||||
val filterCounts = MangaRepository.getLibraryFilterCounts()
|
||||
val filterCounts = MangaRepository.getLibraryFilterCounts(activeFilters)
|
||||
|
||||
val buildUrl = { newFilters: OpdsMangaFilter, newSort: String, newFilter: String ->
|
||||
val crossFilterParams = newFilters.toCrossFilterQueryParameters()
|
||||
@@ -667,7 +760,7 @@ object OpdsEntryBuilder {
|
||||
|
||||
// --- Cross-Filter Facets ---
|
||||
if (activeFilters.primaryFilter != PrimaryFilterType.SOURCE) {
|
||||
val sources = NavigationRepository.getLibrarySources(1).first
|
||||
val sources = NavigationRepository.getLibrarySources(pageNum = null, activeFilters = activeFilters).first
|
||||
addFacet(
|
||||
feedBuilder,
|
||||
buildUrl(activeFilters.without("source_id"), currentSort, currentFilter),
|
||||
@@ -688,7 +781,7 @@ object OpdsEntryBuilder {
|
||||
}
|
||||
}
|
||||
if (activeFilters.primaryFilter != PrimaryFilterType.CATEGORY) {
|
||||
val categories = NavigationRepository.getCategories(1).first
|
||||
val categories = NavigationRepository.getCategories(pageNum = null, activeFilters = activeFilters).first
|
||||
addFacet(
|
||||
feedBuilder,
|
||||
buildUrl(activeFilters.without("category_id"), currentSort, currentFilter),
|
||||
@@ -709,7 +802,7 @@ object OpdsEntryBuilder {
|
||||
}
|
||||
}
|
||||
if (activeFilters.primaryFilter != PrimaryFilterType.STATUS) {
|
||||
val statuses = NavigationRepository.getStatuses(locale)
|
||||
val statuses = NavigationRepository.getStatuses(locale, pageNum = null, activeFilters = activeFilters).first
|
||||
addFacet(
|
||||
feedBuilder,
|
||||
buildUrl(activeFilters.without("status_id"), currentSort, currentFilter),
|
||||
@@ -730,7 +823,7 @@ object OpdsEntryBuilder {
|
||||
}
|
||||
}
|
||||
if (activeFilters.primaryFilter != PrimaryFilterType.LANGUAGE) {
|
||||
val languages = NavigationRepository.getContentLanguages(locale)
|
||||
val languages = NavigationRepository.getContentLanguages(locale, pageNum = null, activeFilters = activeFilters).first
|
||||
addFacet(
|
||||
feedBuilder,
|
||||
buildUrl(activeFilters.without("lang_code"), currentSort, currentFilter),
|
||||
@@ -751,7 +844,7 @@ object OpdsEntryBuilder {
|
||||
}
|
||||
}
|
||||
if (activeFilters.primaryFilter != PrimaryFilterType.GENRE) {
|
||||
val genres = NavigationRepository.getGenres(1, locale).first
|
||||
val genres = NavigationRepository.getGenres(locale, pageNum = null, activeFilters = activeFilters).first
|
||||
addFacet(
|
||||
feedBuilder,
|
||||
buildUrl(activeFilters.without("genre"), currentSort, currentFilter),
|
||||
|
||||
@@ -3,6 +3,7 @@ package suwayomi.tachidesk.opds.impl
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import org.jetbrains.exposed.v1.core.SortOrder
|
||||
import suwayomi.tachidesk.i18n.MR
|
||||
import suwayomi.tachidesk.manga.impl.Manga
|
||||
import suwayomi.tachidesk.manga.impl.MangaList.proxyThumbnailUrl
|
||||
import suwayomi.tachidesk.manga.model.table.ChapterTable
|
||||
import suwayomi.tachidesk.opds.constants.OpdsConstants
|
||||
@@ -40,12 +41,11 @@ object OpdsFeedBuilder {
|
||||
val navItems = NavigationRepository.getRootNavigationItems(locale)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"", // Root path is empty
|
||||
MR.strings.opds_feeds_root.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
null,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "", // Root path is empty
|
||||
title = MR.strings.opds_feeds_root.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
)
|
||||
builder.totalResults = navItems.size.toLong()
|
||||
builder.entries.addAll(
|
||||
@@ -73,30 +73,39 @@ object OpdsFeedBuilder {
|
||||
/**
|
||||
* Generates the history feed showing recently read chapters.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param locale The locale for localization.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @return An XML string representing the history feed.
|
||||
*/
|
||||
suspend fun getHistoryFeed(
|
||||
baseUrl: String,
|
||||
pageNum: Int,
|
||||
locale: Locale,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val (historyItems, total) = ChapterRepository.getHistory(pageNum)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"history",
|
||||
MR.strings.opds_feeds_history_title.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "history",
|
||||
title = MR.strings.opds_feeds_history_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum = pageNum,
|
||||
)
|
||||
builder.totalResults = total
|
||||
val skipMetadata = serverConfig.opdsSkipChapterMetadataFeed.value
|
||||
builder.entries.addAll(
|
||||
historyItems.map { item ->
|
||||
val mangaDetails = OpdsMangaDetails(item.mangaId, item.mangaTitle, item.mangaThumbnailUrl, item.mangaAuthor)
|
||||
OpdsEntryBuilder.createChapterListEntry(item.chapter, mangaDetails, baseUrl, true, locale)
|
||||
val mangaDetails =
|
||||
OpdsMangaDetails(item.mangaId, item.mangaTitle, item.mangaThumbnailUrl, item.mangaAuthor, item.mangaTotalChapters)
|
||||
OpdsEntryBuilder.createChapterListEntry(
|
||||
baseUrl,
|
||||
locale,
|
||||
item.chapter,
|
||||
mangaDetails,
|
||||
true,
|
||||
skipMetadata,
|
||||
)
|
||||
},
|
||||
)
|
||||
return OpdsXmlUtil.serializeFeedToString(builder.build())
|
||||
@@ -104,54 +113,55 @@ object OpdsFeedBuilder {
|
||||
|
||||
/**
|
||||
* Generates a feed for search results based on the provided criteria.
|
||||
* @param criteria The search criteria.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param locale The locale for localization.
|
||||
* @param criteria The search criteria.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @return An XML string representing the search results feed.
|
||||
*/
|
||||
fun getSearchFeed(
|
||||
criteria: OpdsSearchCriteria,
|
||||
baseUrl: String,
|
||||
pageNum: Int,
|
||||
locale: Locale,
|
||||
criteria: OpdsSearchCriteria,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val (mangaEntries, total) = MangaRepository.findMangaByCriteria(criteria)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"library/series",
|
||||
MR.strings.opds_feeds_search_results_title.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "library/series",
|
||||
title = MR.strings.opds_feeds_search_results_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum = pageNum,
|
||||
isSearchFeed = true,
|
||||
)
|
||||
builder.totalResults = total
|
||||
builder.entries.addAll(mangaEntries.map { OpdsEntryBuilder.mangaAcqEntryToEntry(it, baseUrl, locale) })
|
||||
builder.entries.addAll(mangaEntries.map { OpdsEntryBuilder.mangaAcqEntryToEntry(baseUrl, locale, it) })
|
||||
return OpdsXmlUtil.serializeFeedToString(builder.build())
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a generic library feed based on various filtering and sorting criteria.
|
||||
* @param criteria The filtering criteria.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param locale The locale for localization.
|
||||
* @param criteria The filtering criteria.
|
||||
* @param isSearch Indicates if it's a search feed.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param sort The sorting parameter.
|
||||
* @param filter The filtering parameter.
|
||||
* @param locale The locale for localization.
|
||||
* @return An XML string representing the library feed.
|
||||
*/
|
||||
fun getLibraryFeed(
|
||||
criteria: OpdsMangaFilter,
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
criteria: OpdsMangaFilter,
|
||||
isSearch: Boolean,
|
||||
pageNum: Int,
|
||||
sort: String?,
|
||||
filter: String?,
|
||||
locale: Locale,
|
||||
isSearch: Boolean,
|
||||
): String {
|
||||
val result = MangaRepository.getLibraryManga(pageNum, sort, filter, criteria)
|
||||
val result = MangaRepository.getLibraryManga(criteria, pageNum, sort, filter)
|
||||
|
||||
val feedTitle =
|
||||
when (criteria.primaryFilter) {
|
||||
@@ -177,7 +187,12 @@ object OpdsFeedBuilder {
|
||||
}
|
||||
|
||||
PrimaryFilterType.STATUS -> {
|
||||
val statusName = NavigationRepository.getStatuses(locale).find { it.id == criteria.statusId }?.title
|
||||
val statusName =
|
||||
NavigationRepository
|
||||
.getStatuses(locale, pageNum = null, activeFilters = criteria)
|
||||
.first
|
||||
.find { it.id == criteria.statusId }
|
||||
?.title
|
||||
MR.strings.opds_feeds_status_specific_title.localized(locale, statusName ?: criteria.statusId.toString())
|
||||
}
|
||||
|
||||
@@ -193,7 +208,7 @@ object OpdsFeedBuilder {
|
||||
|
||||
val feedUrl =
|
||||
when (criteria.primaryFilter) {
|
||||
PrimaryFilterType.SOURCE -> "library/source/${criteria.sourceId}"
|
||||
PrimaryFilterType.SOURCE -> "source/${criteria.sourceId}"
|
||||
PrimaryFilterType.CATEGORY -> "category/${criteria.categoryId}"
|
||||
PrimaryFilterType.GENRE -> "genre/${criteria.genre}"
|
||||
PrimaryFilterType.STATUS -> "status/${criteria.statusId}"
|
||||
@@ -203,23 +218,23 @@ object OpdsFeedBuilder {
|
||||
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
feedUrl,
|
||||
feedTitle,
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = feedUrl,
|
||||
title = feedTitle,
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum = pageNum,
|
||||
explicitQueryParams = criteria.toCrossFilterQueryParameters(),
|
||||
currentSort = criteria.sort,
|
||||
currentFilter = criteria.filter,
|
||||
explicitQueryParams = criteria.toCrossFilterQueryParameters(),
|
||||
isSearchFeed = isSearch,
|
||||
)
|
||||
builder.totalResults = result.totalCount
|
||||
|
||||
// Add all library facets (sort, filter, and cross-filtering)
|
||||
OpdsEntryBuilder.addLibraryFacets(builder, baseUrl, criteria, locale)
|
||||
OpdsEntryBuilder.addLibraryFacets(builder, baseUrl, locale, criteria)
|
||||
|
||||
builder.entries.addAll(result.mangaEntries.map { OpdsEntryBuilder.mangaAcqEntryToEntry(it, baseUrl, locale) })
|
||||
builder.entries.addAll(result.mangaEntries.map { OpdsEntryBuilder.mangaAcqEntryToEntry(baseUrl, locale, it) })
|
||||
|
||||
return OpdsXmlUtil.serializeFeedToString(builder.build())
|
||||
}
|
||||
@@ -227,24 +242,24 @@ object OpdsFeedBuilder {
|
||||
/**
|
||||
* Generates a navigation feed listing all available sources for exploration.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param locale The locale for localization.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @return An XML string representing the explore sources feed.
|
||||
*/
|
||||
fun getExploreSourcesFeed(
|
||||
baseUrl: String,
|
||||
pageNum: Int,
|
||||
locale: Locale,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val (sourceNavEntries, total) = NavigationRepository.getExploreSources(pageNum)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"sources",
|
||||
MR.strings.opds_feeds_sources_title.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "sources",
|
||||
title = MR.strings.opds_feeds_sources_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum = pageNum,
|
||||
)
|
||||
builder.totalResults = total
|
||||
builder.entries.addAll(
|
||||
@@ -257,7 +272,7 @@ object OpdsFeedBuilder {
|
||||
listOf(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_SUBSECTION,
|
||||
"$baseUrl/source/${entry.id}?sort=popular&lang=${locale.toLanguageTag()}",
|
||||
"$baseUrl/explore/source/${entry.id}?sort=popular&lang=${locale.toLanguageTag()}",
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
),
|
||||
),
|
||||
@@ -270,24 +285,24 @@ object OpdsFeedBuilder {
|
||||
/**
|
||||
* Generates a navigation feed listing sources for series present in the library.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param locale The locale for localization.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @return An XML string representing the library sources feed.
|
||||
*/
|
||||
fun getLibrarySourcesFeed(
|
||||
baseUrl: String,
|
||||
pageNum: Int,
|
||||
locale: Locale,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val (sourceNavEntries, total) = NavigationRepository.getLibrarySources(pageNum)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"library/sources",
|
||||
MR.strings.opds_feeds_library_sources_title.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "library/sources",
|
||||
title = MR.strings.opds_feeds_library_sources_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum = pageNum,
|
||||
)
|
||||
builder.totalResults = total
|
||||
builder.entries.addAll(
|
||||
@@ -300,7 +315,7 @@ object OpdsFeedBuilder {
|
||||
listOf(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_SUBSECTION,
|
||||
"$baseUrl/library/source/${entry.id}?lang=${locale.toLanguageTag()}",
|
||||
"$baseUrl/source/${entry.id}?lang=${locale.toLanguageTag()}",
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
entry.name,
|
||||
thrCount = entry.mangaCount?.toInt(),
|
||||
@@ -314,78 +329,75 @@ object OpdsFeedBuilder {
|
||||
|
||||
/**
|
||||
* Generates an acquisition feed for manga from a specific source (explore context).
|
||||
* @param sourceId The ID of the source.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param locale The locale for localization.
|
||||
* @param sourceId The ID of the source.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param sort The sorting parameter ('popular' or 'latest').
|
||||
* @param locale The locale for localization.
|
||||
* @return An XML string representing the source-specific feed.
|
||||
*/
|
||||
suspend fun getExploreSourceFeed(
|
||||
sourceId: Long,
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
sourceId: Long,
|
||||
pageNum: Int,
|
||||
sort: String,
|
||||
locale: Locale,
|
||||
): String {
|
||||
val (mangaEntries, hasNextPage) = MangaRepository.getMangaBySource(sourceId, pageNum, sort)
|
||||
val sourceNavEntry = NavigationRepository.getExploreSources(1).first.find { it.id == sourceId }
|
||||
val sourceNameOrId = sourceNavEntry?.name ?: sourceId.toString()
|
||||
val sourceInfo = NavigationRepository.getSourceDetails(sourceId)
|
||||
val sourceName = sourceInfo?.first ?: sourceId.toString()
|
||||
val titleRes =
|
||||
if (sort == "latest") {
|
||||
if (sort ==
|
||||
"latest"
|
||||
) {
|
||||
MR.strings.opds_feeds_source_specific_latest_title
|
||||
} else {
|
||||
MR.strings.opds_feeds_source_specific_popular_title
|
||||
}
|
||||
val feedTitle = titleRes.localized(locale, sourceNameOrId)
|
||||
val feedUrl = "source/$sourceId"
|
||||
val feedTitle = titleRes.localized(locale, sourceName)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
feedUrl,
|
||||
feedTitle,
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "explore/source/$sourceId",
|
||||
title = feedTitle,
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum = pageNum,
|
||||
currentSort = sort,
|
||||
)
|
||||
builder.totalResults =
|
||||
if (hasNextPage) {
|
||||
(pageNum * serverConfig.opdsItemsPerPage.value + 1).toLong()
|
||||
} else {
|
||||
(
|
||||
(pageNum - 1) *
|
||||
serverConfig.opdsItemsPerPage.value +
|
||||
mangaEntries.size
|
||||
).toLong()
|
||||
((pageNum - 1) * serverConfig.opdsItemsPerPage.value + mangaEntries.size).toLong()
|
||||
}
|
||||
builder.icon = sourceNavEntry?.iconUrl
|
||||
OpdsEntryBuilder.addSourceSortFacets(builder, "$baseUrl/$feedUrl", sort, locale)
|
||||
builder.entries.addAll(mangaEntries.map { OpdsEntryBuilder.mangaAcqEntryToEntry(it, baseUrl, locale) })
|
||||
builder.icon = sourceInfo?.second
|
||||
OpdsEntryBuilder.addSourceSortFacets(builder, "$baseUrl/explore/source/$sourceId", locale, sort)
|
||||
builder.entries.addAll(mangaEntries.map { OpdsEntryBuilder.mangaAcqEntryToEntry(baseUrl, locale, it) })
|
||||
return OpdsXmlUtil.serializeFeedToString(builder.build())
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a navigation feed for library categories.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param locale The locale for localization.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @return An XML string representing the categories navigation feed.
|
||||
*/
|
||||
fun getCategoriesFeed(
|
||||
baseUrl: String,
|
||||
pageNum: Int,
|
||||
locale: Locale,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val (categoryNavEntries, total) = NavigationRepository.getCategories(pageNum)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"library/categories",
|
||||
MR.strings.opds_feeds_categories_title.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "library/categories",
|
||||
title = MR.strings.opds_feeds_categories_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum = pageNum,
|
||||
)
|
||||
builder.totalResults = total
|
||||
builder.entries.addAll(
|
||||
@@ -413,24 +425,24 @@ object OpdsFeedBuilder {
|
||||
/**
|
||||
* Generates a navigation feed for library genres.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param locale The locale for localization.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @return An XML string representing the genres navigation feed.
|
||||
*/
|
||||
fun getGenresFeed(
|
||||
baseUrl: String,
|
||||
pageNum: Int,
|
||||
locale: Locale,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val (genreNavEntries, total) = NavigationRepository.getGenres(pageNum, locale)
|
||||
val (genreNavEntries, total) = NavigationRepository.getGenres(locale, pageNum)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"library/genres",
|
||||
MR.strings.opds_feeds_genres_title.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "library/genres",
|
||||
title = MR.strings.opds_feeds_genres_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum = pageNum,
|
||||
)
|
||||
builder.totalResults = total
|
||||
builder.entries.addAll(
|
||||
@@ -458,26 +470,26 @@ object OpdsFeedBuilder {
|
||||
/**
|
||||
* Generates a navigation feed for manga publication statuses.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param pageNum The page number (currently unused).
|
||||
* @param locale The locale for localization.
|
||||
* @param pageNum The page number (currently unused).
|
||||
* @return An XML string representing the status navigation feed.
|
||||
*/
|
||||
fun getStatusFeed(
|
||||
baseUrl: String,
|
||||
@Suppress("UNUSED_PARAMETER") pageNum: Int,
|
||||
locale: Locale,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val statuses = NavigationRepository.getStatuses(locale)
|
||||
val (statuses, total) = NavigationRepository.getStatuses(locale, pageNum)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"library/statuses",
|
||||
MR.strings.opds_feeds_status_title.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
null,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "library/statuses",
|
||||
title = MR.strings.opds_feeds_status_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum = pageNum,
|
||||
)
|
||||
builder.totalResults = statuses.size.toLong()
|
||||
builder.totalResults = total
|
||||
builder.entries.addAll(
|
||||
statuses.map { entry ->
|
||||
OpdsEntryXml(
|
||||
@@ -503,24 +515,26 @@ object OpdsFeedBuilder {
|
||||
/**
|
||||
* Generates a navigation feed for content languages available in the library.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param uiLocale The locale for the user interface.
|
||||
* @param locale The locale for the user interface.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @return An XML string representing the languages navigation feed.
|
||||
*/
|
||||
fun getLanguagesFeed(
|
||||
baseUrl: String,
|
||||
uiLocale: Locale,
|
||||
locale: Locale,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val languages = NavigationRepository.getContentLanguages(uiLocale)
|
||||
val (languages, total) = NavigationRepository.getContentLanguages(locale, pageNum)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"library/languages",
|
||||
MR.strings.opds_feeds_languages_title.localized(uiLocale),
|
||||
uiLocale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
null,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "library/languages",
|
||||
title = MR.strings.opds_feeds_languages_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_NAVIGATION,
|
||||
pageNum = pageNum,
|
||||
)
|
||||
builder.totalResults = languages.size.toLong()
|
||||
builder.totalResults = total
|
||||
builder.entries.addAll(
|
||||
languages.map { entry ->
|
||||
OpdsEntryXml(
|
||||
@@ -531,7 +545,7 @@ object OpdsFeedBuilder {
|
||||
listOf(
|
||||
OpdsLinkXml(
|
||||
OpdsConstants.LINK_REL_SUBSECTION,
|
||||
"$baseUrl/language/${entry.id}?lang=${uiLocale.toLanguageTag()}",
|
||||
"$baseUrl/language/${entry.id}?lang=${locale.toLanguageTag()}",
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
entry.title,
|
||||
thrCount = entry.mangaCount.toInt(),
|
||||
@@ -544,32 +558,41 @@ object OpdsFeedBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an acquisition feed for recent chapter updates in the library.
|
||||
* Generates an acquisition feed of recent chapter updates for series in the library.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param locale The locale for localization.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @return An XML string representing the library updates feed.
|
||||
*/
|
||||
suspend fun getLibraryUpdatesFeed(
|
||||
baseUrl: String,
|
||||
pageNum: Int,
|
||||
locale: Locale,
|
||||
pageNum: Int,
|
||||
): String {
|
||||
val (updateItems, total) = ChapterRepository.getLibraryUpdates(pageNum)
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"library-updates",
|
||||
MR.strings.opds_feeds_library_updates_title.localized(locale),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "library-updates",
|
||||
title = MR.strings.opds_feeds_library_updates_title.localized(locale),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum = pageNum,
|
||||
)
|
||||
builder.totalResults = total
|
||||
val skipMetadata = serverConfig.opdsSkipChapterMetadataFeed.value
|
||||
builder.entries.addAll(
|
||||
updateItems.map { item ->
|
||||
val mangaDetails = OpdsMangaDetails(item.mangaId, item.mangaTitle, item.mangaThumbnailUrl, item.mangaAuthor)
|
||||
OpdsEntryBuilder.createChapterListEntry(item.chapter, mangaDetails, baseUrl, true, locale)
|
||||
val mangaDetails =
|
||||
OpdsMangaDetails(item.mangaId, item.mangaTitle, item.mangaThumbnailUrl, item.mangaAuthor, item.mangaTotalChapters)
|
||||
OpdsEntryBuilder.createChapterListEntry(
|
||||
baseUrl,
|
||||
locale,
|
||||
item.chapter,
|
||||
mangaDetails,
|
||||
true,
|
||||
skipMetadata,
|
||||
)
|
||||
},
|
||||
)
|
||||
return OpdsXmlUtil.serializeFeedToString(builder.build())
|
||||
@@ -577,29 +600,29 @@ object OpdsFeedBuilder {
|
||||
|
||||
/**
|
||||
* Generates an acquisition feed for all chapters of a specific manga.
|
||||
* @param mangaId The ID of the manga.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param locale The locale for localization.
|
||||
* @param mangaId The ID of the manga.
|
||||
* @param pageNum The page number for pagination.
|
||||
* @param sortParam The sorting parameter for chapters.
|
||||
* @param filterParam The filtering parameter for chapters.
|
||||
* @param locale The locale for localization.
|
||||
* @return An XML string representing the series' chapters feed.
|
||||
*/
|
||||
suspend fun getSeriesChaptersFeed(
|
||||
mangaId: Int,
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
mangaId: Int,
|
||||
pageNum: Int,
|
||||
sortParam: String?,
|
||||
filterParam: String?,
|
||||
locale: Locale,
|
||||
): String {
|
||||
val mangaDetails =
|
||||
MangaRepository.getMangaDetails(mangaId)
|
||||
?: return buildNotFoundFeed(
|
||||
baseUrl,
|
||||
locale,
|
||||
"series/$mangaId/chapters",
|
||||
MR.strings.opds_error_manga_not_found.localized(locale, mangaId),
|
||||
locale,
|
||||
)
|
||||
val (sortColumn, currentSortOrder) =
|
||||
when (sortParam?.lowercase()) {
|
||||
@@ -610,29 +633,41 @@ object OpdsFeedBuilder {
|
||||
else -> ChapterTable.sourceOrder to (serverConfig.opdsChapterSortOrder.value)
|
||||
}
|
||||
val currentFilter = filterParam?.lowercase() ?: if (serverConfig.opdsShowOnlyUnreadChapters.value) "unread" else "all"
|
||||
val skipMetadata = serverConfig.opdsSkipChapterMetadataFeed.value
|
||||
var (chapterEntries, totalChapters) =
|
||||
ChapterRepository.getChaptersForManga(
|
||||
mangaId,
|
||||
pageNum,
|
||||
sortColumn,
|
||||
currentSortOrder,
|
||||
currentFilter,
|
||||
pageNum,
|
||||
skipMetadata,
|
||||
)
|
||||
|
||||
// Return a not-found feed if all available chapters are filtered out as unreachable
|
||||
if (skipMetadata && chapterEntries.isEmpty() && totalChapters > 0L) {
|
||||
return buildNotFoundFeed(
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "series/$mangaId/chapters",
|
||||
title = MR.strings.opds_error_chapters_not_found.localized(locale, pageNum),
|
||||
)
|
||||
}
|
||||
|
||||
// If no chapters are found in the database, attempt to fetch them from the source.
|
||||
if (chapterEntries.isEmpty() && totalChapters == 0L) {
|
||||
try {
|
||||
suwayomi.tachidesk.manga.impl.Chapter
|
||||
.fetchChapterList(mangaId)
|
||||
Manga.updateMangaAndChapters(mangaId, updateManga = false)
|
||||
|
||||
// Re-query after fetching.
|
||||
val (refetchedChapters, refetchedTotal) =
|
||||
ChapterRepository.getChaptersForManga(
|
||||
mangaId,
|
||||
pageNum,
|
||||
sortColumn,
|
||||
currentSortOrder,
|
||||
currentFilter,
|
||||
pageNum,
|
||||
skipMetadata,
|
||||
)
|
||||
chapterEntries = refetchedChapters
|
||||
totalChapters = refetchedTotal
|
||||
@@ -651,12 +686,12 @@ object OpdsFeedBuilder {
|
||||
val feedUrl = "series/$mangaId/chapters"
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
feedUrl,
|
||||
MR.strings.opds_feeds_manga_chapters.localized(locale, mangaDetails.title),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = feedUrl,
|
||||
title = MR.strings.opds_feeds_manga_chapters.localized(locale, mangaDetails.title),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum = pageNum,
|
||||
currentSort = actualSortParamForLinks,
|
||||
currentFilter = currentFilter,
|
||||
)
|
||||
@@ -669,14 +704,21 @@ object OpdsFeedBuilder {
|
||||
OpdsEntryBuilder.addChapterSortAndFilterFacets(
|
||||
builder,
|
||||
"$baseUrl/$feedUrl",
|
||||
locale,
|
||||
actualSortParamForLinks,
|
||||
currentFilter,
|
||||
locale,
|
||||
filterCounts,
|
||||
)
|
||||
builder.entries.addAll(
|
||||
chapterEntries.map { chapter ->
|
||||
OpdsEntryBuilder.createChapterListEntry(chapter, mangaDetails, baseUrl, false, locale)
|
||||
OpdsEntryBuilder.createChapterListEntry(
|
||||
baseUrl,
|
||||
locale,
|
||||
chapter,
|
||||
mangaDetails,
|
||||
false,
|
||||
skipMetadata,
|
||||
)
|
||||
},
|
||||
)
|
||||
return OpdsXmlUtil.serializeFeedToString(builder.build())
|
||||
@@ -684,43 +726,43 @@ object OpdsFeedBuilder {
|
||||
|
||||
/**
|
||||
* Generates an acquisition feed with detailed metadata for a single chapter.
|
||||
* @param mangaId The ID of the manga.
|
||||
* @param chapterSourceOrder The source order index of the chapter.
|
||||
* @param baseUrl The base URL for constructing links.
|
||||
* @param locale The locale for localization.
|
||||
* @param mangaId The ID of the manga.
|
||||
* @param chapterSourceOrder The source order index of the chapter.
|
||||
* @return An XML string representing the chapter's metadata feed.
|
||||
*/
|
||||
suspend fun getChapterMetadataFeed(
|
||||
mangaId: Int,
|
||||
chapterSourceOrder: Int,
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
mangaId: Int,
|
||||
chapterSourceOrder: Int,
|
||||
): String {
|
||||
val mangaDetails =
|
||||
MangaRepository.getMangaDetails(mangaId)
|
||||
?: return buildNotFoundFeed(
|
||||
baseUrl,
|
||||
locale,
|
||||
"series/$mangaId/chapter/$chapterSourceOrder/metadata",
|
||||
MR.strings.opds_error_manga_not_found.localized(locale, mangaId),
|
||||
locale,
|
||||
)
|
||||
val chapterMetadata =
|
||||
ChapterRepository.getChapterDetailsForMetadataFeed(mangaId, chapterSourceOrder)
|
||||
?: return buildNotFoundFeed(
|
||||
baseUrl,
|
||||
locale,
|
||||
"series/$mangaId/chapter/$chapterSourceOrder/metadata",
|
||||
MR.strings.opds_error_chapter_not_found.localized(locale, chapterSourceOrder),
|
||||
locale,
|
||||
)
|
||||
|
||||
val builder =
|
||||
FeedBuilderInternal(
|
||||
baseUrl,
|
||||
"series/$mangaId/chapter/${chapterMetadata.sourceOrder}/metadata",
|
||||
MR.strings.opds_feeds_chapter_details.localized(locale, mangaDetails.title, chapterMetadata.name),
|
||||
locale,
|
||||
OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
null,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = "series/$mangaId/chapter/${chapterMetadata.sourceOrder}/metadata",
|
||||
title = MR.strings.opds_feeds_chapter_details.localized(locale, mangaDetails.title, chapterMetadata.name),
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum = null,
|
||||
)
|
||||
|
||||
mangaDetails.thumbnailUrl?.let { proxyThumbnailUrl(mangaDetails.id) }?.also {
|
||||
@@ -731,10 +773,10 @@ object OpdsFeedBuilder {
|
||||
|
||||
val (primaryEntry, conflictEntry) =
|
||||
OpdsEntryBuilder.createChapterMetadataEntries(
|
||||
chapter = chapterMetadata,
|
||||
manga = mangaDetails,
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
chapter = chapterMetadata,
|
||||
manga = mangaDetails,
|
||||
)
|
||||
|
||||
builder.entries.add(primaryEntry)
|
||||
@@ -751,19 +793,25 @@ object OpdsFeedBuilder {
|
||||
/**
|
||||
* Builds a simple OPDS feed to indicate that a resource was not found.
|
||||
* @param baseUrl The base URL.
|
||||
* @param locale The locale for localization.
|
||||
* @param idPath The path that was not found.
|
||||
* @param title The title for the feed (e.g., an error message).
|
||||
* @param locale The locale for localization.
|
||||
* @return An XML string representing the 'not found' feed.
|
||||
*/
|
||||
fun buildNotFoundFeed(
|
||||
baseUrl: String,
|
||||
locale: Locale,
|
||||
idPath: String,
|
||||
title: String,
|
||||
locale: Locale,
|
||||
): String =
|
||||
FeedBuilderInternal(baseUrl, idPath, title, locale, feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION, pageNum = null)
|
||||
.apply { totalResults = 0L }
|
||||
FeedBuilderInternal(
|
||||
baseUrl = baseUrl,
|
||||
locale = locale,
|
||||
idPath = idPath,
|
||||
title = title,
|
||||
feedType = OpdsConstants.TYPE_ATOM_XML_FEED_ACQUISITION,
|
||||
pageNum = null,
|
||||
).apply { totalResults = 0L }
|
||||
.build()
|
||||
.let(OpdsXmlUtil::serializeFeedToString)
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user