Skip to content

Commit 682c364

Browse files
authored
Address Build Warnings and Cleanup (#707)
* Address build warnings and cleanup * Actual name of who defined the protocol * Remove uneeded detekt supression * GraphQL Before-After cleanup * Lint * Cleanup unused functions * Fix some discrepancies with the 1.5 source api and fix lang exception
1 parent e70730e commit 682c364

31 files changed

+151
-278
lines changed

server/build.gradle.kts

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import de.undercouch.gradle.tasks.download.Download
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
23
import java.time.Instant
34

45
plugins {
@@ -142,6 +143,15 @@ tasks {
142143
}
143144
}
144145

146+
withType<KotlinJvmCompile> {
147+
kotlinOptions {
148+
freeCompilerArgs +=
149+
listOf(
150+
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
151+
)
152+
}
153+
}
154+
145155
named<Copy>("processResources") {
146156
duplicatesStrategy = DuplicatesStrategy.INCLUDE
147157
mustRunAfter("downloadWebUI")

server/src/main/kotlin/eu/kanade/tachiyomi/network/JavaScriptEngine.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import kotlinx.coroutines.withContext
88
/**
99
* Util for evaluating JavaScript in sources.
1010
*/
11-
class JavaScriptEngine(context: Context) {
11+
class JavaScriptEngine(
12+
@Suppress("UNUSED_PARAMETER") context: Context,
13+
) {
1214
/**
1315
* Evaluate arbitrary JavaScript code and get the result as a primitive type
1416
* (e.g., String, Int).

server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CloudflareInterceptor : Interceptor {
2525

2626
private val network: NetworkHelper by injectLazy()
2727

28+
@Suppress("UNUSED_VARIABLE", "UNREACHABLE_CODE")
2829
override fun intercept(chain: Interceptor.Chain): Response {
2930
val originalRequest = chain.request()
3031

@@ -141,6 +142,7 @@ object CFClearance {
141142
.build()
142143
}
143144

145+
@Suppress("UNREACHABLE_CODE")
144146
fun getWebViewUserAgent(): String {
145147
return try {
146148
throw PlaywrightException("playwrite is diabled for v0.6.7")

server/src/main/kotlin/eu/kanade/tachiyomi/source/CatalogueSource.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface CatalogueSource : Source {
99
/**
1010
* An ISO 639-1 compliant language code (two letters in lower case).
1111
*/
12-
val lang: String
12+
override val lang: String
1313

1414
/**
1515
* Whether the source has support for latest updates.

server/src/main/kotlin/eu/kanade/tachiyomi/source/ConfigurableSource.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ interface ConfigurableSource : Source {
1818
fun setupPreferenceScreen(screen: PreferenceScreen)
1919
}
2020

21-
private fun ConfigurableSource.preferenceKey(): String = "source_$id"
21+
fun ConfigurableSource.preferenceKey(): String = "source_$id"
2222

2323
// TODO: use getSourcePreferences once all extensions are on ext-lib 1.5
2424
fun ConfigurableSource.sourcePreferences(): SharedPreferences =
2525
Injekt.get<Application>().getSharedPreferences(preferenceKey(), Context.MODE_PRIVATE)
26+
27+
fun sourcePreferences(key: String): SharedPreferences = Injekt.get<Application>().getSharedPreferences(key, Context.MODE_PRIVATE)

server/src/main/kotlin/eu/kanade/tachiyomi/source/Source.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import rx.Observable
77
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
88

99
/**
10-
* A basic interface for creating a source. It could be an online source, a local source, etc...
10+
* A basic interface for creating a source. It could be an online source, a local source, etc.
1111
*/
1212
interface Source {
1313
/**
14-
* Id for the source. Must be unique.
14+
* ID for the source. Must be unique.
1515
*/
1616
val id: Long
1717

@@ -20,6 +20,9 @@ interface Source {
2020
*/
2121
val name: String
2222

23+
val lang: String
24+
get() = ""
25+
2326
/**
2427
* Get the updated details for a manga.
2528
*
@@ -73,9 +76,7 @@ interface Source {
7376
"Use the non-RxJava API instead",
7477
ReplaceWith("getPageList"),
7578
)
76-
fun fetchPageList(chapter: SChapter): Observable<List<Page>> = Observable.empty()
79+
fun fetchPageList(chapter: SChapter): Observable<List<Page>> = throw IllegalStateException("Not used")
7780
}
7881

7982
// fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this)
80-
81-
fun Source.getPreferenceKey(): String = "source_$id"

server/src/main/kotlin/eu/kanade/tachiyomi/source/local/LocalSource.kt

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import kotlinx.coroutines.withContext
3232
import kotlinx.serialization.json.Json
3333
import kotlinx.serialization.json.decodeFromStream
3434
import mu.KotlinLogging
35+
import nl.adaptivity.xmlutil.ExperimentalXmlUtilApi
3536
import nl.adaptivity.xmlutil.core.KtXmlReader
3637
import nl.adaptivity.xmlutil.serialization.XML
3738
import org.apache.commons.compress.archivers.zip.ZipFile
@@ -271,6 +272,7 @@ class LocalSource(
271272
}
272273
}
273274

275+
@OptIn(ExperimentalXmlUtilApi::class)
274276
private fun setMangaDetailsFromComicInfoFile(
275277
stream: InputStream,
276278
manga: SManga,

server/src/main/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt

+19-13
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,12 @@ import java.security.MessageDigest
2626
/**
2727
* A simple implementation for sources from a website.
2828
*/
29+
@Suppress("unused")
2930
abstract class HttpSource : CatalogueSource {
3031
/**
3132
* Network service.
3233
*/
33-
val network: NetworkHelper by injectLazy()
34-
35-
// /**
36-
// * Preferences that a source may need.
37-
// */
38-
// val preferences: SharedPreferences by lazy {
39-
// Injekt.get<Application>().getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE)
40-
// }
34+
protected val network: NetworkHelper by injectLazy()
4135

4236
/**
4337
* Base url of the website without the trailing slash, like: http://mysite.com
@@ -60,7 +54,7 @@ abstract class HttpSource : CatalogueSource {
6054
*
6155
* Note: the generated ID sets the sign bit to `0`.
6256
*/
63-
override val id by lazy { generateId(name, lang, versionId) }
57+
override val id by lazy { generateId() }
6458

6559
/**
6660
* Headers used for requests.
@@ -73,6 +67,10 @@ abstract class HttpSource : CatalogueSource {
7367
open val client: OkHttpClient
7468
get() = network.client
7569

70+
private fun generateId(): Long {
71+
return generateId(name, lang, versionId)
72+
}
73+
7674
/**
7775
* Generates a unique ID for the source based on the provided [name], [lang] and
7876
* [versionId]. It will use the first 16 characters (64 bits) of the MD5 of the string
@@ -89,6 +87,7 @@ abstract class HttpSource : CatalogueSource {
8987
* @param versionId [Int] the version ID of the source
9088
* @return a unique ID for the source
9189
*/
90+
@Suppress("MemberVisibilityCanBePrivate")
9291
protected fun generateId(
9392
name: String,
9493
lang: String,
@@ -155,8 +154,15 @@ abstract class HttpSource : CatalogueSource {
155154
query: String,
156155
filters: FilterList,
157156
): Observable<MangasPage> {
158-
return client.newCall(searchMangaRequest(page, query, filters))
159-
.asObservableSuccess()
157+
return Observable.defer {
158+
try {
159+
client.newCall(searchMangaRequest(page, query, filters)).asObservableSuccess()
160+
} catch (e: NoClassDefFoundError) {
161+
// RxJava doesn't handle Errors, which tends to happen during global searches
162+
// if an old extension using non-existent classes is still around
163+
throw RuntimeException(e)
164+
}
165+
}
160166
.map { response ->
161167
searchMangaParse(response)
162168
}
@@ -387,7 +393,7 @@ abstract class HttpSource : CatalogueSource {
387393
*
388394
* @param page the chapter whose page list has to be fetched
389395
*/
390-
open fun imageRequest(page: Page): Request {
396+
protected open fun imageRequest(page: Page): Request {
391397
return GET(page.imageUrl!!, headers)
392398
}
393399

@@ -418,7 +424,7 @@ abstract class HttpSource : CatalogueSource {
418424
*/
419425
private fun getUrlWithoutDomain(orig: String): String {
420426
return try {
421-
val uri = URI(orig)
427+
val uri = URI(orig.replace(" ", "%20"))
422428
var out = uri.path
423429
if (uri.query != null) {
424430
out += "?" + uri.query

server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/CategoryQuery.kt

+7-22
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ import graphql.schema.DataFetchingEnvironment
1212
import org.jetbrains.exposed.sql.Column
1313
import org.jetbrains.exposed.sql.Op
1414
import org.jetbrains.exposed.sql.SortOrder
15-
import org.jetbrains.exposed.sql.SortOrder.ASC
16-
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
17-
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
18-
import org.jetbrains.exposed.sql.SortOrder.DESC
19-
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
20-
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
2115
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
2216
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
23-
import org.jetbrains.exposed.sql.andWhere
2417
import org.jetbrains.exposed.sql.selectAll
2518
import org.jetbrains.exposed.sql.transactions.transaction
2619
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
@@ -37,6 +30,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
3730
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
3831
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
3932
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
33+
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
4034
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
4135
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
4236
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
@@ -157,21 +151,12 @@ class CategoryQuery {
157151
val firstResult = res.firstOrNull()?.get(CategoryTable.id)?.value
158152
val lastResult = res.lastOrNull()?.get(CategoryTable.id)?.value
159153

160-
if (after != null) {
161-
res.andWhere {
162-
when (orderByType) {
163-
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).less(after)
164-
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).greater(after)
165-
}
166-
}
167-
} else if (before != null) {
168-
res.andWhere {
169-
when (orderByType) {
170-
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).greater(before)
171-
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).less(before)
172-
}
173-
}
174-
}
154+
res.applyBeforeAfter(
155+
before = before,
156+
after = after,
157+
orderBy = orderBy ?: CategoryOrderBy.ID,
158+
orderByType = orderByType,
159+
)
175160

176161
if (first != null) {
177162
res.limit(first, offset?.toLong() ?: 0)

server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ChapterQuery.kt

+7-22
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,11 @@ import graphql.schema.DataFetchingEnvironment
1212
import org.jetbrains.exposed.sql.Column
1313
import org.jetbrains.exposed.sql.Op
1414
import org.jetbrains.exposed.sql.SortOrder
15-
import org.jetbrains.exposed.sql.SortOrder.ASC
16-
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
17-
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
18-
import org.jetbrains.exposed.sql.SortOrder.DESC
19-
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
20-
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
2115
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
2216
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
2317
import org.jetbrains.exposed.sql.andWhere
2418
import org.jetbrains.exposed.sql.selectAll
2519
import org.jetbrains.exposed.sql.transactions.transaction
26-
import suwayomi.tachidesk.graphql.queries.ChapterQuery.ChapterOrderBy.ID
2720
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
2821
import suwayomi.tachidesk.graphql.queries.filter.Filter
2922
import suwayomi.tachidesk.graphql.queries.filter.FloatFilter
@@ -40,6 +33,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
4033
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
4134
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
4235
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
36+
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
4337
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
4438
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
4539
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
@@ -241,21 +235,12 @@ class ChapterQuery {
241235
val firstResult = res.firstOrNull()?.get(ChapterTable.id)?.value
242236
val lastResult = res.lastOrNull()?.get(ChapterTable.id)?.value
243237

244-
if (after != null) {
245-
res.andWhere {
246-
when (orderByType) {
247-
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ID).less(after)
248-
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ID).greater(after)
249-
}
250-
}
251-
} else if (before != null) {
252-
res.andWhere {
253-
when (orderByType) {
254-
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ID).greater(before)
255-
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ID).less(before)
256-
}
257-
}
258-
}
238+
res.applyBeforeAfter(
239+
before = before,
240+
after = after,
241+
orderBy = orderBy ?: ChapterOrderBy.ID,
242+
orderByType = orderByType,
243+
)
259244

260245
if (first != null) {
261246
res.limit(first, offset?.toLong() ?: 0)

server/src/main/kotlin/suwayomi/tachidesk/graphql/queries/ExtensionQuery.kt

+7-22
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@ import graphql.schema.DataFetchingEnvironment
1313
import org.jetbrains.exposed.sql.Column
1414
import org.jetbrains.exposed.sql.Op
1515
import org.jetbrains.exposed.sql.SortOrder
16-
import org.jetbrains.exposed.sql.SortOrder.ASC
17-
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_FIRST
18-
import org.jetbrains.exposed.sql.SortOrder.ASC_NULLS_LAST
19-
import org.jetbrains.exposed.sql.SortOrder.DESC
20-
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_FIRST
21-
import org.jetbrains.exposed.sql.SortOrder.DESC_NULLS_LAST
2216
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater
2317
import org.jetbrains.exposed.sql.SqlExpressionBuilder.less
2418
import org.jetbrains.exposed.sql.SqlExpressionBuilder.neq
25-
import org.jetbrains.exposed.sql.andWhere
2619
import org.jetbrains.exposed.sql.selectAll
2720
import org.jetbrains.exposed.sql.transactions.transaction
2821
import suwayomi.tachidesk.graphql.queries.filter.BooleanFilter
@@ -38,6 +31,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Cursor
3831
import suwayomi.tachidesk.graphql.server.primitives.OrderBy
3932
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
4033
import suwayomi.tachidesk.graphql.server.primitives.QueryResults
34+
import suwayomi.tachidesk.graphql.server.primitives.applyBeforeAfter
4135
import suwayomi.tachidesk.graphql.server.primitives.greaterNotUnique
4236
import suwayomi.tachidesk.graphql.server.primitives.lessNotUnique
4337
import suwayomi.tachidesk.graphql.server.primitives.maybeSwap
@@ -187,21 +181,12 @@ class ExtensionQuery {
187181
val firstResult = res.firstOrNull()?.get(ExtensionTable.pkgName)
188182
val lastResult = res.lastOrNull()?.get(ExtensionTable.pkgName)
189183

190-
if (after != null) {
191-
res.andWhere {
192-
when (orderByType) {
193-
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).less(after)
194-
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).greater(after)
195-
}
196-
}
197-
} else if (before != null) {
198-
res.andWhere {
199-
when (orderByType) {
200-
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).greater(before)
201-
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).less(before)
202-
}
203-
}
204-
}
184+
res.applyBeforeAfter(
185+
before = before,
186+
after = after,
187+
orderBy = orderBy ?: ExtensionOrderBy.PKG_NAME,
188+
orderByType = orderByType,
189+
)
205190

206191
if (first != null) {
207192
res.limit(first, offset?.toLong() ?: 0)

0 commit comments

Comments
 (0)