Switch to a new Ktlint Formatter (#705)

* Switch to new Ktlint plugin

* Add ktlintCheck to PR builds

* Run formatter

* Put ktlint version in libs toml

* Fix lint

* Use Zip4Java from libs.toml
This commit is contained in:
Mitchell Syer
2023-10-06 23:38:39 -04:00
committed by GitHub
parent 3cd3cb0186
commit 849acfca3d
277 changed files with 6709 additions and 5090 deletions

View File

@@ -23,7 +23,7 @@ object GraphQLController {
ctx.future(
future {
server.execute(ctx)
}
},
)
}

View File

@@ -23,48 +23,56 @@ import suwayomi.tachidesk.server.JavalinSetup.future
class CategoryDataLoader : KotlinDataLoader<Int, CategoryType> {
override val dataLoaderName = "CategoryDataLoader"
override fun getDataLoader(): DataLoader<Int, CategoryType> = DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val categories = CategoryTable.select { CategoryTable.id inList ids }
.map { CategoryType(it) }
.associateBy { it.id }
ids.map { categories[it] }
override fun getDataLoader(): DataLoader<Int, CategoryType> =
DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val categories =
CategoryTable.select { CategoryTable.id inList ids }
.map { CategoryType(it) }
.associateBy { it.id }
ids.map { categories[it] }
}
}
}
}
}
class CategoryForIdsDataLoader : KotlinDataLoader<List<Int>, CategoryNodeList> {
override val dataLoaderName = "CategoryForIdsDataLoader"
override fun getDataLoader(): DataLoader<List<Int>, CategoryNodeList> = DataLoaderFactory.newDataLoader { categoryIds ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val ids = categoryIds.flatten().distinct()
val categories = CategoryTable.select { CategoryTable.id inList ids }.map { CategoryType(it) }
categoryIds.map { categoryIds ->
categories.filter { it.id in categoryIds }.toNodeList()
override fun getDataLoader(): DataLoader<List<Int>, CategoryNodeList> =
DataLoaderFactory.newDataLoader { categoryIds ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val ids = categoryIds.flatten().distinct()
val categories = CategoryTable.select { CategoryTable.id inList ids }.map { CategoryType(it) }
categoryIds.map { categoryIds ->
categories.filter { it.id in categoryIds }.toNodeList()
}
}
}
}
}
}
class CategoriesForMangaDataLoader : KotlinDataLoader<Int, CategoryNodeList> {
override val dataLoaderName = "CategoriesForMangaDataLoader"
override fun getDataLoader(): DataLoader<Int, CategoryNodeList> = DataLoaderFactory.newDataLoader<Int, CategoryNodeList> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val itemsByRef = CategoryMangaTable.innerJoin(CategoryTable)
.select { CategoryMangaTable.manga inList ids }
.map { Pair(it[CategoryMangaTable.manga].value, CategoryType(it)) }
.groupBy { it.first }
.mapValues { it.value.map { pair -> pair.second } }
ids.map { (itemsByRef[it] ?: emptyList()).toNodeList() }
override fun getDataLoader(): DataLoader<Int, CategoryNodeList> =
DataLoaderFactory.newDataLoader<Int, CategoryNodeList> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val itemsByRef =
CategoryMangaTable.innerJoin(CategoryTable)
.select { CategoryMangaTable.manga inList ids }
.map { Pair(it[CategoryMangaTable.manga].value, CategoryType(it)) }
.groupBy { it.first }
.mapValues { it.value.map { pair -> pair.second } }
ids.map { (itemsByRef[it] ?: emptyList()).toNodeList() }
}
}
}
}
}

View File

@@ -25,82 +25,95 @@ import suwayomi.tachidesk.server.JavalinSetup.future
class ChapterDataLoader : KotlinDataLoader<Int, ChapterType?> {
override val dataLoaderName = "ChapterDataLoader"
override fun getDataLoader(): DataLoader<Int, ChapterType?> = DataLoaderFactory.newDataLoader<Int, ChapterType> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val chapters = ChapterTable.select { ChapterTable.id inList ids }
.map { ChapterType(it) }
.associateBy { it.id }
ids.map { chapters[it] }
override fun getDataLoader(): DataLoader<Int, ChapterType?> =
DataLoaderFactory.newDataLoader<Int, ChapterType> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val chapters =
ChapterTable.select { ChapterTable.id inList ids }
.map { ChapterType(it) }
.associateBy { it.id }
ids.map { chapters[it] }
}
}
}
}
}
class ChaptersForMangaDataLoader : KotlinDataLoader<Int, ChapterNodeList> {
override val dataLoaderName = "ChaptersForMangaDataLoader"
override fun getDataLoader(): DataLoader<Int, ChapterNodeList> = DataLoaderFactory.newDataLoader<Int, ChapterNodeList> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val chaptersByMangaId = ChapterTable.select { ChapterTable.manga inList ids }
.map { ChapterType(it) }
.groupBy { it.mangaId }
ids.map { (chaptersByMangaId[it] ?: emptyList()).toNodeList() }
override fun getDataLoader(): DataLoader<Int, ChapterNodeList> =
DataLoaderFactory.newDataLoader<Int, ChapterNodeList> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val chaptersByMangaId =
ChapterTable.select { ChapterTable.manga inList ids }
.map { ChapterType(it) }
.groupBy { it.mangaId }
ids.map { (chaptersByMangaId[it] ?: emptyList()).toNodeList() }
}
}
}
}
}
class DownloadedChapterCountForMangaDataLoader : KotlinDataLoader<Int, Int> {
override val dataLoaderName = "DownloadedChapterCountForMangaDataLoader"
override fun getDataLoader(): DataLoader<Int, Int> = DataLoaderFactory.newDataLoader<Int, Int> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val downloadedChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isDownloaded.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isDownloaded eq true) }
.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isDownloaded.count()] }
ids.map { downloadedChapterCountByMangaId[it]?.toInt() ?: 0 }
override fun getDataLoader(): DataLoader<Int, Int> =
DataLoaderFactory.newDataLoader<Int, Int> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val downloadedChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isDownloaded.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isDownloaded eq true) }
.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isDownloaded.count()] }
ids.map { downloadedChapterCountByMangaId[it]?.toInt() ?: 0 }
}
}
}
}
}
class UnreadChapterCountForMangaDataLoader : KotlinDataLoader<Int, Int> {
override val dataLoaderName = "UnreadChapterCountForMangaDataLoader"
override fun getDataLoader(): DataLoader<Int, Int> = DataLoaderFactory.newDataLoader<Int, Int> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val unreadChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isRead.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq false) }
.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isRead.count()] }
ids.map { unreadChapterCountByMangaId[it]?.toInt() ?: 0 }
override fun getDataLoader(): DataLoader<Int, Int> =
DataLoaderFactory.newDataLoader<Int, Int> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val unreadChapterCountByMangaId =
ChapterTable
.slice(ChapterTable.manga, ChapterTable.isRead.count())
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq false) }
.groupBy(ChapterTable.manga)
.associate { it[ChapterTable.manga].value to it[ChapterTable.isRead.count()] }
ids.map { unreadChapterCountByMangaId[it]?.toInt() ?: 0 }
}
}
}
}
}
class LastReadChapterForMangaDataLoader : KotlinDataLoader<Int, ChapterType?> {
override val dataLoaderName = "LastReadChapterForMangaDataLoader"
override fun getDataLoader(): DataLoader<Int, ChapterType?> = DataLoaderFactory.newDataLoader<Int, ChapterType?> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val lastReadChaptersByMangaId = ChapterTable
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq true) }
.orderBy(ChapterTable.sourceOrder to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> lastReadChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
override fun getDataLoader(): DataLoader<Int, ChapterType?> =
DataLoaderFactory.newDataLoader<Int, ChapterType?> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val lastReadChaptersByMangaId =
ChapterTable
.select { (ChapterTable.manga inList ids) and (ChapterTable.isRead eq true) }
.orderBy(ChapterTable.sourceOrder to SortOrder.DESC)
.groupBy { it[ChapterTable.manga].value }
ids.map { id -> lastReadChaptersByMangaId[id]?.let { chapters -> ChapterType(chapters.first()) } }
}
}
}
}
}

View File

@@ -21,43 +21,50 @@ import suwayomi.tachidesk.server.JavalinSetup.future
class ExtensionDataLoader : KotlinDataLoader<String, ExtensionType?> {
override val dataLoaderName = "ExtensionDataLoader"
override fun getDataLoader(): DataLoader<String, ExtensionType?> = DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val extensions = ExtensionTable.select { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
.associateBy { it.pkgName }
ids.map { extensions[it] }
override fun getDataLoader(): DataLoader<String, ExtensionType?> =
DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val extensions =
ExtensionTable.select { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
.associateBy { it.pkgName }
ids.map { extensions[it] }
}
}
}
}
}
class ExtensionForSourceDataLoader : KotlinDataLoader<Long, ExtensionType?> {
override val dataLoaderName = "ExtensionForSourceDataLoader"
override fun getDataLoader(): DataLoader<Long, ExtensionType?> = DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val extensions = ExtensionTable.innerJoin(SourceTable)
.select { SourceTable.id inList ids }
.toList()
.map { Triple(it[SourceTable.id].value, it[ExtensionTable.pkgName], it) }
.let { triples ->
val sources = buildMap {
triples.forEach {
if (!containsKey(it.second)) {
put(it.second, ExtensionType(it.third))
override fun getDataLoader(): DataLoader<Long, ExtensionType?> =
DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val extensions =
ExtensionTable.innerJoin(SourceTable)
.select { SourceTable.id inList ids }
.toList()
.map { Triple(it[SourceTable.id].value, it[ExtensionTable.pkgName], it) }
.let { triples ->
val sources =
buildMap {
triples.forEach {
if (!containsKey(it.second)) {
put(it.second, ExtensionType(it.third))
}
}
}
triples.associate {
it.first to sources[it.second]
}
}
}
triples.associate {
it.first to sources[it.second]
}
}
ids.map { extensions[it] }
ids.map { extensions[it] }
}
}
}
}
}

View File

@@ -24,76 +24,89 @@ import suwayomi.tachidesk.server.JavalinSetup.future
class MangaDataLoader : KotlinDataLoader<Int, MangaType?> {
override val dataLoaderName = "MangaDataLoader"
override fun getDataLoader(): DataLoader<Int, MangaType?> = DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val manga = MangaTable.select { MangaTable.id inList ids }
.map { MangaType(it) }
.associateBy { it.id }
ids.map { manga[it] }
override fun getDataLoader(): DataLoader<Int, MangaType?> =
DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val manga =
MangaTable.select { MangaTable.id inList ids }
.map { MangaType(it) }
.associateBy { it.id }
ids.map { manga[it] }
}
}
}
}
}
class MangaForCategoryDataLoader : KotlinDataLoader<Int, MangaNodeList> {
override val dataLoaderName = "MangaForCategoryDataLoader"
override fun getDataLoader(): DataLoader<Int, MangaNodeList> = DataLoaderFactory.newDataLoader<Int, MangaNodeList> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val itemsByRef = if (ids.contains(0)) {
MangaTable
.leftJoin(CategoryMangaTable)
.select { MangaTable.inLibrary eq true }
.andWhere { CategoryMangaTable.manga.isNull() }
.map { MangaType(it) }
.let {
mapOf(0 to it)
}
} else {
emptyMap()
} + CategoryMangaTable.innerJoin(MangaTable)
.select { CategoryMangaTable.category inList ids }
.map { Pair(it[CategoryMangaTable.category].value, MangaType(it)) }
.groupBy { it.first }
.mapValues { it.value.map { pair -> pair.second } }
ids.map { (itemsByRef[it] ?: emptyList()).toNodeList() }
override fun getDataLoader(): DataLoader<Int, MangaNodeList> =
DataLoaderFactory.newDataLoader<Int, MangaNodeList> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val itemsByRef =
if (ids.contains(0)) {
MangaTable
.leftJoin(CategoryMangaTable)
.select { MangaTable.inLibrary eq true }
.andWhere { CategoryMangaTable.manga.isNull() }
.map { MangaType(it) }
.let {
mapOf(0 to it)
}
} else {
emptyMap()
} +
CategoryMangaTable.innerJoin(MangaTable)
.select { CategoryMangaTable.category inList ids }
.map { Pair(it[CategoryMangaTable.category].value, MangaType(it)) }
.groupBy { it.first }
.mapValues { it.value.map { pair -> pair.second } }
ids.map { (itemsByRef[it] ?: emptyList()).toNodeList() }
}
}
}
}
}
class MangaForSourceDataLoader : KotlinDataLoader<Long, MangaNodeList> {
override val dataLoaderName = "MangaForSourceDataLoader"
override fun getDataLoader(): DataLoader<Long, MangaNodeList> = DataLoaderFactory.newDataLoader<Long, MangaNodeList> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val mangaBySourceId = MangaTable.select { MangaTable.sourceReference inList ids }
.map { MangaType(it) }
.groupBy { it.sourceId }
ids.map { (mangaBySourceId[it] ?: emptyList()).toNodeList() }
override fun getDataLoader(): DataLoader<Long, MangaNodeList> =
DataLoaderFactory.newDataLoader<Long, MangaNodeList> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val mangaBySourceId =
MangaTable.select { MangaTable.sourceReference inList ids }
.map { MangaType(it) }
.groupBy { it.sourceId }
ids.map { (mangaBySourceId[it] ?: emptyList()).toNodeList() }
}
}
}
}
}
class MangaForIdsDataLoader : KotlinDataLoader<List<Int>, MangaNodeList> {
override val dataLoaderName = "MangaForIdsDataLoader"
override fun getDataLoader(): DataLoader<List<Int>, MangaNodeList> = DataLoaderFactory.newDataLoader { mangaIds ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val ids = mangaIds.flatten().distinct()
val manga = MangaTable.select { MangaTable.id inList ids }
.map { MangaType(it) }
mangaIds.map { mangaIds ->
manga.filter { it.id in mangaIds }.toNodeList()
override fun getDataLoader(): DataLoader<List<Int>, MangaNodeList> =
DataLoaderFactory.newDataLoader { mangaIds ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val ids = mangaIds.flatten().distinct()
val manga =
MangaTable.select { MangaTable.id inList ids }
.map { MangaType(it) }
mangaIds.map { mangaIds ->
manga.filter { it.id in mangaIds }.toNodeList()
}
}
}
}
}
}

View File

@@ -19,60 +19,72 @@ import suwayomi.tachidesk.server.JavalinSetup.future
class GlobalMetaDataLoader : KotlinDataLoader<String, GlobalMetaType?> {
override val dataLoaderName = "GlobalMetaDataLoader"
override fun getDataLoader(): DataLoader<String, GlobalMetaType?> = DataLoaderFactory.newDataLoader<String, GlobalMetaType?> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId = GlobalMetaTable.select { GlobalMetaTable.key inList ids }
.map { GlobalMetaType(it) }
.associateBy { it.key }
ids.map { metasByRefId[it] }
override fun getDataLoader(): DataLoader<String, GlobalMetaType?> =
DataLoaderFactory.newDataLoader<String, GlobalMetaType?> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
GlobalMetaTable.select { GlobalMetaTable.key inList ids }
.map { GlobalMetaType(it) }
.associateBy { it.key }
ids.map { metasByRefId[it] }
}
}
}
}
}
class ChapterMetaDataLoader : KotlinDataLoader<Int, List<ChapterMetaType>> {
override val dataLoaderName = "ChapterMetaDataLoader"
override fun getDataLoader(): DataLoader<Int, List<ChapterMetaType>> = DataLoaderFactory.newDataLoader<Int, List<ChapterMetaType>> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId = ChapterMetaTable.select { ChapterMetaTable.ref inList ids }
.map { ChapterMetaType(it) }
.groupBy { it.chapterId }
ids.map { metasByRefId[it].orEmpty() }
override fun getDataLoader(): DataLoader<Int, List<ChapterMetaType>> =
DataLoaderFactory.newDataLoader<Int, List<ChapterMetaType>> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
ChapterMetaTable.select { ChapterMetaTable.ref inList ids }
.map { ChapterMetaType(it) }
.groupBy { it.chapterId }
ids.map { metasByRefId[it].orEmpty() }
}
}
}
}
}
class MangaMetaDataLoader : KotlinDataLoader<Int, List<MangaMetaType>> {
override val dataLoaderName = "MangaMetaDataLoader"
override fun getDataLoader(): DataLoader<Int, List<MangaMetaType>> = DataLoaderFactory.newDataLoader<Int, List<MangaMetaType>> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId = MangaMetaTable.select { MangaMetaTable.ref inList ids }
.map { MangaMetaType(it) }
.groupBy { it.mangaId }
ids.map { metasByRefId[it].orEmpty() }
override fun getDataLoader(): DataLoader<Int, List<MangaMetaType>> =
DataLoaderFactory.newDataLoader<Int, List<MangaMetaType>> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
MangaMetaTable.select { MangaMetaTable.ref inList ids }
.map { MangaMetaType(it) }
.groupBy { it.mangaId }
ids.map { metasByRefId[it].orEmpty() }
}
}
}
}
}
class CategoryMetaDataLoader : KotlinDataLoader<Int, List<CategoryMetaType>> {
override val dataLoaderName = "CategoryMetaDataLoader"
override fun getDataLoader(): DataLoader<Int, List<CategoryMetaType>> = DataLoaderFactory.newDataLoader<Int, List<CategoryMetaType>> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId = CategoryMetaTable.select { CategoryMetaTable.ref inList ids }
.map { CategoryMetaType(it) }
.groupBy { it.categoryId }
ids.map { metasByRefId[it].orEmpty() }
override fun getDataLoader(): DataLoader<Int, List<CategoryMetaType>> =
DataLoaderFactory.newDataLoader<Int, List<CategoryMetaType>> { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val metasByRefId =
CategoryMetaTable.select { CategoryMetaTable.ref inList ids }
.map { CategoryMetaType(it) }
.groupBy { it.categoryId }
ids.map { metasByRefId[it].orEmpty() }
}
}
}
}
}

View File

@@ -23,34 +23,40 @@ import suwayomi.tachidesk.server.JavalinSetup.future
class SourceDataLoader : KotlinDataLoader<Long, SourceType?> {
override val dataLoaderName = "SourceDataLoader"
override fun getDataLoader(): DataLoader<Long, SourceType?> = DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val source = SourceTable.select { SourceTable.id inList ids }
.mapNotNull { SourceType(it) }
.associateBy { it.id }
ids.map { source[it] }
override fun getDataLoader(): DataLoader<Long, SourceType?> =
DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val source =
SourceTable.select { SourceTable.id inList ids }
.mapNotNull { SourceType(it) }
.associateBy { it.id }
ids.map { source[it] }
}
}
}
}
}
class SourcesForExtensionDataLoader : KotlinDataLoader<String, SourceNodeList> {
override val dataLoaderName = "SourcesForExtensionDataLoader"
override fun getDataLoader(): DataLoader<String, SourceNodeList> = DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
val sourcesByExtensionPkg = SourceTable.innerJoin(ExtensionTable)
.select { ExtensionTable.pkgName inList ids }
.map { Pair(it[ExtensionTable.pkgName], SourceType(it)) }
.groupBy { it.first }
.mapValues { it.value.mapNotNull { pair -> pair.second } }
override fun getDataLoader(): DataLoader<String, SourceNodeList> =
DataLoaderFactory.newDataLoader { ids ->
future {
transaction {
addLogger(Slf4jSqlDebugLogger)
ids.map { (sourcesByExtensionPkg[it] ?: emptyList()).toNodeList() }
val sourcesByExtensionPkg =
SourceTable.innerJoin(ExtensionTable)
.select { ExtensionTable.pkgName inList ids }
.map { Pair(it[ExtensionTable.pkgName], SourceType(it)) }
.groupBy { it.first }
.mapValues { it.value.mapNotNull { pair -> pair.second } }
ids.map { (sourcesByExtensionPkg[it] ?: emptyList()).toNodeList() }
}
}
}
}
}

View File

@@ -20,17 +20,16 @@ import kotlin.time.Duration.Companion.seconds
class BackupMutation {
data class RestoreBackupInput(
val clientMutationId: String? = null,
val backup: UploadedFile
val backup: UploadedFile,
)
data class RestoreBackupPayload(
val clientMutationId: String?,
val status: BackupRestoreStatus
val status: BackupRestoreStatus,
)
@OptIn(DelicateCoroutinesApi::class)
fun restoreBackup(
input: RestoreBackupInput
): CompletableFuture<RestoreBackupPayload> {
fun restoreBackup(input: RestoreBackupInput): CompletableFuture<RestoreBackupPayload> {
val (clientMutationId, backup) = input
return future {
@@ -38,11 +37,12 @@ class BackupMutation {
ProtoBackupImport.performRestore(backup.content)
}
val status = withTimeout(10.seconds) {
ProtoBackupImport.backupRestoreState.first {
it != ProtoBackupImport.BackupRestoreState.Idle
}.toStatus()
}
val status =
withTimeout(10.seconds) {
ProtoBackupImport.backupRestoreState.first {
it != ProtoBackupImport.BackupRestoreState.Idle
}.toStatus()
}
RestoreBackupPayload(clientMutationId, status)
}
@@ -51,32 +51,33 @@ class BackupMutation {
data class CreateBackupInput(
val clientMutationId: String? = null,
val includeChapters: Boolean? = null,
val includeCategories: Boolean? = null
val includeCategories: Boolean? = null,
)
data class CreateBackupPayload(
val clientMutationId: String?,
val url: String
val url: String,
)
fun createBackup(
input: CreateBackupInput? = null
): CreateBackupPayload {
fun createBackup(input: CreateBackupInput? = null): CreateBackupPayload {
val filename = ProtoBackupExport.getBackupFilename()
val backup = ProtoBackupExport.createBackup(
BackupFlags(
includeManga = true,
includeCategories = input?.includeCategories ?: true,
includeChapters = input?.includeChapters ?: true,
includeTracking = true,
includeHistory = true
val backup =
ProtoBackupExport.createBackup(
BackupFlags(
includeManga = true,
includeCategories = input?.includeCategories ?: true,
includeChapters = input?.includeChapters ?: true,
includeTracking = true,
includeHistory = true,
),
)
)
TemporaryFileStorage.saveFile(filename, backup)
return CreateBackupPayload(
clientMutationId = input?.clientMutationId,
url = "/api/graphql/files/backup/$filename"
url = "/api/graphql/files/backup/$filename",
)
}
}

View File

@@ -27,15 +27,15 @@ import suwayomi.tachidesk.manga.model.table.MangaTable
class CategoryMutation {
data class SetCategoryMetaInput(
val clientMutationId: String? = null,
val meta: CategoryMetaType
val meta: CategoryMetaType,
)
data class SetCategoryMetaPayload(
val clientMutationId: String?,
val meta: CategoryMetaType
val meta: CategoryMetaType,
)
fun setCategoryMeta(
input: SetCategoryMetaInput
): SetCategoryMetaPayload {
fun setCategoryMeta(input: SetCategoryMetaInput): SetCategoryMetaPayload {
val (clientMutationId, meta) = input
Category.modifyMeta(meta.categoryId, meta.key, meta.value)
@@ -46,65 +46,73 @@ class CategoryMutation {
data class DeleteCategoryMetaInput(
val clientMutationId: String? = null,
val categoryId: Int,
val key: String
val key: String,
)
data class DeleteCategoryMetaPayload(
val clientMutationId: String?,
val meta: CategoryMetaType?,
val category: CategoryType
val category: CategoryType,
)
fun deleteCategoryMeta(
input: DeleteCategoryMetaInput
): DeleteCategoryMetaPayload {
fun deleteCategoryMeta(input: DeleteCategoryMetaInput): DeleteCategoryMetaPayload {
val (clientMutationId, categoryId, key) = input
val (meta, category) = transaction {
val meta = CategoryMetaTable.select { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
.firstOrNull()
val (meta, category) =
transaction {
val meta =
CategoryMetaTable.select { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
.firstOrNull()
CategoryMetaTable.deleteWhere { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
CategoryMetaTable.deleteWhere { (CategoryMetaTable.ref eq categoryId) and (CategoryMetaTable.key eq key) }
val category = transaction {
CategoryType(CategoryTable.select { CategoryTable.id eq categoryId }.first())
val category =
transaction {
CategoryType(CategoryTable.select { CategoryTable.id eq categoryId }.first())
}
if (meta != null) {
CategoryMetaType(meta)
} else {
null
} to category
}
if (meta != null) {
CategoryMetaType(meta)
} else {
null
} to category
}
return DeleteCategoryMetaPayload(clientMutationId, meta, category)
}
data class UpdateCategoryPatch(
val name: String? = null,
val default: Boolean? = null,
val includeInUpdate: IncludeInUpdate? = null
val includeInUpdate: IncludeInUpdate? = null,
)
data class UpdateCategoryPayload(
val clientMutationId: String?,
val category: CategoryType
val category: CategoryType,
)
data class UpdateCategoryInput(
val clientMutationId: String? = null,
val id: Int,
val patch: UpdateCategoryPatch
val patch: UpdateCategoryPatch,
)
data class UpdateCategoriesPayload(
val clientMutationId: String?,
val categories: List<CategoryType>
val categories: List<CategoryType>,
)
data class UpdateCategoriesInput(
val clientMutationId: String? = null,
val ids: List<Int>,
val patch: UpdateCategoryPatch
val patch: UpdateCategoryPatch,
)
private fun updateCategories(ids: List<Int>, patch: UpdateCategoryPatch) {
private fun updateCategories(
ids: List<Int>,
patch: UpdateCategoryPatch,
) {
transaction {
if (patch.name != null) {
CategoryTable.update({ CategoryTable.id inList ids }) { update ->
@@ -135,13 +143,14 @@ class CategoryMutation {
updateCategories(listOf(id), patch)
val category = transaction {
CategoryType(CategoryTable.select { CategoryTable.id eq id }.first())
}
val category =
transaction {
CategoryType(CategoryTable.select { CategoryTable.id eq id }.first())
}
return UpdateCategoryPayload(
clientMutationId = clientMutationId,
category = category
category = category,
)
}
@@ -150,24 +159,26 @@ class CategoryMutation {
updateCategories(ids, patch)
val categories = transaction {
CategoryTable.select { CategoryTable.id inList ids }.map { CategoryType(it) }
}
val categories =
transaction {
CategoryTable.select { CategoryTable.id inList ids }.map { CategoryType(it) }
}
return UpdateCategoriesPayload(
clientMutationId = clientMutationId,
categories = categories
categories = categories,
)
}
data class UpdateCategoryOrderPayload(
val clientMutationId: String?,
val categories: List<CategoryType>
val categories: List<CategoryType>,
)
data class UpdateCategoryOrderInput(
val clientMutationId: String? = null,
val id: Int,
val position: Int
val position: Int,
)
fun updateCategoryOrder(input: UpdateCategoryOrderInput): UpdateCategoryOrderPayload {
@@ -177,9 +188,10 @@ class CategoryMutation {
}
transaction {
val currentOrder = CategoryTable
.select { CategoryTable.id eq categoryId }
.first()[CategoryTable.order]
val currentOrder =
CategoryTable
.select { CategoryTable.id eq categoryId }
.first()[CategoryTable.order]
if (currentOrder != position) {
if (position < currentOrder) {
@@ -200,13 +212,14 @@ class CategoryMutation {
Category.normalizeCategories()
val categories = transaction {
CategoryTable.selectAll().orderBy(CategoryTable.order).map { CategoryType(it) }
}
val categories =
transaction {
CategoryTable.selectAll().orderBy(CategoryTable.order).map { CategoryType(it) }
}
return UpdateCategoryOrderPayload(
clientMutationId = clientMutationId,
categories = categories
categories = categories,
)
}
@@ -215,15 +228,15 @@ class CategoryMutation {
val name: String,
val order: Int? = null,
val default: Boolean? = null,
val includeInUpdate: IncludeInUpdate? = null
val includeInUpdate: IncludeInUpdate? = null,
)
data class CreateCategoryPayload(
val clientMutationId: String?,
val category: CategoryType
val category: CategoryType,
)
fun createCategory(
input: CreateCategoryInput
): CreateCategoryPayload {
fun createCategory(input: CreateCategoryInput): CreateCategoryPayload {
val (clientMutationId, name, order, default, includeInUpdate) = input
transaction {
require(CategoryTable.select { CategoryTable.name eq input.name }.isEmpty()) {
@@ -239,104 +252,114 @@ class CategoryMutation {
}
}
val category = transaction {
if (order != null) {
CategoryTable.update({ CategoryTable.order greaterEq order }) {
it[CategoryTable.order] = CategoryTable.order + 1
val category =
transaction {
if (order != null) {
CategoryTable.update({ CategoryTable.order greaterEq order }) {
it[CategoryTable.order] = CategoryTable.order + 1
}
}
val id =
CategoryTable.insertAndGetId {
it[CategoryTable.name] = input.name
it[CategoryTable.order] = order ?: Int.MAX_VALUE
if (default != null) {
it[CategoryTable.isDefault] = default
}
if (includeInUpdate != null) {
it[CategoryTable.includeInUpdate] = includeInUpdate.value
}
}
Category.normalizeCategories()
CategoryType(CategoryTable.select { CategoryTable.id eq id }.first())
}
val id = CategoryTable.insertAndGetId {
it[CategoryTable.name] = input.name
it[CategoryTable.order] = order ?: Int.MAX_VALUE
if (default != null) {
it[CategoryTable.isDefault] = default
}
if (includeInUpdate != null) {
it[CategoryTable.includeInUpdate] = includeInUpdate.value
}
}
Category.normalizeCategories()
CategoryType(CategoryTable.select { CategoryTable.id eq id }.first())
}
return CreateCategoryPayload(clientMutationId, category)
}
data class DeleteCategoryInput(
val clientMutationId: String? = null,
val categoryId: Int
val categoryId: Int,
)
data class DeleteCategoryPayload(
val clientMutationId: String?,
val category: CategoryType?,
val mangas: List<MangaType>
val mangas: List<MangaType>,
)
fun deleteCategory(
input: DeleteCategoryInput
): DeleteCategoryPayload {
fun deleteCategory(input: DeleteCategoryInput): DeleteCategoryPayload {
val (clientMutationId, categoryId) = input
if (categoryId == 0) { // Don't delete default category
return DeleteCategoryPayload(
clientMutationId,
null,
emptyList()
emptyList(),
)
}
val (category, mangas) = transaction {
val category = CategoryTable.select { CategoryTable.id eq categoryId }
.firstOrNull()
val (category, mangas) =
transaction {
val category =
CategoryTable.select { CategoryTable.id eq categoryId }
.firstOrNull()
val mangas = transaction {
MangaTable.innerJoin(CategoryMangaTable)
.select { CategoryMangaTable.category eq categoryId }
.map { MangaType(it) }
val mangas =
transaction {
MangaTable.innerJoin(CategoryMangaTable)
.select { CategoryMangaTable.category eq categoryId }
.map { MangaType(it) }
}
CategoryTable.deleteWhere { CategoryTable.id eq categoryId }
Category.normalizeCategories()
if (category != null) {
CategoryType(category)
} else {
null
} to mangas
}
CategoryTable.deleteWhere { CategoryTable.id eq categoryId }
Category.normalizeCategories()
if (category != null) {
CategoryType(category)
} else {
null
} to mangas
}
return DeleteCategoryPayload(clientMutationId, category, mangas)
}
data class UpdateMangaCategoriesPatch(
val clearCategories: Boolean? = null,
val addToCategories: List<Int>? = null,
val removeFromCategories: List<Int>? = null
val removeFromCategories: List<Int>? = null,
)
data class UpdateMangaCategoriesPayload(
val clientMutationId: String?,
val manga: MangaType
val manga: MangaType,
)
data class UpdateMangaCategoriesInput(
val clientMutationId: String? = null,
val id: Int,
val patch: UpdateMangaCategoriesPatch
val patch: UpdateMangaCategoriesPatch,
)
data class UpdateMangasCategoriesPayload(
val clientMutationId: String?,
val mangas: List<MangaType>
val mangas: List<MangaType>,
)
data class UpdateMangasCategoriesInput(
val clientMutationId: String? = null,
val ids: List<Int>,
val patch: UpdateMangaCategoriesPatch
val patch: UpdateMangaCategoriesPatch,
)
private fun updateMangas(ids: List<Int>, patch: UpdateMangaCategoriesPatch) {
private fun updateMangas(
ids: List<Int>,
patch: UpdateMangaCategoriesPatch,
) {
transaction {
if (patch.clearCategories == true) {
CategoryMangaTable.deleteWhere { CategoryMangaTable.manga inList ids }
@@ -346,19 +369,21 @@ class CategoryMutation {
}
}
if (!patch.addToCategories.isNullOrEmpty()) {
val newCategories = buildList {
ids.forEach { mangaId ->
patch.addToCategories.forEach { categoryId ->
val existingMapping = CategoryMangaTable.select {
(CategoryMangaTable.manga eq mangaId) and (CategoryMangaTable.category eq categoryId)
}.isNotEmpty()
val newCategories =
buildList {
ids.forEach { mangaId ->
patch.addToCategories.forEach { categoryId ->
val existingMapping =
CategoryMangaTable.select {
(CategoryMangaTable.manga eq mangaId) and (CategoryMangaTable.category eq categoryId)
}.isNotEmpty()
if (!existingMapping) {
add(mangaId to categoryId)
if (!existingMapping) {
add(mangaId to categoryId)
}
}
}
}
}
CategoryMangaTable.batchInsert(newCategories) { (manga, category) ->
this[CategoryMangaTable.manga] = manga
@@ -373,13 +398,14 @@ class CategoryMutation {
updateMangas(listOf(id), patch)
val manga = transaction {
MangaType(MangaTable.select { MangaTable.id eq id }.first())
}
val manga =
transaction {
MangaType(MangaTable.select { MangaTable.id eq id }.first())
}
return UpdateMangaCategoriesPayload(
clientMutationId = clientMutationId,
manga = manga
manga = manga,
)
}
@@ -388,13 +414,14 @@ class CategoryMutation {
updateMangas(ids, patch)
val mangas = transaction {
MangaTable.select { MangaTable.id inList ids }.map { MangaType(it) }
}
val mangas =
transaction {
MangaTable.select { MangaTable.id inList ids }.map { MangaType(it) }
}
return UpdateMangasCategoriesPayload(
clientMutationId = clientMutationId,
mangas = mangas
mangas = mangas,
)
}
}

View File

@@ -25,30 +25,35 @@ class ChapterMutation {
data class UpdateChapterPatch(
val isBookmarked: Boolean? = null,
val isRead: Boolean? = null,
val lastPageRead: Int? = null
val lastPageRead: Int? = null,
)
data class UpdateChapterPayload(
val clientMutationId: String?,
val chapter: ChapterType
val chapter: ChapterType,
)
data class UpdateChapterInput(
val clientMutationId: String? = null,
val id: Int,
val patch: UpdateChapterPatch
val patch: UpdateChapterPatch,
)
data class UpdateChaptersPayload(
val clientMutationId: String?,
val chapters: List<ChapterType>
val chapters: List<ChapterType>,
)
data class UpdateChaptersInput(
val clientMutationId: String? = null,
val ids: List<Int>,
val patch: UpdateChapterPatch
val patch: UpdateChapterPatch,
)
private fun updateChapters(ids: List<Int>, patch: UpdateChapterPatch) {
private fun updateChapters(
ids: List<Int>,
patch: UpdateChapterPatch,
) {
transaction {
if (patch.isRead != null || patch.isBookmarked != null || patch.lastPageRead != null) {
val now = Instant.now().epochSecond
@@ -68,81 +73,79 @@ class ChapterMutation {
}
}
fun updateChapter(
input: UpdateChapterInput
): UpdateChapterPayload {
fun updateChapter(input: UpdateChapterInput): UpdateChapterPayload {
val (clientMutationId, id, patch) = input
updateChapters(listOf(id), patch)
val chapter = transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq id }.first())
}
val chapter =
transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq id }.first())
}
return UpdateChapterPayload(
clientMutationId = clientMutationId,
chapter = chapter
chapter = chapter,
)
}
fun updateChapters(
input: UpdateChaptersInput
): UpdateChaptersPayload {
fun updateChapters(input: UpdateChaptersInput): UpdateChaptersPayload {
val (clientMutationId, ids, patch) = input
updateChapters(ids, patch)
val chapters = transaction {
ChapterTable.select { ChapterTable.id inList ids }.map { ChapterType(it) }
}
val chapters =
transaction {
ChapterTable.select { ChapterTable.id inList ids }.map { ChapterType(it) }
}
return UpdateChaptersPayload(
clientMutationId = clientMutationId,
chapters = chapters
chapters = chapters,
)
}
data class FetchChaptersInput(
val clientMutationId: String? = null,
val mangaId: Int
)
data class FetchChaptersPayload(
val clientMutationId: String?,
val chapters: List<ChapterType>
val mangaId: Int,
)
fun fetchChapters(
input: FetchChaptersInput
): CompletableFuture<FetchChaptersPayload> {
data class FetchChaptersPayload(
val clientMutationId: String?,
val chapters: List<ChapterType>,
)
fun fetchChapters(input: FetchChaptersInput): CompletableFuture<FetchChaptersPayload> {
val (clientMutationId, mangaId) = input
return future {
Chapter.fetchChapterList(mangaId)
}.thenApply {
val chapters = transaction {
ChapterTable.select { ChapterTable.manga eq mangaId }
.orderBy(ChapterTable.sourceOrder)
.map { ChapterType(it) }
}
val chapters =
transaction {
ChapterTable.select { ChapterTable.manga eq mangaId }
.orderBy(ChapterTable.sourceOrder)
.map { ChapterType(it) }
}
FetchChaptersPayload(
clientMutationId = clientMutationId,
chapters = chapters
chapters = chapters,
)
}
}
data class SetChapterMetaInput(
val clientMutationId: String? = null,
val meta: ChapterMetaType
val meta: ChapterMetaType,
)
data class SetChapterMetaPayload(
val clientMutationId: String?,
val meta: ChapterMetaType
val meta: ChapterMetaType,
)
fun setChapterMeta(
input: SetChapterMetaInput
): SetChapterMetaPayload {
fun setChapterMeta(input: SetChapterMetaInput): SetChapterMetaPayload {
val (clientMutationId, meta) = input
Chapter.modifyChapterMeta(meta.chapterId, meta.key, meta.value)
@@ -153,50 +156,53 @@ class ChapterMutation {
data class DeleteChapterMetaInput(
val clientMutationId: String? = null,
val chapterId: Int,
val key: String
val key: String,
)
data class DeleteChapterMetaPayload(
val clientMutationId: String?,
val meta: ChapterMetaType?,
val chapter: ChapterType
val chapter: ChapterType,
)
fun deleteChapterMeta(
input: DeleteChapterMetaInput
): DeleteChapterMetaPayload {
fun deleteChapterMeta(input: DeleteChapterMetaInput): DeleteChapterMetaPayload {
val (clientMutationId, chapterId, key) = input
val (meta, chapter) = transaction {
val meta = ChapterMetaTable.select { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
.firstOrNull()
val (meta, chapter) =
transaction {
val meta =
ChapterMetaTable.select { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
.firstOrNull()
ChapterMetaTable.deleteWhere { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
ChapterMetaTable.deleteWhere { (ChapterMetaTable.ref eq chapterId) and (ChapterMetaTable.key eq key) }
val chapter = transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq chapterId }.first())
val chapter =
transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq chapterId }.first())
}
if (meta != null) {
ChapterMetaType(meta)
} else {
null
} to chapter
}
if (meta != null) {
ChapterMetaType(meta)
} else {
null
} to chapter
}
return DeleteChapterMetaPayload(clientMutationId, meta, chapter)
}
data class FetchChapterPagesInput(
val clientMutationId: String? = null,
val chapterId: Int
val chapterId: Int,
)
data class FetchChapterPagesPayload(
val clientMutationId: String?,
val pages: List<String>,
val chapter: ChapterType
val chapter: ChapterType,
)
fun fetchChapterPages(
input: FetchChapterPagesInput
): CompletableFuture<FetchChapterPagesPayload> {
fun fetchChapterPages(input: FetchChapterPagesInput): CompletableFuture<FetchChapterPagesPayload> {
val (clientMutationId, chapterId) = input
return future {
@@ -204,10 +210,11 @@ class ChapterMutation {
}.thenApply { chapter ->
FetchChapterPagesPayload(
clientMutationId = clientMutationId,
pages = List(chapter.pageCount) { index ->
"/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}/page/$index"
},
chapter = ChapterType(chapter)
pages =
List(chapter.pageCount) { index ->
"/api/v1/manga/${chapter.mangaId}/chapter/${chapter.index}/page/$index"
},
chapter = ChapterType(chapter),
)
}
}

View File

@@ -16,14 +16,14 @@ import java.util.concurrent.CompletableFuture
import kotlin.time.Duration.Companion.seconds
class DownloadMutation {
data class DeleteDownloadedChaptersInput(
val clientMutationId: String? = null,
val ids: List<Int>
val ids: List<Int>,
)
data class DeleteDownloadedChaptersPayload(
val clientMutationId: String?,
val chapters: List<ChapterType>
val chapters: List<ChapterType>,
)
fun deleteDownloadedChapters(input: DeleteDownloadedChaptersInput): DeleteDownloadedChaptersPayload {
@@ -33,20 +33,22 @@ class DownloadMutation {
return DeleteDownloadedChaptersPayload(
clientMutationId = clientMutationId,
chapters = transaction {
ChapterTable.select { ChapterTable.id inList chapters }
.map { ChapterType(it) }
}
chapters =
transaction {
ChapterTable.select { ChapterTable.id inList chapters }
.map { ChapterType(it) }
},
)
}
data class DeleteDownloadedChapterInput(
val clientMutationId: String? = null,
val id: Int
val id: Int,
)
data class DeleteDownloadedChapterPayload(
val clientMutationId: String?,
val chapters: ChapterType
val chapters: ChapterType,
)
fun deleteDownloadedChapter(input: DeleteDownloadedChapterInput): DeleteDownloadedChapterPayload {
@@ -56,24 +58,24 @@ class DownloadMutation {
return DeleteDownloadedChapterPayload(
clientMutationId = clientMutationId,
chapters = transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq chapter }.first())
}
chapters =
transaction {
ChapterType(ChapterTable.select { ChapterTable.id eq chapter }.first())
},
)
}
data class EnqueueChapterDownloadsInput(
val clientMutationId: String? = null,
val ids: List<Int>
)
data class EnqueueChapterDownloadsPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus
val ids: List<Int>,
)
fun enqueueChapterDownloads(
input: EnqueueChapterDownloadsInput
): CompletableFuture<EnqueueChapterDownloadsPayload> {
data class EnqueueChapterDownloadsPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus,
)
fun enqueueChapterDownloads(input: EnqueueChapterDownloadsInput): CompletableFuture<EnqueueChapterDownloadsPayload> {
val (clientMutationId, chapters) = input
DownloadManager.enqueue(DownloadManager.EnqueueInput(chapters))
@@ -81,25 +83,25 @@ class DownloadMutation {
return future {
EnqueueChapterDownloadsPayload(
clientMutationId = clientMutationId,
downloadStatus = withTimeout(30.seconds) {
DownloadStatus(DownloadManager.status.first { it.queue.any { it.chapter.id in chapters } })
}
downloadStatus =
withTimeout(30.seconds) {
DownloadStatus(DownloadManager.status.first { it.queue.any { it.chapter.id in chapters } })
},
)
}
}
data class EnqueueChapterDownloadInput(
val clientMutationId: String? = null,
val id: Int
)
data class EnqueueChapterDownloadPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus
val id: Int,
)
fun enqueueChapterDownload(
input: EnqueueChapterDownloadInput
): CompletableFuture<EnqueueChapterDownloadPayload> {
data class EnqueueChapterDownloadPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus,
)
fun enqueueChapterDownload(input: EnqueueChapterDownloadInput): CompletableFuture<EnqueueChapterDownloadPayload> {
val (clientMutationId, chapter) = input
DownloadManager.enqueue(DownloadManager.EnqueueInput(listOf(chapter)))
@@ -107,25 +109,25 @@ class DownloadMutation {
return future {
EnqueueChapterDownloadPayload(
clientMutationId = clientMutationId,
downloadStatus = withTimeout(30.seconds) {
DownloadStatus(DownloadManager.status.first { it.queue.any { it.chapter.id == chapter } })
}
downloadStatus =
withTimeout(30.seconds) {
DownloadStatus(DownloadManager.status.first { it.queue.any { it.chapter.id == chapter } })
},
)
}
}
data class DequeueChapterDownloadsInput(
val clientMutationId: String? = null,
val ids: List<Int>
)
data class DequeueChapterDownloadsPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus
val ids: List<Int>,
)
fun dequeueChapterDownloads(
input: DequeueChapterDownloadsInput
): CompletableFuture<DequeueChapterDownloadsPayload> {
data class DequeueChapterDownloadsPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus,
)
fun dequeueChapterDownloads(input: DequeueChapterDownloadsInput): CompletableFuture<DequeueChapterDownloadsPayload> {
val (clientMutationId, chapters) = input
DownloadManager.dequeue(DownloadManager.EnqueueInput(chapters))
@@ -133,25 +135,25 @@ class DownloadMutation {
return future {
DequeueChapterDownloadsPayload(
clientMutationId = clientMutationId,
downloadStatus = withTimeout(30.seconds) {
DownloadStatus(DownloadManager.status.first { it.queue.none { it.chapter.id in chapters } })
}
downloadStatus =
withTimeout(30.seconds) {
DownloadStatus(DownloadManager.status.first { it.queue.none { it.chapter.id in chapters } })
},
)
}
}
data class DequeueChapterDownloadInput(
val clientMutationId: String? = null,
val id: Int
)
data class DequeueChapterDownloadPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus
val id: Int,
)
fun dequeueChapterDownload(
input: DequeueChapterDownloadInput
): CompletableFuture<DequeueChapterDownloadPayload> {
data class DequeueChapterDownloadPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus,
)
fun dequeueChapterDownload(input: DequeueChapterDownloadInput): CompletableFuture<DequeueChapterDownloadPayload> {
val (clientMutationId, chapter) = input
DownloadManager.dequeue(DownloadManager.EnqueueInput(listOf(chapter)))
@@ -159,19 +161,21 @@ class DownloadMutation {
return future {
DequeueChapterDownloadPayload(
clientMutationId = clientMutationId,
downloadStatus = withTimeout(30.seconds) {
DownloadStatus(DownloadManager.status.first { it.queue.none { it.chapter.id == chapter } })
}
downloadStatus =
withTimeout(30.seconds) {
DownloadStatus(DownloadManager.status.first { it.queue.none { it.chapter.id == chapter } })
},
)
}
}
data class StartDownloaderInput(
val clientMutationId: String? = null
val clientMutationId: String? = null,
)
data class StartDownloaderPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus
val downloadStatus: DownloadStatus,
)
fun startDownloader(input: StartDownloaderInput): CompletableFuture<StartDownloaderPayload> {
@@ -180,21 +184,23 @@ class DownloadMutation {
return future {
StartDownloaderPayload(
input.clientMutationId,
downloadStatus = withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.status.first { it.status == Status.Started }
)
}
downloadStatus =
withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.status.first { it.status == Status.Started },
)
},
)
}
}
data class StopDownloaderInput(
val clientMutationId: String? = null
val clientMutationId: String? = null,
)
data class StopDownloaderPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus
val downloadStatus: DownloadStatus,
)
fun stopDownloader(input: StopDownloaderInput): CompletableFuture<StopDownloaderPayload> {
@@ -202,21 +208,23 @@ class DownloadMutation {
DownloadManager.stop()
StopDownloaderPayload(
input.clientMutationId,
downloadStatus = withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.status.first { it.status == Status.Stopped }
)
}
downloadStatus =
withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.status.first { it.status == Status.Stopped },
)
},
)
}
}
data class ClearDownloaderInput(
val clientMutationId: String? = null
val clientMutationId: String? = null,
)
data class ClearDownloaderPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus
val downloadStatus: DownloadStatus,
)
fun clearDownloader(input: ClearDownloaderInput): CompletableFuture<ClearDownloaderPayload> {
@@ -224,11 +232,12 @@ class DownloadMutation {
DownloadManager.clear()
ClearDownloaderPayload(
input.clientMutationId,
downloadStatus = withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.status.first { it.status == Status.Stopped && it.queue.isEmpty() }
)
}
downloadStatus =
withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.status.first { it.status == Status.Stopped && it.queue.isEmpty() },
)
},
)
}
}
@@ -236,11 +245,12 @@ class DownloadMutation {
data class ReorderChapterDownloadInput(
val clientMutationId: String? = null,
val chapterId: Int,
val to: Int
val to: Int,
)
data class ReorderChapterDownloadPayload(
val clientMutationId: String?,
val downloadStatus: DownloadStatus
val downloadStatus: DownloadStatus,
)
fun reorderChapterDownload(input: ReorderChapterDownloadInput): CompletableFuture<ReorderChapterDownloadPayload> {
@@ -250,11 +260,12 @@ class DownloadMutation {
return future {
ReorderChapterDownloadPayload(
clientMutationId,
downloadStatus = withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.status.first { it.queue.indexOfFirst { it.chapter.id == chapter } <= to }
)
}
downloadStatus =
withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.status.first { it.queue.indexOfFirst { it.chapter.id == chapter } <= to },
)
},
)
}
}
@@ -262,7 +273,7 @@ class DownloadMutation {
data class DownloadAheadInput(
val clientMutationId: String? = null,
val mangaIds: List<Int> = emptyList(),
val latestReadChapterIds: List<Int>? = null
val latestReadChapterIds: List<Int>? = null,
)
data class DownloadAheadPayload(val clientMutationId: String?)

View File

@@ -15,34 +15,40 @@ class ExtensionMutation {
data class UpdateExtensionPatch(
val install: Boolean? = null,
val update: Boolean? = null,
val uninstall: Boolean? = null
val uninstall: Boolean? = null,
)
data class UpdateExtensionPayload(
val clientMutationId: String?,
val extension: ExtensionType
val extension: ExtensionType,
)
data class UpdateExtensionInput(
val clientMutationId: String? = null,
val id: String,
val patch: UpdateExtensionPatch
val patch: UpdateExtensionPatch,
)
data class UpdateExtensionsPayload(
val clientMutationId: String?,
val extensions: List<ExtensionType>
val extensions: List<ExtensionType>,
)
data class UpdateExtensionsInput(
val clientMutationId: String? = null,
val ids: List<String>,
val patch: UpdateExtensionPatch
val patch: UpdateExtensionPatch,
)
private suspend fun updateExtensions(ids: List<String>, patch: UpdateExtensionPatch) {
val extensions = transaction {
ExtensionTable.select { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
}
private suspend fun updateExtensions(
ids: List<String>,
patch: UpdateExtensionPatch,
) {
val extensions =
transaction {
ExtensionTable.select { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
}
if (patch.update == true) {
extensions.filter { it.hasUpdate }.forEach {
@@ -69,13 +75,14 @@ class ExtensionMutation {
return future {
updateExtensions(listOf(id), patch)
}.thenApply {
val extension = transaction {
ExtensionType(ExtensionTable.select { ExtensionTable.pkgName eq id }.first())
}
val extension =
transaction {
ExtensionType(ExtensionTable.select { ExtensionTable.pkgName eq id }.first())
}
UpdateExtensionPayload(
clientMutationId = clientMutationId,
extension = extension
extension = extension,
)
}
}
@@ -86,54 +93,55 @@ class ExtensionMutation {
return future {
updateExtensions(ids, patch)
}.thenApply {
val extensions = transaction {
ExtensionTable.select { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
}
val extensions =
transaction {
ExtensionTable.select { ExtensionTable.pkgName inList ids }
.map { ExtensionType(it) }
}
UpdateExtensionsPayload(
clientMutationId = clientMutationId,
extensions = extensions
extensions = extensions,
)
}
}
data class FetchExtensionsInput(
val clientMutationId: String? = null
)
data class FetchExtensionsPayload(
val clientMutationId: String?,
val extensions: List<ExtensionType>
val clientMutationId: String? = null,
)
fun fetchExtensions(
input: FetchExtensionsInput
): CompletableFuture<FetchExtensionsPayload> {
data class FetchExtensionsPayload(
val clientMutationId: String?,
val extensions: List<ExtensionType>,
)
fun fetchExtensions(input: FetchExtensionsInput): CompletableFuture<FetchExtensionsPayload> {
val (clientMutationId) = input
return future {
ExtensionsList.fetchExtensions()
}.thenApply {
val extensions = transaction {
ExtensionTable.select { ExtensionTable.name neq LocalSource.EXTENSION_NAME }
.map { ExtensionType(it) }
}
val extensions =
transaction {
ExtensionTable.select { ExtensionTable.name neq LocalSource.EXTENSION_NAME }
.map { ExtensionType(it) }
}
FetchExtensionsPayload(
clientMutationId = clientMutationId,
extensions = extensions
extensions = extensions,
)
}
}
data class InstallExternalExtensionInput(
val clientMutationId: String? = null,
val extensionFile: UploadedFile
val extensionFile: UploadedFile,
)
data class InstallExternalExtensionPayload(
val clientMutationId: String?,
val extension: ExtensionType
val extension: ExtensionType,
)
fun installExternalExtension(input: InstallExternalExtensionInput): CompletableFuture<InstallExternalExtensionPayload> {
@@ -146,7 +154,7 @@ class ExtensionMutation {
InstallExternalExtensionPayload(
clientMutationId,
extension = ExtensionType(dbExtension)
extension = ExtensionType(dbExtension),
)
}
}

View File

@@ -14,12 +14,12 @@ import kotlin.time.Duration.Companion.seconds
class InfoMutation {
data class WebUIUpdateInput(
val clientMutationId: String? = null
val clientMutationId: String? = null,
)
data class WebUIUpdatePayload(
val clientMutationId: String?,
val updateStatus: WebUIUpdateStatus
val updateStatus: WebUIUpdateStatus,
)
fun updateWebUI(input: WebUIUpdateInput): CompletableFuture<WebUIUpdatePayload> {
@@ -35,14 +35,15 @@ class InfoMutation {
return@withTimeout WebUIUpdatePayload(
input.clientMutationId,
WebUIUpdateStatus(
info = WebUIUpdateInfo(
channel = serverConfig.webUIChannel.value,
tag = version,
updateAvailable
),
info =
WebUIUpdateInfo(
channel = serverConfig.webUIChannel.value,
tag = version,
updateAvailable,
),
state = STOPPED,
progress = 0
)
progress = 0,
),
)
}
try {
@@ -53,7 +54,7 @@ class InfoMutation {
WebUIUpdatePayload(
input.clientMutationId,
updateStatus = WebInterfaceManager.status.first { it.state == DOWNLOADING }
updateStatus = WebInterfaceManager.status.first { it.state == DOWNLOADING },
)
}
}

View File

@@ -22,30 +22,35 @@ import java.util.concurrent.CompletableFuture
*/
class MangaMutation {
data class UpdateMangaPatch(
val inLibrary: Boolean? = null
val inLibrary: Boolean? = null,
)
data class UpdateMangaPayload(
val clientMutationId: String?,
val manga: MangaType
val manga: MangaType,
)
data class UpdateMangaInput(
val clientMutationId: String? = null,
val id: Int,
val patch: UpdateMangaPatch
val patch: UpdateMangaPatch,
)
data class UpdateMangasPayload(
val clientMutationId: String?,
val mangas: List<MangaType>
val mangas: List<MangaType>,
)
data class UpdateMangasInput(
val clientMutationId: String? = null,
val ids: List<Int>,
val patch: UpdateMangaPatch
val patch: UpdateMangaPatch,
)
private suspend fun updateMangas(ids: List<Int>, patch: UpdateMangaPatch) {
private suspend fun updateMangas(
ids: List<Int>,
patch: UpdateMangaPatch,
) {
transaction {
if (patch.inLibrary != null) {
MangaTable.update({ MangaTable.id inList ids }) { update ->
@@ -69,13 +74,14 @@ class MangaMutation {
return future {
updateMangas(listOf(id), patch)
}.thenApply {
val manga = transaction {
MangaType(MangaTable.select { MangaTable.id eq id }.first())
}
val manga =
transaction {
MangaType(MangaTable.select { MangaTable.id eq id }.first())
}
UpdateMangaPayload(
clientMutationId = clientMutationId,
manga = manga
manga = manga,
)
}
}
@@ -86,55 +92,56 @@ class MangaMutation {
return future {
updateMangas(ids, patch)
}.thenApply {
val mangas = transaction {
MangaTable.select { MangaTable.id inList ids }.map { MangaType(it) }
}
val mangas =
transaction {
MangaTable.select { MangaTable.id inList ids }.map { MangaType(it) }
}
UpdateMangasPayload(
clientMutationId = clientMutationId,
mangas = mangas
mangas = mangas,
)
}
}
data class FetchMangaInput(
val clientMutationId: String? = null,
val id: Int
)
data class FetchMangaPayload(
val clientMutationId: String?,
val manga: MangaType
val id: Int,
)
fun fetchManga(
input: FetchMangaInput
): CompletableFuture<FetchMangaPayload> {
data class FetchMangaPayload(
val clientMutationId: String?,
val manga: MangaType,
)
fun fetchManga(input: FetchMangaInput): CompletableFuture<FetchMangaPayload> {
val (clientMutationId, id) = input
return future {
Manga.fetchManga(id)
}.thenApply {
val manga = transaction {
MangaTable.select { MangaTable.id eq id }.first()
}
val manga =
transaction {
MangaTable.select { MangaTable.id eq id }.first()
}
FetchMangaPayload(
clientMutationId = clientMutationId,
manga = MangaType(manga)
manga = MangaType(manga),
)
}
}
data class SetMangaMetaInput(
val clientMutationId: String? = null,
val meta: MangaMetaType
val meta: MangaMetaType,
)
data class SetMangaMetaPayload(
val clientMutationId: String?,
val meta: MangaMetaType
val meta: MangaMetaType,
)
fun setMangaMeta(
input: SetMangaMetaInput
): SetMangaMetaPayload {
fun setMangaMeta(input: SetMangaMetaInput): SetMangaMetaPayload {
val (clientMutationId, meta) = input
Manga.modifyMangaMeta(meta.mangaId, meta.key, meta.value)
@@ -145,35 +152,38 @@ class MangaMutation {
data class DeleteMangaMetaInput(
val clientMutationId: String? = null,
val mangaId: Int,
val key: String
val key: String,
)
data class DeleteMangaMetaPayload(
val clientMutationId: String?,
val meta: MangaMetaType?,
val manga: MangaType
val manga: MangaType,
)
fun deleteMangaMeta(
input: DeleteMangaMetaInput
): DeleteMangaMetaPayload {
fun deleteMangaMeta(input: DeleteMangaMetaInput): DeleteMangaMetaPayload {
val (clientMutationId, mangaId, key) = input
val (meta, manga) = transaction {
val meta = MangaMetaTable.select { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
.firstOrNull()
val (meta, manga) =
transaction {
val meta =
MangaMetaTable.select { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
.firstOrNull()
MangaMetaTable.deleteWhere { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
MangaMetaTable.deleteWhere { (MangaMetaTable.ref eq mangaId) and (MangaMetaTable.key eq key) }
val manga = transaction {
MangaType(MangaTable.select { MangaTable.id eq mangaId }.first())
val manga =
transaction {
MangaType(MangaTable.select { MangaTable.id eq mangaId }.first())
}
if (meta != null) {
MangaMetaType(meta)
} else {
null
} to manga
}
if (meta != null) {
MangaMetaType(meta)
} else {
null
} to manga
}
return DeleteMangaMetaPayload(clientMutationId, meta, manga)
}
}

View File

@@ -9,18 +9,17 @@ import suwayomi.tachidesk.global.model.table.GlobalMetaTable
import suwayomi.tachidesk.graphql.types.GlobalMetaType
class MetaMutation {
data class SetGlobalMetaInput(
val clientMutationId: String? = null,
val meta: GlobalMetaType
val meta: GlobalMetaType,
)
data class SetGlobalMetaPayload(
val clientMutationId: String?,
val meta: GlobalMetaType
val meta: GlobalMetaType,
)
fun setGlobalMeta(
input: SetGlobalMetaInput
): SetGlobalMetaPayload {
fun setGlobalMeta(input: SetGlobalMetaInput): SetGlobalMetaPayload {
val (clientMutationId, meta) = input
GlobalMeta.modifyMeta(meta.key, meta.value)
@@ -30,29 +29,31 @@ class MetaMutation {
data class DeleteGlobalMetaInput(
val clientMutationId: String? = null,
val key: String
val key: String,
)
data class DeleteGlobalMetaPayload(
val clientMutationId: String?,
val meta: GlobalMetaType?
val meta: GlobalMetaType?,
)
fun deleteGlobalMeta(
input: DeleteGlobalMetaInput
): DeleteGlobalMetaPayload {
fun deleteGlobalMeta(input: DeleteGlobalMetaInput): DeleteGlobalMetaPayload {
val (clientMutationId, key) = input
val meta = transaction {
val meta = GlobalMetaTable.select { GlobalMetaTable.key eq key }
.firstOrNull()
val meta =
transaction {
val meta =
GlobalMetaTable.select { GlobalMetaTable.key eq key }
.firstOrNull()
GlobalMetaTable.deleteWhere { GlobalMetaTable.key eq key }
GlobalMetaTable.deleteWhere { GlobalMetaTable.key eq key }
if (meta != null) {
GlobalMetaType(meta)
} else {
null
if (meta != null) {
GlobalMetaType(meta)
} else {
null
}
}
}
return DeleteGlobalMetaPayload(clientMutationId, meta)
}

View File

@@ -11,53 +11,107 @@ import xyz.nulldev.ts.config.GlobalConfigManager
class SettingsMutation {
data class SetSettingsInput(
val clientMutationId: String? = null,
val settings: PartialSettingsType
val settings: PartialSettingsType,
)
data class SetSettingsPayload(
val clientMutationId: String?,
val settings: SettingsType
val settings: SettingsType,
)
private fun updateSettings(settings: Settings) {
if (settings.ip != null) serverConfig.ip.value = settings.ip!!
if (settings.port != null) serverConfig.port.value = settings.port!!
if (settings.socksProxyEnabled != null) serverConfig.socksProxyEnabled.value = settings.socksProxyEnabled!!
if (settings.socksProxyHost != null) serverConfig.socksProxyHost.value = settings.socksProxyHost!!
if (settings.socksProxyPort != null) serverConfig.socksProxyPort.value = settings.socksProxyPort!!
if (settings.socksProxyEnabled != null) {
serverConfig.socksProxyEnabled.value = settings.socksProxyEnabled!!
}
if (settings.socksProxyHost != null) {
serverConfig.socksProxyHost.value = settings.socksProxyHost!!
}
if (settings.socksProxyPort != null) {
serverConfig.socksProxyPort.value = settings.socksProxyPort!!
}
if (settings.webUIFlavor != null) serverConfig.webUIFlavor.value = settings.webUIFlavor!!.uiName
if (settings.initialOpenInBrowserEnabled != null) serverConfig.initialOpenInBrowserEnabled.value = settings.initialOpenInBrowserEnabled!!
if (settings.webUIInterface != null) serverConfig.webUIInterface.value = settings.webUIInterface!!.name.lowercase()
if (settings.electronPath != null) serverConfig.electronPath.value = settings.electronPath!!
if (settings.webUIChannel != null) serverConfig.webUIChannel.value = settings.webUIChannel!!.name.lowercase()
if (settings.webUIUpdateCheckInterval != null) serverConfig.webUIUpdateCheckInterval.value = settings.webUIUpdateCheckInterval!!
if (settings.webUIFlavor != null) {
serverConfig.webUIFlavor.value = settings.webUIFlavor!!.uiName
}
if (settings.initialOpenInBrowserEnabled != null) {
serverConfig.initialOpenInBrowserEnabled.value = settings.initialOpenInBrowserEnabled!!
}
if (settings.webUIInterface != null) {
serverConfig.webUIInterface.value = settings.webUIInterface!!.name.lowercase()
}
if (settings.electronPath != null) {
serverConfig.electronPath.value = settings.electronPath!!
}
if (settings.webUIChannel != null) {
serverConfig.webUIChannel.value = settings.webUIChannel!!.name.lowercase()
}
if (settings.webUIUpdateCheckInterval != null) {
serverConfig.webUIUpdateCheckInterval.value = settings.webUIUpdateCheckInterval!!
}
if (settings.downloadAsCbz != null) serverConfig.downloadAsCbz.value = settings.downloadAsCbz!!
if (settings.downloadsPath != null) serverConfig.downloadsPath.value = settings.downloadsPath!!
if (settings.autoDownloadNewChapters != null) serverConfig.autoDownloadNewChapters.value = settings.autoDownloadNewChapters!!
if (settings.downloadAsCbz != null) {
serverConfig.downloadAsCbz.value = settings.downloadAsCbz!!
}
if (settings.downloadsPath != null) {
serverConfig.downloadsPath.value = settings.downloadsPath!!
}
if (settings.autoDownloadNewChapters != null) {
serverConfig.autoDownloadNewChapters.value = settings.autoDownloadNewChapters!!
}
if (settings.maxSourcesInParallel != null) serverConfig.maxSourcesInParallel.value = settings.maxSourcesInParallel!!
if (settings.maxSourcesInParallel != null) {
serverConfig.maxSourcesInParallel.value = settings.maxSourcesInParallel!!
}
if (settings.excludeUnreadChapters != null) serverConfig.excludeUnreadChapters.value = settings.excludeUnreadChapters!!
if (settings.excludeNotStarted != null) serverConfig.excludeNotStarted.value = settings.excludeNotStarted!!
if (settings.excludeCompleted != null) serverConfig.excludeCompleted.value = settings.excludeCompleted!!
if (settings.globalUpdateInterval != null) serverConfig.globalUpdateInterval.value = settings.globalUpdateInterval!!
if (settings.excludeUnreadChapters != null) {
serverConfig.excludeUnreadChapters.value = settings.excludeUnreadChapters!!
}
if (settings.excludeNotStarted != null) {
serverConfig.excludeNotStarted.value = settings.excludeNotStarted!!
}
if (settings.excludeCompleted != null) {
serverConfig.excludeCompleted.value = settings.excludeCompleted!!
}
if (settings.globalUpdateInterval != null) {
serverConfig.globalUpdateInterval.value = settings.globalUpdateInterval!!
}
if (settings.basicAuthEnabled != null) serverConfig.basicAuthEnabled.value = settings.basicAuthEnabled!!
if (settings.basicAuthUsername != null) serverConfig.basicAuthUsername.value = settings.basicAuthUsername!!
if (settings.basicAuthPassword != null) serverConfig.basicAuthPassword.value = settings.basicAuthPassword!!
if (settings.basicAuthEnabled != null) {
serverConfig.basicAuthEnabled.value = settings.basicAuthEnabled!!
}
if (settings.basicAuthUsername != null) {
serverConfig.basicAuthUsername.value = settings.basicAuthUsername!!
}
if (settings.basicAuthPassword != null) {
serverConfig.basicAuthPassword.value = settings.basicAuthPassword!!
}
if (settings.debugLogsEnabled != null) serverConfig.debugLogsEnabled.value = settings.debugLogsEnabled!!
if (settings.systemTrayEnabled != null) serverConfig.systemTrayEnabled.value = settings.systemTrayEnabled!!
if (settings.debugLogsEnabled != null) {
serverConfig.debugLogsEnabled.value = settings.debugLogsEnabled!!
}
if (settings.systemTrayEnabled != null) {
serverConfig.systemTrayEnabled.value = settings.systemTrayEnabled!!
}
if (settings.backupPath != null) serverConfig.backupPath.value = settings.backupPath!!
if (settings.backupTime != null) serverConfig.backupTime.value = settings.backupTime!!
if (settings.backupInterval != null) serverConfig.backupInterval.value = settings.backupInterval!!
if (settings.backupTTL != null) serverConfig.backupTTL.value = settings.backupTTL!!
if (settings.backupPath != null) {
serverConfig.backupPath.value = settings.backupPath!!
}
if (settings.backupTime != null) {
serverConfig.backupTime.value = settings.backupTime!!
}
if (settings.backupInterval != null) {
serverConfig.backupInterval.value = settings.backupInterval!!
}
if (settings.backupTTL != null) {
serverConfig.backupTTL.value = settings.backupTTL!!
}
if (settings.localSourcePath != null) serverConfig.localSourcePath.value = settings.localSourcePath!!
if (settings.localSourcePath != null) {
serverConfig.localSourcePath.value = settings.localSourcePath!!
}
}
fun setSettings(input: SetSettingsInput): SetSettingsPayload {
@@ -72,7 +126,7 @@ class SettingsMutation {
data class ResetSettingsPayload(
val clientMutationId: String?,
val settings: SettingsType
val settings: SettingsType,
)
fun resetSettings(input: ResetSettingsInput): ResetSettingsPayload {

View File

@@ -20,63 +20,64 @@ import suwayomi.tachidesk.server.JavalinSetup.future
import java.util.concurrent.CompletableFuture
class SourceMutation {
enum class FetchSourceMangaType {
SEARCH,
POPULAR,
LATEST
LATEST,
}
data class FetchSourceMangaInput(
val clientMutationId: String? = null,
val source: Long,
val type: FetchSourceMangaType,
val page: Int,
val query: String? = null,
val filters: List<FilterChange>? = null
val filters: List<FilterChange>? = null,
)
data class FetchSourceMangaPayload(
val clientMutationId: String?,
val mangas: List<MangaType>,
val hasNextPage: Boolean
val hasNextPage: Boolean,
)
fun fetchSourceManga(
input: FetchSourceMangaInput
): CompletableFuture<FetchSourceMangaPayload> {
fun fetchSourceManga(input: FetchSourceMangaInput): CompletableFuture<FetchSourceMangaPayload> {
val (clientMutationId, sourceId, type, page, query, filters) = input
return future {
val source = GetCatalogueSource.getCatalogueSourceOrNull(sourceId)!!
val mangasPage = when (type) {
FetchSourceMangaType.SEARCH -> {
source.getSearchManga(
page = page,
query = query.orEmpty(),
filters = updateFilterList(source, filters)
)
val mangasPage =
when (type) {
FetchSourceMangaType.SEARCH -> {
source.getSearchManga(
page = page,
query = query.orEmpty(),
filters = updateFilterList(source, filters),
)
}
FetchSourceMangaType.POPULAR -> {
source.getPopularManga(page)
}
FetchSourceMangaType.LATEST -> {
if (!source.supportsLatest) throw Exception("Source does not support latest")
source.getLatestUpdates(page)
}
}
FetchSourceMangaType.POPULAR -> {
source.getPopularManga(page)
}
FetchSourceMangaType.LATEST -> {
if (!source.supportsLatest) throw Exception("Source does not support latest")
source.getLatestUpdates(page)
}
}
val mangaIds = mangasPage.insertOrGet(sourceId)
val mangas = transaction {
MangaTable.select { MangaTable.id inList mangaIds }
.map { MangaType(it) }
}.sortedBy {
mangaIds.indexOf(it.id)
}
val mangas =
transaction {
MangaTable.select { MangaTable.id inList mangaIds }
.map { MangaType(it) }
}.sortedBy {
mangaIds.indexOf(it.id)
}
FetchSourceMangaPayload(
clientMutationId = clientMutationId,
mangas = mangas,
hasNextPage = mangasPage.hasNextPage
hasNextPage = mangasPage.hasNextPage,
)
}
}
@@ -87,21 +88,21 @@ class SourceMutation {
val checkBoxState: Boolean? = null,
val editTextState: String? = null,
val listState: String? = null,
val multiSelectState: List<String>? = null
val multiSelectState: List<String>? = null,
)
data class UpdateSourcePreferenceInput(
val clientMutationId: String? = null,
val source: Long,
val change: SourcePreferenceChange
)
data class UpdateSourcePreferencePayload(
val clientMutationId: String?,
val preferences: List<Preference>
val change: SourcePreferenceChange,
)
fun updateSourcePreference(
input: UpdateSourcePreferenceInput
): UpdateSourcePreferencePayload {
data class UpdateSourcePreferencePayload(
val clientMutationId: String?,
val preferences: List<Preference>,
)
fun updateSourcePreference(input: UpdateSourcePreferenceInput): UpdateSourcePreferencePayload {
val (clientMutationId, sourceId, change) = input
Source.setSourcePreference(sourceId, change.position, "") { preference ->
@@ -117,7 +118,7 @@ class SourceMutation {
return UpdateSourcePreferencePayload(
clientMutationId = clientMutationId,
preferences = Source.getSourcePreferencesRaw(sourceId).map { preferenceOf(it) }
preferences = Source.getSourcePreferencesRaw(sourceId).map { preferenceOf(it) },
)
}
}

View File

@@ -15,18 +15,19 @@ class UpdateMutation {
private val updater by DI.global.instance<IUpdater>()
data class UpdateLibraryMangaInput(
val clientMutationId: String? = null
val clientMutationId: String? = null,
)
data class UpdateLibraryMangaPayload(
val clientMutationId: String?,
val updateStatus: UpdateStatus
val updateStatus: UpdateStatus,
)
fun updateLibraryManga(input: UpdateLibraryMangaInput): UpdateLibraryMangaPayload {
updater.addCategoriesToUpdateQueue(
Category.getCategoryList(),
clear = true,
forceAll = false
forceAll = false,
)
return UpdateLibraryMangaPayload(input.clientMutationId, UpdateStatus(updater.status.value))
@@ -34,32 +35,35 @@ class UpdateMutation {
data class UpdateCategoryMangaInput(
val clientMutationId: String? = null,
val categories: List<Int>
val categories: List<Int>,
)
data class UpdateCategoryMangaPayload(
val clientMutationId: String?,
val updateStatus: UpdateStatus
val updateStatus: UpdateStatus,
)
fun updateCategoryManga(input: UpdateCategoryMangaInput): UpdateCategoryMangaPayload {
val categories = transaction {
CategoryTable.select { CategoryTable.id inList input.categories }.map {
CategoryTable.toDataClass(it)
val categories =
transaction {
CategoryTable.select { CategoryTable.id inList input.categories }.map {
CategoryTable.toDataClass(it)
}
}
}
updater.addCategoriesToUpdateQueue(categories, clear = true, forceAll = true)
return UpdateCategoryMangaPayload(
clientMutationId = input.clientMutationId,
updateStatus = UpdateStatus(updater.status.value)
updateStatus = UpdateStatus(updater.status.value),
)
}
data class UpdateStopInput(
val clientMutationId: String? = null
val clientMutationId: String? = null,
)
data class UpdateStopPayload(
val clientMutationId: String?
val clientMutationId: String?,
)
fun updateStop(input: UpdateStopInput): UpdateStopPayload {

View File

@@ -8,21 +8,22 @@ import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupValidator
class BackupQuery {
data class ValidateBackupInput(
val backup: UploadedFile
val backup: UploadedFile,
)
data class ValidateBackupSource(
val id: Long,
val name: String
val name: String,
)
data class ValidateBackupResult(
val missingSources: List<ValidateBackupSource>
val missingSources: List<ValidateBackupSource>,
)
fun validateBackup(
input: ValidateBackupInput
): ValidateBackupResult {
fun validateBackup(input: ValidateBackupInput): ValidateBackupResult {
val result = ProtoBackupValidator.validate(input.backup.content)
return ValidateBackupResult(
result.missingSourceIds.map { ValidateBackupSource(it.first, it.second) }
result.missingSourceIds.map { ValidateBackupSource(it.first, it.second) },
)
}

View File

@@ -46,14 +46,18 @@ import suwayomi.tachidesk.manga.model.table.CategoryTable
import java.util.concurrent.CompletableFuture
class CategoryQuery {
fun category(dataFetchingEnvironment: DataFetchingEnvironment, id: Int): CompletableFuture<CategoryType> {
fun category(
dataFetchingEnvironment: DataFetchingEnvironment,
id: Int,
): CompletableFuture<CategoryType> {
return dataFetchingEnvironment.getValueFromDataLoader("CategoryDataLoader", id)
}
enum class CategoryOrderBy(override val column: Column<out Comparable<*>>) : OrderBy<CategoryType> {
ID(CategoryTable.id),
NAME(CategoryTable.name),
ORDER(CategoryTable.order);
ORDER(CategoryTable.order),
;
override fun greater(cursor: Cursor): Op<Boolean> {
return when (this) {
@@ -72,11 +76,12 @@ class CategoryQuery {
}
override fun asCursor(type: CategoryType): Cursor {
val value = when (this) {
ID -> type.id.toString()
NAME -> type.id.toString() + "-" + type.name
ORDER -> type.id.toString() + "-" + type.order
}
val value =
when (this) {
ID -> type.id.toString()
NAME -> type.id.toString() + "-" + type.name
ORDER -> type.id.toString() + "-" + type.order
}
return Cursor(value)
}
}
@@ -85,7 +90,7 @@ class CategoryQuery {
val id: Int? = null,
val order: Int? = null,
val name: String? = null,
val default: Boolean? = null
val default: Boolean? = null,
) : HasGetOp {
override fun getOp(): Op<Boolean>? {
val opAnd = OpAnd()
@@ -105,14 +110,14 @@ class CategoryQuery {
val default: BooleanFilter? = null,
override val and: List<CategoryFilter>? = null,
override val or: List<CategoryFilter>? = null,
override val not: CategoryFilter? = null
override val not: CategoryFilter? = null,
) : Filter<CategoryFilter> {
override fun getOpList(): List<Op<Boolean>> {
return listOfNotNull(
andFilterWithCompareEntity(CategoryTable.id, id),
andFilterWithCompare(CategoryTable.order, order),
andFilterWithCompareString(CategoryTable.name, name),
andFilterWithCompare(CategoryTable.isDefault, default)
andFilterWithCompare(CategoryTable.isDefault, default),
)
}
}
@@ -126,55 +131,56 @@ class CategoryQuery {
after: Cursor? = null,
first: Int? = null,
last: Int? = null,
offset: Int? = null
offset: Int? = null,
): CategoryNodeList {
val queryResults = transaction {
val res = CategoryTable.selectAll()
val queryResults =
transaction {
val res = CategoryTable.selectAll()
res.applyOps(condition, filter)
res.applyOps(condition, filter)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: CategoryTable.id
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: CategoryTable.id
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy == CategoryOrderBy.ID || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
CategoryTable.id to SortOrder.ASC
)
}
}
val total = res.count()
val firstResult = res.firstOrNull()?.get(CategoryTable.id)?.value
val lastResult = res.lastOrNull()?.get(CategoryTable.id)?.value
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).greater(after)
if (orderBy == CategoryOrderBy.ID || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
CategoryTable.id to SortOrder.ASC,
)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).less(before)
val total = res.count()
val firstResult = res.firstOrNull()?.get(CategoryTable.id)?.value
val lastResult = res.lastOrNull()?.get(CategoryTable.id)?.value
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).greater(after)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: CategoryOrderBy.ID).less(before)
}
}
}
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
QueryResults(total, firstResult, lastResult, res.toList())
}
QueryResults(total, firstResult, lastResult, res.toList())
}
val getAsCursor: (CategoryType) -> Cursor = (orderBy ?: CategoryOrderBy.ID)::asCursor
@@ -189,24 +195,25 @@ class CategoryQuery {
resultsAsType.firstOrNull()?.let {
CategoryNodeList.CategoryEdge(
getAsCursor(it),
it
it,
)
},
resultsAsType.lastOrNull()?.let {
CategoryNodeList.CategoryEdge(
getAsCursor(it),
it
it,
)
}
},
)
},
pageInfo = PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.id,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.id,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) }
),
totalCount = queryResults.total.toInt()
pageInfo =
PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.id,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.id,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) },
),
totalCount = queryResults.total.toInt(),
)
}
}

View File

@@ -55,7 +55,10 @@ import java.util.concurrent.CompletableFuture
* - Get page list?
*/
class ChapterQuery {
fun chapter(dataFetchingEnvironment: DataFetchingEnvironment, id: Int): CompletableFuture<ChapterType> {
fun chapter(
dataFetchingEnvironment: DataFetchingEnvironment,
id: Int,
): CompletableFuture<ChapterType> {
return dataFetchingEnvironment.getValueFromDataLoader("ChapterDataLoader", id)
}
@@ -66,7 +69,8 @@ class ChapterQuery {
UPLOAD_DATE(ChapterTable.date_upload),
CHAPTER_NUMBER(ChapterTable.chapter_number),
LAST_READ_AT(ChapterTable.lastReadAt),
FETCHED_AT(ChapterTable.fetchedAt);
FETCHED_AT(ChapterTable.fetchedAt),
;
override fun greater(cursor: Cursor): Op<Boolean> {
return when (this) {
@@ -93,15 +97,16 @@ class ChapterQuery {
}
override fun asCursor(type: ChapterType): Cursor {
val value = when (this) {
ID -> type.id.toString()
SOURCE_ORDER -> type.id.toString() + "-" + type.sourceOrder
NAME -> type.id.toString() + "-" + type.name
UPLOAD_DATE -> type.id.toString() + "-" + type.uploadDate
CHAPTER_NUMBER -> type.id.toString() + "-" + type.chapterNumber
LAST_READ_AT -> type.id.toString() + "-" + type.lastReadAt
FETCHED_AT -> type.id.toString() + "-" + type.fetchedAt
}
val value =
when (this) {
ID -> type.id.toString()
SOURCE_ORDER -> type.id.toString() + "-" + type.sourceOrder
NAME -> type.id.toString() + "-" + type.name
UPLOAD_DATE -> type.id.toString() + "-" + type.uploadDate
CHAPTER_NUMBER -> type.id.toString() + "-" + type.chapterNumber
LAST_READ_AT -> type.id.toString() + "-" + type.lastReadAt
FETCHED_AT -> type.id.toString() + "-" + type.fetchedAt
}
return Cursor(value)
}
}
@@ -122,7 +127,7 @@ class ChapterQuery {
val realUrl: String? = null,
val fetchedAt: Long? = null,
val isDownloaded: Boolean? = null,
val pageCount: Int? = null
val pageCount: Int? = null,
) : HasGetOp {
override fun getOp(): Op<Boolean>? {
val opAnd = OpAnd()
@@ -167,7 +172,7 @@ class ChapterQuery {
val inLibrary: BooleanFilter? = null,
override val and: List<ChapterFilter>? = null,
override val or: List<ChapterFilter>? = null,
override val not: ChapterFilter? = null
override val not: ChapterFilter? = null,
) : Filter<ChapterFilter> {
override fun getOpList(): List<Op<Boolean>> {
return listOfNotNull(
@@ -186,7 +191,7 @@ class ChapterQuery {
andFilterWithCompareString(ChapterTable.realUrl, realUrl),
andFilterWithCompare(ChapterTable.fetchedAt, fetchedAt),
andFilterWithCompare(ChapterTable.isDownloaded, isDownloaded),
andFilterWithCompare(ChapterTable.pageCount, pageCount)
andFilterWithCompare(ChapterTable.pageCount, pageCount),
)
}
@@ -202,63 +207,64 @@ class ChapterQuery {
after: Cursor? = null,
first: Int? = null,
last: Int? = null,
offset: Int? = null
offset: Int? = null,
): ChapterNodeList {
val queryResults = transaction {
val res = ChapterTable.selectAll()
val queryResults =
transaction {
val res = ChapterTable.selectAll()
val libraryOp = filter?.getLibraryOp()
if (libraryOp != null) {
res.adjustColumnSet {
innerJoin(MangaTable)
val libraryOp = filter?.getLibraryOp()
if (libraryOp != null) {
res.adjustColumnSet {
innerJoin(MangaTable)
}
res.andWhere { libraryOp }
}
res.andWhere { libraryOp }
}
res.applyOps(condition, filter)
res.applyOps(condition, filter)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: ChapterTable.id
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: ChapterTable.id
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy == ChapterOrderBy.ID || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
ChapterTable.id to SortOrder.ASC
)
}
}
val total = res.count()
val firstResult = res.firstOrNull()?.get(ChapterTable.id)?.value
val lastResult = res.lastOrNull()?.get(ChapterTable.id)?.value
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ID).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ID).greater(after)
if (orderBy == ChapterOrderBy.ID || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
ChapterTable.id to SortOrder.ASC,
)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ID).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ID).less(before)
val total = res.count()
val firstResult = res.firstOrNull()?.get(ChapterTable.id)?.value
val lastResult = res.lastOrNull()?.get(ChapterTable.id)?.value
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ID).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ID).greater(after)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ID).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ID).less(before)
}
}
}
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
QueryResults(total, firstResult, lastResult, res.toList())
}
QueryResults(total, firstResult, lastResult, res.toList())
}
val getAsCursor: (ChapterType) -> Cursor = (orderBy ?: ChapterOrderBy.ID)::asCursor
@@ -273,24 +279,25 @@ class ChapterQuery {
resultsAsType.firstOrNull()?.let {
ChapterNodeList.ChapterEdge(
getAsCursor(it),
it
it,
)
},
resultsAsType.lastOrNull()?.let {
ChapterNodeList.ChapterEdge(
getAsCursor(it),
it
it,
)
}
},
)
},
pageInfo = PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.id,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.id,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) }
),
totalCount = queryResults.total.toInt()
pageInfo =
PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.id,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.id,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) },
),
totalCount = queryResults.total.toInt(),
)
}
}

View File

@@ -7,7 +7,6 @@ import suwayomi.tachidesk.server.JavalinSetup.future
import java.util.concurrent.CompletableFuture
class DownloadQuery {
fun downloadStatus(): CompletableFuture<DownloadStatus> {
return future {
DownloadStatus(DownloadManager.status.first())

View File

@@ -47,14 +47,18 @@ import suwayomi.tachidesk.manga.model.table.ExtensionTable
import java.util.concurrent.CompletableFuture
class ExtensionQuery {
fun extension(dataFetchingEnvironment: DataFetchingEnvironment, pkgName: String): CompletableFuture<ExtensionType> {
fun extension(
dataFetchingEnvironment: DataFetchingEnvironment,
pkgName: String,
): CompletableFuture<ExtensionType> {
return dataFetchingEnvironment.getValueFromDataLoader("ExtensionDataLoader", pkgName)
}
enum class ExtensionOrderBy(override val column: Column<out Comparable<*>>) : OrderBy<ExtensionType> {
PKG_NAME(ExtensionTable.pkgName),
NAME(ExtensionTable.name),
APK_NAME(ExtensionTable.apkName);
APK_NAME(ExtensionTable.apkName),
;
override fun greater(cursor: Cursor): Op<Boolean> {
return when (this) {
@@ -73,11 +77,12 @@ class ExtensionQuery {
}
override fun asCursor(type: ExtensionType): Cursor {
val value = when (this) {
PKG_NAME -> type.pkgName
NAME -> type.pkgName + "\\-" + type.name
APK_NAME -> type.pkgName + "\\-" + type.apkName
}
val value =
when (this) {
PKG_NAME -> type.pkgName
NAME -> type.pkgName + "\\-" + type.name
APK_NAME -> type.pkgName + "\\-" + type.apkName
}
return Cursor(value)
}
}
@@ -93,7 +98,7 @@ class ExtensionQuery {
val isNsfw: Boolean? = null,
val isInstalled: Boolean? = null,
val hasUpdate: Boolean? = null,
val isObsolete: Boolean? = null
val isObsolete: Boolean? = null,
) : HasGetOp {
override fun getOp(): Op<Boolean>? {
val opAnd = OpAnd()
@@ -126,7 +131,7 @@ class ExtensionQuery {
val isObsolete: BooleanFilter? = null,
override val and: List<ExtensionFilter>? = null,
override val or: List<ExtensionFilter>? = null,
override val not: ExtensionFilter? = null
override val not: ExtensionFilter? = null,
) : Filter<ExtensionFilter> {
override fun getOpList(): List<Op<Boolean>> {
return listOfNotNull(
@@ -140,7 +145,7 @@ class ExtensionQuery {
andFilterWithCompare(ExtensionTable.isNsfw, isNsfw),
andFilterWithCompare(ExtensionTable.isInstalled, isInstalled),
andFilterWithCompare(ExtensionTable.hasUpdate, hasUpdate),
andFilterWithCompare(ExtensionTable.isObsolete, isObsolete)
andFilterWithCompare(ExtensionTable.isObsolete, isObsolete),
)
}
}
@@ -154,57 +159,58 @@ class ExtensionQuery {
after: Cursor? = null,
first: Int? = null,
last: Int? = null,
offset: Int? = null
offset: Int? = null,
): ExtensionNodeList {
val queryResults = transaction {
val res = ExtensionTable.selectAll()
val queryResults =
transaction {
val res = ExtensionTable.selectAll()
res.adjustWhere { ExtensionTable.name neq LocalSource.EXTENSION_NAME }
res.adjustWhere { ExtensionTable.name neq LocalSource.EXTENSION_NAME }
res.applyOps(condition, filter)
res.applyOps(condition, filter)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: ExtensionTable.pkgName
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: ExtensionTable.pkgName
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy == ExtensionOrderBy.PKG_NAME || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
ExtensionTable.pkgName to SortOrder.ASC
)
}
}
val total = res.count()
val firstResult = res.firstOrNull()?.get(ExtensionTable.pkgName)
val lastResult = res.lastOrNull()?.get(ExtensionTable.pkgName)
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).greater(after)
if (orderBy == ExtensionOrderBy.PKG_NAME || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
ExtensionTable.pkgName to SortOrder.ASC,
)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).less(before)
val total = res.count()
val firstResult = res.firstOrNull()?.get(ExtensionTable.pkgName)
val lastResult = res.lastOrNull()?.get(ExtensionTable.pkgName)
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).greater(after)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: ExtensionOrderBy.PKG_NAME).less(before)
}
}
}
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
QueryResults(total, firstResult, lastResult, res.toList())
}
QueryResults(total, firstResult, lastResult, res.toList())
}
val getAsCursor: (ExtensionType) -> Cursor = (orderBy ?: ExtensionOrderBy.PKG_NAME)::asCursor
@@ -219,24 +225,25 @@ class ExtensionQuery {
resultsAsType.firstOrNull()?.let {
ExtensionNodeList.ExtensionEdge(
getAsCursor(it),
it
it,
)
},
resultsAsType.lastOrNull()?.let {
ExtensionNodeList.ExtensionEdge(
getAsCursor(it),
it
it,
)
}
},
)
},
pageInfo = PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.pkgName,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.pkgName,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) }
),
totalCount = queryResults.total.toInt()
pageInfo =
PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.pkgName,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.pkgName,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) },
),
totalCount = queryResults.total.toInt(),
)
}
}

View File

@@ -3,8 +3,8 @@ package suwayomi.tachidesk.graphql.queries
import suwayomi.tachidesk.global.impl.AppUpdate
import suwayomi.tachidesk.graphql.types.WebUIUpdateInfo
import suwayomi.tachidesk.graphql.types.WebUIUpdateStatus
import suwayomi.tachidesk.server.BuildConfig
import suwayomi.tachidesk.server.JavalinSetup.future
import suwayomi.tachidesk.server.generated.BuildConfig
import suwayomi.tachidesk.server.serverConfig
import suwayomi.tachidesk.server.util.WebInterfaceManager
import java.util.concurrent.CompletableFuture
@@ -17,7 +17,7 @@ class InfoQuery {
val buildType: String,
val buildTime: Long,
val github: String,
val discord: String
val discord: String,
)
fun about(): AboutPayload {
@@ -28,7 +28,7 @@ class InfoQuery {
BuildConfig.BUILD_TYPE,
BuildConfig.BUILD_TIME,
BuildConfig.GITHUB,
BuildConfig.DISCORD
BuildConfig.DISCORD,
)
}
@@ -36,7 +36,7 @@ class InfoQuery {
/** [channel] mirrors [suwayomi.tachidesk.server.BuildConfig.BUILD_TYPE] */
val channel: String,
val tag: String,
val url: String
val url: String,
)
fun checkForServerUpdates(): CompletableFuture<List<CheckForServerUpdatesPayload>> {
@@ -45,7 +45,7 @@ class InfoQuery {
CheckForServerUpdatesPayload(
channel = it.channel,
tag = it.tag,
url = it.url
url = it.url,
)
}
}
@@ -57,7 +57,7 @@ class InfoQuery {
WebUIUpdateInfo(
channel = serverConfig.webUIChannel.value,
tag = version,
updateAvailable
updateAvailable,
)
}
}

View File

@@ -49,7 +49,10 @@ import suwayomi.tachidesk.manga.model.table.MangaTable
import java.util.concurrent.CompletableFuture
class MangaQuery {
fun manga(dataFetchingEnvironment: DataFetchingEnvironment, id: Int): CompletableFuture<MangaType> {
fun manga(
dataFetchingEnvironment: DataFetchingEnvironment,
id: Int,
): CompletableFuture<MangaType> {
return dataFetchingEnvironment.getValueFromDataLoader("MangaDataLoader", id)
}
@@ -57,7 +60,8 @@ class MangaQuery {
ID(MangaTable.id),
TITLE(MangaTable.title),
IN_LIBRARY_AT(MangaTable.inLibraryAt),
LAST_FETCHED_AT(MangaTable.lastFetchedAt);
LAST_FETCHED_AT(MangaTable.lastFetchedAt),
;
override fun greater(cursor: Cursor): Op<Boolean> {
return when (this) {
@@ -78,12 +82,13 @@ class MangaQuery {
}
override fun asCursor(type: MangaType): Cursor {
val value = when (this) {
ID -> type.id.toString()
TITLE -> type.id.toString() + "-" + type.title
IN_LIBRARY_AT -> type.id.toString() + "-" + type.inLibraryAt.toString()
LAST_FETCHED_AT -> type.id.toString() + "-" + type.lastFetchedAt.toString()
}
val value =
when (this) {
ID -> type.id.toString()
TITLE -> type.id.toString() + "-" + type.title
IN_LIBRARY_AT -> type.id.toString() + "-" + type.inLibraryAt.toString()
LAST_FETCHED_AT -> type.id.toString() + "-" + type.lastFetchedAt.toString()
}
return Cursor(value)
}
}
@@ -104,7 +109,7 @@ class MangaQuery {
val inLibraryAt: Long? = null,
val realUrl: String? = null,
val lastFetchedAt: Long? = null,
val chaptersLastFetchedAt: Long? = null
val chaptersLastFetchedAt: Long? = null,
) : HasGetOp {
override fun getOp(): Op<Boolean>? {
val opAnd = OpAnd()
@@ -140,21 +145,21 @@ class MangaQuery {
override val lessThan: MangaStatus? = null,
override val lessThanOrEqualTo: MangaStatus? = null,
override val greaterThan: MangaStatus? = null,
override val greaterThanOrEqualTo: MangaStatus? = null
override val greaterThanOrEqualTo: MangaStatus? = null,
) : ComparableScalarFilter<MangaStatus> {
fun asIntFilter() = IntFilter(
equalTo = equalTo?.value,
notEqualTo = notEqualTo?.value,
distinctFrom = distinctFrom?.value,
notDistinctFrom = notDistinctFrom?.value,
`in` = `in`?.map { it.value },
notIn = notIn?.map { it.value },
lessThan = lessThan?.value,
lessThanOrEqualTo = lessThanOrEqualTo?.value,
greaterThan = greaterThan?.value,
greaterThanOrEqualTo = greaterThanOrEqualTo?.value
)
fun asIntFilter() =
IntFilter(
equalTo = equalTo?.value,
notEqualTo = notEqualTo?.value,
distinctFrom = distinctFrom?.value,
notDistinctFrom = notDistinctFrom?.value,
`in` = `in`?.map { it.value },
notIn = notIn?.map { it.value },
lessThan = lessThan?.value,
lessThanOrEqualTo = lessThanOrEqualTo?.value,
greaterThan = greaterThan?.value,
greaterThanOrEqualTo = greaterThanOrEqualTo?.value,
)
}
data class MangaFilter(
@@ -176,7 +181,7 @@ class MangaQuery {
val chaptersLastFetchedAt: LongFilter? = null,
override val and: List<MangaFilter>? = null,
override val or: List<MangaFilter>? = null,
override val not: MangaFilter? = null
override val not: MangaFilter? = null,
) : Filter<MangaFilter> {
override fun getOpList(): List<Op<Boolean>> {
return listOfNotNull(
@@ -194,7 +199,7 @@ class MangaQuery {
andFilterWithCompare(MangaTable.inLibraryAt, inLibraryAt),
andFilterWithCompareString(MangaTable.realUrl, realUrl),
andFilterWithCompare(MangaTable.lastFetchedAt, lastFetchedAt),
andFilterWithCompare(MangaTable.chaptersLastFetchedAt, chaptersLastFetchedAt)
andFilterWithCompare(MangaTable.chaptersLastFetchedAt, chaptersLastFetchedAt),
)
}
}
@@ -208,55 +213,56 @@ class MangaQuery {
after: Cursor? = null,
first: Int? = null,
last: Int? = null,
offset: Int? = null
offset: Int? = null,
): MangaNodeList {
val queryResults = transaction {
val res = MangaTable.selectAll()
val queryResults =
transaction {
val res = MangaTable.selectAll()
res.applyOps(condition, filter)
res.applyOps(condition, filter)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: MangaTable.id
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: MangaTable.id
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy == MangaOrderBy.ID || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
MangaTable.id to SortOrder.ASC
)
}
}
val total = res.count()
val firstResult = res.firstOrNull()?.get(MangaTable.id)?.value
val lastResult = res.lastOrNull()?.get(MangaTable.id)?.value
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).greater(after)
if (orderBy == MangaOrderBy.ID || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
MangaTable.id to SortOrder.ASC,
)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).less(before)
val total = res.count()
val firstResult = res.firstOrNull()?.get(MangaTable.id)?.value
val lastResult = res.lastOrNull()?.get(MangaTable.id)?.value
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).greater(after)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MangaOrderBy.ID).less(before)
}
}
}
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
QueryResults(total, firstResult, lastResult, res.toList())
}
QueryResults(total, firstResult, lastResult, res.toList())
}
val getAsCursor: (MangaType) -> Cursor = (orderBy ?: MangaOrderBy.ID)::asCursor
@@ -271,24 +277,25 @@ class MangaQuery {
resultsAsType.firstOrNull()?.let {
MangaNodeList.MangaEdge(
getAsCursor(it),
it
it,
)
},
resultsAsType.lastOrNull()?.let {
MangaNodeList.MangaEdge(
getAsCursor(it),
it
it,
)
}
},
)
},
pageInfo = PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.id,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.id,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) }
),
totalCount = queryResults.total.toInt()
pageInfo =
PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.id,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.id,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) },
),
totalCount = queryResults.total.toInt(),
)
}
}

View File

@@ -42,13 +42,17 @@ import suwayomi.tachidesk.graphql.types.GlobalMetaType
import java.util.concurrent.CompletableFuture
class MetaQuery {
fun meta(dataFetchingEnvironment: DataFetchingEnvironment, key: String): CompletableFuture<GlobalMetaType> {
fun meta(
dataFetchingEnvironment: DataFetchingEnvironment,
key: String,
): CompletableFuture<GlobalMetaType> {
return dataFetchingEnvironment.getValueFromDataLoader("GlobalMetaDataLoader", key)
}
enum class MetaOrderBy(override val column: Column<out Comparable<*>>) : OrderBy<GlobalMetaType> {
KEY(GlobalMetaTable.key),
VALUE(GlobalMetaTable.value);
VALUE(GlobalMetaTable.value),
;
override fun greater(cursor: Cursor): Op<Boolean> {
return when (this) {
@@ -65,17 +69,18 @@ class MetaQuery {
}
override fun asCursor(type: GlobalMetaType): Cursor {
val value = when (this) {
KEY -> type.key
VALUE -> type.key + "\\-" + type.value
}
val value =
when (this) {
KEY -> type.key
VALUE -> type.key + "\\-" + type.value
}
return Cursor(value)
}
}
data class MetaCondition(
val key: String? = null,
val value: String? = null
val value: String? = null,
) : HasGetOp {
override fun getOp(): Op<Boolean>? {
val opAnd = OpAnd()
@@ -91,12 +96,12 @@ class MetaQuery {
val value: StringFilter? = null,
override val and: List<MetaFilter>? = null,
override val or: List<MetaFilter>? = null,
override val not: MetaFilter? = null
override val not: MetaFilter? = null,
) : Filter<MetaFilter> {
override fun getOpList(): List<Op<Boolean>> {
return listOfNotNull(
andFilterWithCompareString(GlobalMetaTable.key, key),
andFilterWithCompareString(GlobalMetaTable.value, value)
andFilterWithCompareString(GlobalMetaTable.value, value),
)
}
}
@@ -110,55 +115,56 @@ class MetaQuery {
after: Cursor? = null,
first: Int? = null,
last: Int? = null,
offset: Int? = null
offset: Int? = null,
): GlobalMetaNodeList {
val queryResults = transaction {
val res = GlobalMetaTable.selectAll()
val queryResults =
transaction {
val res = GlobalMetaTable.selectAll()
res.applyOps(condition, filter)
res.applyOps(condition, filter)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: GlobalMetaTable.key
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: GlobalMetaTable.key
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy == MetaOrderBy.KEY || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
GlobalMetaTable.key to SortOrder.ASC
)
}
}
val total = res.count()
val firstResult = res.firstOrNull()?.get(GlobalMetaTable.key)
val lastResult = res.lastOrNull()?.get(GlobalMetaTable.key)
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).greater(after)
if (orderBy == MetaOrderBy.KEY || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
GlobalMetaTable.key to SortOrder.ASC,
)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).less(before)
val total = res.count()
val firstResult = res.firstOrNull()?.get(GlobalMetaTable.key)
val lastResult = res.lastOrNull()?.get(GlobalMetaTable.key)
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).greater(after)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: MetaOrderBy.KEY).less(before)
}
}
}
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
QueryResults(total, firstResult, lastResult, res.toList())
}
QueryResults(total, firstResult, lastResult, res.toList())
}
val getAsCursor: (GlobalMetaType) -> Cursor = (orderBy ?: MetaOrderBy.KEY)::asCursor
@@ -173,24 +179,25 @@ class MetaQuery {
resultsAsType.firstOrNull()?.let {
GlobalMetaNodeList.MetaEdge(
getAsCursor(it),
it
it,
)
},
resultsAsType.lastOrNull()?.let {
GlobalMetaNodeList.MetaEdge(
getAsCursor(it),
it
it,
)
}
},
)
},
pageInfo = PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.key,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.key,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) }
),
totalCount = queryResults.total.toInt()
pageInfo =
PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.key,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.key,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) },
),
totalCount = queryResults.total.toInt(),
)
}
}

View File

@@ -46,14 +46,18 @@ import suwayomi.tachidesk.manga.model.table.SourceTable
import java.util.concurrent.CompletableFuture
class SourceQuery {
fun source(dataFetchingEnvironment: DataFetchingEnvironment, id: Long): CompletableFuture<SourceType> {
fun source(
dataFetchingEnvironment: DataFetchingEnvironment,
id: Long,
): CompletableFuture<SourceType> {
return dataFetchingEnvironment.getValueFromDataLoader("SourceDataLoader", id)
}
enum class SourceOrderBy(override val column: Column<out Comparable<*>>) : OrderBy<SourceType> {
ID(SourceTable.id),
NAME(SourceTable.name),
LANG(SourceTable.lang);
LANG(SourceTable.lang),
;
override fun greater(cursor: Cursor): Op<Boolean> {
return when (this) {
@@ -72,11 +76,12 @@ class SourceQuery {
}
override fun asCursor(type: SourceType): Cursor {
val value = when (this) {
ID -> type.id.toString()
NAME -> type.id.toString() + "-" + type.name
LANG -> type.id.toString() + "-" + type.lang
}
val value =
when (this) {
ID -> type.id.toString()
NAME -> type.id.toString() + "-" + type.name
LANG -> type.id.toString() + "-" + type.lang
}
return Cursor(value)
}
}
@@ -85,7 +90,7 @@ class SourceQuery {
val id: Long? = null,
val name: String? = null,
val lang: String? = null,
val isNsfw: Boolean? = null
val isNsfw: Boolean? = null,
) : HasGetOp {
override fun getOp(): Op<Boolean>? {
val opAnd = OpAnd()
@@ -105,14 +110,14 @@ class SourceQuery {
val isNsfw: BooleanFilter? = null,
override val and: List<SourceFilter>? = null,
override val or: List<SourceFilter>? = null,
override val not: SourceFilter? = null
override val not: SourceFilter? = null,
) : Filter<SourceFilter> {
override fun getOpList(): List<Op<Boolean>> {
return listOfNotNull(
andFilterWithCompareEntity(SourceTable.id, id),
andFilterWithCompareString(SourceTable.name, name),
andFilterWithCompareString(SourceTable.lang, lang),
andFilterWithCompare(SourceTable.isNsfw, isNsfw)
andFilterWithCompare(SourceTable.isNsfw, isNsfw),
)
}
}
@@ -126,57 +131,58 @@ class SourceQuery {
after: Cursor? = null,
first: Int? = null,
last: Int? = null,
offset: Int? = null
offset: Int? = null,
): SourceNodeList {
val (queryResults, resultsAsType) = transaction {
val res = SourceTable.selectAll()
val (queryResults, resultsAsType) =
transaction {
val res = SourceTable.selectAll()
res.applyOps(condition, filter)
res.applyOps(condition, filter)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: SourceTable.id
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy != null || (last != null || before != null)) {
val orderByColumn = orderBy?.column ?: SourceTable.id
val orderType = orderByType.maybeSwap(last ?: before)
if (orderBy == SourceOrderBy.ID || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
SourceTable.id to SortOrder.ASC
)
}
}
val total = res.count()
val firstResult = res.firstOrNull()?.get(SourceTable.id)?.value
val lastResult = res.lastOrNull()?.get(SourceTable.id)?.value
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).greater(after)
if (orderBy == SourceOrderBy.ID || orderBy == null) {
res.orderBy(orderByColumn to orderType)
} else {
res.orderBy(
orderByColumn to orderType,
SourceTable.id to SortOrder.ASC,
)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).less(before)
val total = res.count()
val firstResult = res.firstOrNull()?.get(SourceTable.id)?.value
val lastResult = res.lastOrNull()?.get(SourceTable.id)?.value
if (after != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).less(after)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).greater(after)
}
}
} else if (before != null) {
res.andWhere {
when (orderByType) {
DESC, DESC_NULLS_FIRST, DESC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).greater(before)
null, ASC, ASC_NULLS_FIRST, ASC_NULLS_LAST -> (orderBy ?: SourceOrderBy.ID).less(before)
}
}
}
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
if (first != null) {
res.limit(first, offset?.toLong() ?: 0)
} else if (last != null) {
res.limit(last)
}
QueryResults(total, firstResult, lastResult, res.toList()).let {
it to it.results.mapNotNull { SourceType(it) }
QueryResults(total, firstResult, lastResult, res.toList()).let {
it to it.results.mapNotNull { SourceType(it) }
}
}
}
val getAsCursor: (SourceType) -> Cursor = (orderBy ?: SourceOrderBy.ID)::asCursor
@@ -189,24 +195,25 @@ class SourceQuery {
resultsAsType.firstOrNull()?.let {
SourceNodeList.SourceEdge(
getAsCursor(it),
it
it,
)
},
resultsAsType.lastOrNull()?.let {
SourceNodeList.SourceEdge(
getAsCursor(it),
it
it,
)
}
},
)
},
pageInfo = PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.id,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.id,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) }
),
totalCount = queryResults.total.toInt()
pageInfo =
PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.lastOrNull()?.id,
hasPreviousPage = queryResults.firstKey != resultsAsType.firstOrNull()?.id,
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(it) },
),
totalCount = queryResults.total.toInt(),
)
}
}

View File

@@ -17,7 +17,11 @@ import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.stringParam
import org.jetbrains.exposed.sql.upperCase
class ILikeEscapeOp(expr1: Expression<*>, expr2: Expression<*>, like: Boolean, val escapeChar: Char?) : ComparisonOp(expr1, expr2, if (like) "ILIKE" else "NOT ILIKE") {
class ILikeEscapeOp(expr1: Expression<*>, expr2: Expression<*>, like: Boolean, val escapeChar: Char?) : ComparisonOp(
expr1,
expr2,
if (like) "ILIKE" else "NOT ILIKE",
) {
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
super.toQueryBuilder(queryBuilder)
if (escapeChar != null) {
@@ -29,43 +33,93 @@ class ILikeEscapeOp(expr1: Expression<*>, expr2: Expression<*>, like: Boolean, v
}
companion object {
fun <T : String?> iLike(expression: Expression<T>, pattern: String): ILikeEscapeOp = iLike(expression, LikePattern(pattern))
fun <T : String?> iNotLike(expression: Expression<T>, pattern: String): ILikeEscapeOp = iNotLike(expression, LikePattern(pattern))
fun <T : String?> iLike(expression: Expression<T>, pattern: LikePattern): ILikeEscapeOp = ILikeEscapeOp(expression, stringParam(pattern.pattern), true, pattern.escapeChar)
fun <T : String?> iNotLike(expression: Expression<T>, pattern: LikePattern): ILikeEscapeOp = ILikeEscapeOp(expression, stringParam(pattern.pattern), false, pattern.escapeChar)
fun <T : String?> iLike(
expression: Expression<T>,
pattern: String,
): ILikeEscapeOp = iLike(expression, LikePattern(pattern))
fun <T : String?> iNotLike(
expression: Expression<T>,
pattern: String,
): ILikeEscapeOp = iNotLike(expression, LikePattern(pattern))
fun <T : String?> iLike(
expression: Expression<T>,
pattern: LikePattern,
): ILikeEscapeOp =
ILikeEscapeOp(
expression,
stringParam(pattern.pattern),
true,
pattern.escapeChar,
)
fun <T : String?> iNotLike(
expression: Expression<T>,
pattern: LikePattern,
): ILikeEscapeOp =
ILikeEscapeOp(
expression,
stringParam(pattern.pattern),
false,
pattern.escapeChar,
)
}
}
class DistinctFromOp(expr1: Expression<*>, expr2: Expression<*>, not: Boolean) : ComparisonOp(expr1, expr2, if (not) "IS NOT DISTINCT FROM" else "IS DISTINCT FROM") {
class DistinctFromOp(expr1: Expression<*>, expr2: Expression<*>, not: Boolean) : ComparisonOp(
expr1,
expr2,
if (not) "IS NOT DISTINCT FROM" else "IS DISTINCT FROM",
) {
companion object {
fun <T> distinctFrom(expression: ExpressionWithColumnType<T>, t: T): DistinctFromOp = DistinctFromOp(
expression,
with(SqlExpressionBuilder) {
expression.wrap(t)
},
false
)
fun <T> notDistinctFrom(expression: ExpressionWithColumnType<T>, t: T): DistinctFromOp = DistinctFromOp(
expression,
with(SqlExpressionBuilder) {
expression.wrap(t)
},
true
)
fun <T : Comparable<T>> distinctFrom(expression: ExpressionWithColumnType<EntityID<T>>, t: T): DistinctFromOp = DistinctFromOp(
expression,
with(SqlExpressionBuilder) {
expression.wrap(t)
},
false
)
fun <T : Comparable<T>> notDistinctFrom(expression: ExpressionWithColumnType<EntityID<T>>, t: T): DistinctFromOp = DistinctFromOp(
expression,
with(SqlExpressionBuilder) {
expression.wrap(t)
},
true
)
fun <T> distinctFrom(
expression: ExpressionWithColumnType<T>,
t: T,
): DistinctFromOp =
DistinctFromOp(
expression,
with(SqlExpressionBuilder) {
expression.wrap(t)
},
false,
)
fun <T> notDistinctFrom(
expression: ExpressionWithColumnType<T>,
t: T,
): DistinctFromOp =
DistinctFromOp(
expression,
with(SqlExpressionBuilder) {
expression.wrap(t)
},
true,
)
fun <T : Comparable<T>> distinctFrom(
expression: ExpressionWithColumnType<EntityID<T>>,
t: T,
): DistinctFromOp =
DistinctFromOp(
expression,
with(SqlExpressionBuilder) {
expression.wrap(t)
},
false,
)
fun <T : Comparable<T>> notDistinctFrom(
expression: ExpressionWithColumnType<EntityID<T>>,
t: T,
): DistinctFromOp =
DistinctFromOp(
expression,
with(SqlExpressionBuilder) {
expression.wrap(t)
},
true,
)
}
}
@@ -88,9 +142,10 @@ interface Filter<T : Filter<T>> : HasGetOp {
override fun getOp(): Op<Boolean>? {
var op: Op<Boolean>? = null
fun newOp(
otherOp: Op<Boolean>?,
operator: (Op<Boolean>, Op<Boolean>) -> Op<Boolean>
operator: (Op<Boolean>, Op<Boolean>) -> Op<Boolean>,
) {
when {
op == null && otherOp == null -> Unit
@@ -99,9 +154,11 @@ interface Filter<T : Filter<T>> : HasGetOp {
op != null && otherOp != null -> op = operator(op!!, otherOp)
}
}
fun andOp(andOp: Op<Boolean>?) {
newOp(andOp, Op<Boolean>::and)
}
fun orOp(orOp: Op<Boolean>?) {
newOp(orOp, Op<Boolean>::or)
}
@@ -127,6 +184,8 @@ interface ScalarFilter<T> {
val notEqualTo: T?
val distinctFrom: T?
val notDistinctFrom: T?
@Suppress("ktlint:standard:property-naming")
val `in`: List<T>?
val notIn: List<T>?
}
@@ -155,7 +214,7 @@ data class LongFilter(
override val lessThan: Long? = null,
override val lessThanOrEqualTo: Long? = null,
override val greaterThan: Long? = null,
override val greaterThanOrEqualTo: Long? = null
override val greaterThanOrEqualTo: Long? = null,
) : ComparableScalarFilter<Long>
data class BooleanFilter(
@@ -169,7 +228,7 @@ data class BooleanFilter(
override val lessThan: Boolean? = null,
override val lessThanOrEqualTo: Boolean? = null,
override val greaterThan: Boolean? = null,
override val greaterThanOrEqualTo: Boolean? = null
override val greaterThanOrEqualTo: Boolean? = null,
) : ComparableScalarFilter<Boolean>
data class IntFilter(
@@ -183,7 +242,7 @@ data class IntFilter(
override val lessThan: Int? = null,
override val lessThanOrEqualTo: Int? = null,
override val greaterThan: Int? = null,
override val greaterThanOrEqualTo: Int? = null
override val greaterThanOrEqualTo: Int? = null,
) : ComparableScalarFilter<Int>
data class FloatFilter(
@@ -197,7 +256,7 @@ data class FloatFilter(
override val lessThan: Float? = null,
override val lessThanOrEqualTo: Float? = null,
override val greaterThan: Float? = null,
override val greaterThanOrEqualTo: Float? = null
override val greaterThanOrEqualTo: Float? = null,
) : ComparableScalarFilter<Float>
data class StringFilter(
@@ -235,7 +294,7 @@ data class StringFilter(
val lessThanInsensitive: String? = null,
val lessThanOrEqualToInsensitive: String? = null,
val greaterThanInsensitive: String? = null,
val greaterThanOrEqualToInsensitive: String? = null
val greaterThanOrEqualToInsensitive: String? = null,
) : ComparableScalarFilter<String>
data class StringListFilter(
@@ -251,13 +310,13 @@ data class StringListFilter(
override val hasNone: List<String>? = null,
val hasAnyInsensitive: List<String>? = null,
val hasAllInsensitive: List<String>? = null,
val hasNoneInsensitive: List<String>? = null
val hasNoneInsensitive: List<String>? = null,
) : ListScalarFilter<String, List<String>>
@Suppress("UNCHECKED_CAST")
fun <T : String, S : T?> andFilterWithCompareString(
column: Column<S>,
filter: StringFilter?
filter: StringFilter?,
): Op<Boolean>? {
filter ?: return null
val opAnd = OpAnd()
@@ -314,19 +373,29 @@ fun <T : String, S : T?> andFilterWithCompareString(
}
class OpAnd(var op: Op<Boolean>? = null) {
fun <T> andWhere(value: T?, andPart: SqlExpressionBuilder.(T & Any) -> Op<Boolean>) {
fun <T> andWhere(
value: T?,
andPart: SqlExpressionBuilder.(T & Any) -> Op<Boolean>,
) {
value ?: return
val expr = Op.build { andPart(value) }
op = if (op == null) expr else (op!! and expr)
}
fun <T> eq(value: T?, column: Column<T>) = andWhere(value) { column eq it }
fun <T : Comparable<T>> eq(value: T?, column: Column<EntityID<T>>) = andWhere(value) { column eq it }
fun <T> eq(
value: T?,
column: Column<T>,
) = andWhere(value) { column eq it }
fun <T : Comparable<T>> eq(
value: T?,
column: Column<EntityID<T>>,
) = andWhere(value) { column eq it }
}
fun <T : Comparable<T>> andFilterWithCompare(
column: Column<T>,
filter: ComparableScalarFilter<T>?
filter: ComparableScalarFilter<T>?,
): Op<Boolean>? {
filter ?: return null
val opAnd = OpAnd(andFilter(column, filter))
@@ -341,7 +410,7 @@ fun <T : Comparable<T>> andFilterWithCompare(
fun <T : Comparable<T>> andFilterWithCompareEntity(
column: Column<EntityID<T>>,
filter: ComparableScalarFilter<T>?
filter: ComparableScalarFilter<T>?,
): Op<Boolean>? {
filter ?: return null
val opAnd = OpAnd(andFilterEntity(column, filter))
@@ -356,7 +425,7 @@ fun <T : Comparable<T>> andFilterWithCompareEntity(
fun <T : Comparable<T>> andFilter(
column: Column<T>,
filter: ScalarFilter<T>?
filter: ScalarFilter<T>?,
): Op<Boolean>? {
filter ?: return null
val opAnd = OpAnd()
@@ -377,7 +446,7 @@ fun <T : Comparable<T>> andFilter(
fun <T : Comparable<T>> andFilterEntity(
column: Column<EntityID<T>>,
filter: ScalarFilter<T>?
filter: ScalarFilter<T>?,
): Op<Boolean>? {
filter ?: return null
val opAnd = OpAnd()

View File

@@ -17,36 +17,39 @@ import io.javalin.plugin.json.jsonMapper
import java.io.IOException
class JavalinGraphQLRequestParser : GraphQLRequestParser<Context> {
@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE", "UNCHECKED_CAST")
override suspend fun parseRequest(context: Context): GraphQLServerRequest? {
return try {
val formParam = context.formParam("operations")
?: return context.bodyAsClass(GraphQLServerRequest::class.java)
val formParam =
context.formParam("operations")
?: return context.bodyAsClass(GraphQLServerRequest::class.java)
val request = context.jsonMapper().fromJsonString(
formParam,
GraphQLServerRequest::class.java
)
val map = context.formParam("map")?.let {
val request =
context.jsonMapper().fromJsonString(
it,
Map::class.java as Class<Map<String, List<String>>>
formParam,
GraphQLServerRequest::class.java,
)
}.orEmpty()
val mapItems = map.flatMap { (key, variables) ->
val file = context.uploadedFile(key)
variables.map { fullVariable ->
val variable = fullVariable.removePrefix("variables.").substringBefore('.')
val listIndex = fullVariable.substringAfterLast('.').toIntOrNull()
MapItem(
variable,
listIndex,
file
val map =
context.formParam("map")?.let {
context.jsonMapper().fromJsonString(
it,
Map::class.java as Class<Map<String, List<String>>>,
)
}
}.groupBy { it.variable }
}.orEmpty()
val mapItems =
map.flatMap { (key, variables) ->
val file = context.uploadedFile(key)
variables.map { fullVariable ->
val variable = fullVariable.removePrefix("variables.").substringBefore('.')
val listIndex = fullVariable.substringAfterLast('.').toIntOrNull()
MapItem(
variable,
listIndex,
file,
)
}
}.groupBy { it.variable }
when (request) {
is GraphQLRequest -> {
@@ -54,11 +57,12 @@ class JavalinGraphQLRequestParser : GraphQLRequestParser<Context> {
}
is GraphQLBatchRequest -> {
request.copy(
requests = request.requests.map {
it.copy(
variables = it.variables?.modifyFiles(mapItems)
)
}
requests =
request.requests.map {
it.copy(
variables = it.variables?.modifyFiles(mapItems),
)
},
)
}
}
@@ -70,7 +74,7 @@ class JavalinGraphQLRequestParser : GraphQLRequestParser<Context> {
data class MapItem(
val variable: String,
val listIndex: Int?,
val file: UploadedFile?
val file: UploadedFile?,
)
/**

View File

@@ -52,7 +52,7 @@ class TachideskDataLoaderRegistryFactory {
SourceDataLoader(),
SourcesForExtensionDataLoader(),
ExtensionDataLoader(),
ExtensionForSourceDataLoader()
ExtensionForSourceDataLoader(),
)
}
}

View File

@@ -37,5 +37,4 @@ class TachideskGraphQLContextFactory : GraphQLContextFactory<GraphQLContext, Con
* Create a [GraphQLContext] from [this] map
* @return a new [GraphQLContext]
*/
fun Map<*, Any?>.toGraphQLContext(): graphql.GraphQLContext =
graphql.GraphQLContext.of(this)
fun Map<*, Any?>.toGraphQLContext(): graphql.GraphQLContext = graphql.GraphQLContext.of(this)

View File

@@ -46,49 +46,55 @@ import kotlin.reflect.KClass
import kotlin.reflect.KType
class CustomSchemaGeneratorHooks : FlowSubscriptionSchemaGeneratorHooks() {
override fun willGenerateGraphQLType(type: KType): GraphQLType? = when (type.classifier as? KClass<*>) {
Long::class -> GraphQLLongAsString // encode to string for JS
Cursor::class -> GraphQLCursor
UploadedFile::class -> GraphQLUpload
else -> super.willGenerateGraphQLType(type)
}
override fun willGenerateGraphQLType(type: KType): GraphQLType? =
when (type.classifier as? KClass<*>) {
Long::class -> GraphQLLongAsString // encode to string for JS
Cursor::class -> GraphQLCursor
UploadedFile::class -> GraphQLUpload
else -> super.willGenerateGraphQLType(type)
}
}
val schema = toSchema(
config = SchemaGeneratorConfig(
supportedPackages = listOf("suwayomi.tachidesk.graphql"),
introspectionEnabled = true,
hooks = CustomSchemaGeneratorHooks()
),
queries = listOf(
TopLevelObject(BackupQuery()),
TopLevelObject(CategoryQuery()),
TopLevelObject(ChapterQuery()),
TopLevelObject(DownloadQuery()),
TopLevelObject(ExtensionQuery()),
TopLevelObject(InfoQuery()),
TopLevelObject(MangaQuery()),
TopLevelObject(MetaQuery()),
TopLevelObject(SettingsQuery()),
TopLevelObject(SourceQuery()),
TopLevelObject(UpdateQuery())
),
mutations = listOf(
TopLevelObject(BackupMutation()),
TopLevelObject(CategoryMutation()),
TopLevelObject(ChapterMutation()),
TopLevelObject(DownloadMutation()),
TopLevelObject(ExtensionMutation()),
TopLevelObject(InfoMutation()),
TopLevelObject(MangaMutation()),
TopLevelObject(MetaMutation()),
TopLevelObject(SettingsMutation()),
TopLevelObject(SourceMutation()),
TopLevelObject(UpdateMutation())
),
subscriptions = listOf(
TopLevelObject(DownloadSubscription()),
TopLevelObject(InfoSubscription()),
TopLevelObject(UpdateSubscription())
val schema =
toSchema(
config =
SchemaGeneratorConfig(
supportedPackages = listOf("suwayomi.tachidesk.graphql"),
introspectionEnabled = true,
hooks = CustomSchemaGeneratorHooks(),
),
queries =
listOf(
TopLevelObject(BackupQuery()),
TopLevelObject(CategoryQuery()),
TopLevelObject(ChapterQuery()),
TopLevelObject(DownloadQuery()),
TopLevelObject(ExtensionQuery()),
TopLevelObject(InfoQuery()),
TopLevelObject(MangaQuery()),
TopLevelObject(MetaQuery()),
TopLevelObject(SettingsQuery()),
TopLevelObject(SourceQuery()),
TopLevelObject(UpdateQuery()),
),
mutations =
listOf(
TopLevelObject(BackupMutation()),
TopLevelObject(CategoryMutation()),
TopLevelObject(ChapterMutation()),
TopLevelObject(DownloadMutation()),
TopLevelObject(ExtensionMutation()),
TopLevelObject(InfoMutation()),
TopLevelObject(MangaMutation()),
TopLevelObject(MetaMutation()),
TopLevelObject(SettingsMutation()),
TopLevelObject(SourceMutation()),
TopLevelObject(UpdateMutation()),
),
subscriptions =
listOf(
TopLevelObject(DownloadSubscription()),
TopLevelObject(InfoSubscription()),
TopLevelObject(UpdateSubscription()),
),
)
)

View File

@@ -25,7 +25,7 @@ class TachideskGraphQLServer(
requestParser: JavalinGraphQLRequestParser,
contextFactory: TachideskGraphQLContextFactory,
requestHandler: GraphQLRequestHandler,
subscriptionHandler: GraphQLSubscriptionHandler
subscriptionHandler: GraphQLSubscriptionHandler,
) : GraphQLServer<Context>(requestParser, contextFactory, requestHandler) {
private val objectMapper = jacksonObjectMapper()
private val subscriptionProtocolHandler = ApolloSubscriptionProtocolHandler(contextFactory, subscriptionHandler, objectMapper)
@@ -42,9 +42,10 @@ class TachideskGraphQLServer(
}
companion object {
private fun getGraphQLObject(): GraphQL = GraphQL.newGraphQL(schema)
.subscriptionExecutionStrategy(FlowSubscriptionExecutionStrategy())
.build()
private fun getGraphQLObject(): GraphQL =
GraphQL.newGraphQL(schema)
.subscriptionExecutionStrategy(FlowSubscriptionExecutionStrategy())
.build()
fun create(): TachideskGraphQLServer {
val graphQL = getGraphQLObject()

View File

@@ -22,12 +22,15 @@ object TemporaryFileStorage {
Runtime.getRuntime().addShutdownHook(
thread(start = false) {
folder.deleteRecursively()
}
},
)
}
@OptIn(DelicateCoroutinesApi::class)
fun saveFile(name: String, content: InputStream) {
fun saveFile(
name: String,
content: InputStream,
) {
val file = folder.resolve(name)
content.use { inStream ->
file.outputStream().use {

View File

@@ -14,36 +14,45 @@ import java.util.Locale
data class Cursor(val value: String)
val GraphQLCursor: GraphQLScalarType = GraphQLScalarType.newScalar()
.name("Cursor").description("A location in a connection that can be used for resuming pagination.").coercing(GraphqlCursorCoercing()).build()
val GraphQLCursor: GraphQLScalarType =
GraphQLScalarType.newScalar()
.name(
"Cursor",
).description("A location in a connection that can be used for resuming pagination.").coercing(GraphqlCursorCoercing()).build()
private class GraphqlCursorCoercing : Coercing<Cursor, String> {
private fun toStringImpl(input: Any): String? {
return (input as? Cursor)?.value
}
private fun parseValueImpl(input: Any, locale: Locale): Cursor {
private fun parseValueImpl(
input: Any,
locale: Locale,
): Cursor {
if (input !is String) {
throw CoercingParseValueException(
CoercingUtil.i18nMsg(
locale,
"String.unexpectedRawValueType",
CoercingUtil.typeName(input)
)
CoercingUtil.typeName(input),
),
)
}
return Cursor(input)
}
private fun parseLiteralImpl(input: Any, locale: Locale): Cursor {
private fun parseLiteralImpl(
input: Any,
locale: Locale,
): Cursor {
if (input !is StringValue) {
throw CoercingParseLiteralException(
CoercingUtil.i18nMsg(
locale,
"Scalar.unexpectedAstType",
"StringValue",
CoercingUtil.typeName(input)
)
CoercingUtil.typeName(input),
),
)
}
return Cursor(input.value)
@@ -59,8 +68,8 @@ private class GraphqlCursorCoercing : Coercing<Cursor, String> {
CoercingUtil.i18nMsg(
Locale.getDefault(),
"String.unexpectedRawValueType",
CoercingUtil.typeName(dataFetcherResult)
)
CoercingUtil.typeName(dataFetcherResult),
),
)
}
@@ -68,14 +77,14 @@ private class GraphqlCursorCoercing : Coercing<Cursor, String> {
override fun serialize(
dataFetcherResult: Any,
graphQLContext: GraphQLContext,
locale: Locale
locale: Locale,
): String {
return toStringImpl(dataFetcherResult) ?: throw CoercingSerializeException(
CoercingUtil.i18nMsg(
locale,
"String.unexpectedRawValueType",
CoercingUtil.typeName(dataFetcherResult)
)
CoercingUtil.typeName(dataFetcherResult),
),
)
}
@@ -85,7 +94,11 @@ private class GraphqlCursorCoercing : Coercing<Cursor, String> {
}
@Throws(CoercingParseValueException::class)
override fun parseValue(input: Any, graphQLContext: GraphQLContext, locale: Locale): Cursor {
override fun parseValue(
input: Any,
graphQLContext: GraphQLContext,
locale: Locale,
): Cursor {
return parseValueImpl(input, locale)
}
@@ -99,7 +112,7 @@ private class GraphqlCursorCoercing : Coercing<Cursor, String> {
input: Value<*>,
variables: CoercedVariables,
graphQLContext: GraphQLContext,
locale: Locale
locale: Locale,
): Cursor {
return parseLiteralImpl(input, locale)
}
@@ -112,7 +125,7 @@ private class GraphqlCursorCoercing : Coercing<Cursor, String> {
override fun valueToLiteral(
input: Any,
graphQLContext: GraphQLContext,
locale: Locale
locale: Locale,
): Value<*> {
return valueToLiteralImpl(input)
}

View File

@@ -12,36 +12,43 @@ import graphql.schema.CoercingSerializeException
import graphql.schema.GraphQLScalarType
import java.util.Locale
val GraphQLLongAsString: GraphQLScalarType = GraphQLScalarType.newScalar()
.name("LongString").description("A 64-bit signed integer as a String").coercing(GraphqlLongAsStringCoercing()).build()
val GraphQLLongAsString: GraphQLScalarType =
GraphQLScalarType.newScalar()
.name("LongString").description("A 64-bit signed integer as a String").coercing(GraphqlLongAsStringCoercing()).build()
private class GraphqlLongAsStringCoercing : Coercing<Long, String> {
private fun toStringImpl(input: Any): String {
return input.toString()
}
private fun parseValueImpl(input: Any, locale: Locale): Long {
private fun parseValueImpl(
input: Any,
locale: Locale,
): Long {
if (input !is String) {
throw CoercingParseValueException(
CoercingUtil.i18nMsg(
locale,
"String.unexpectedRawValueType",
CoercingUtil.typeName(input)
)
CoercingUtil.typeName(input),
),
)
}
return input.toLong()
}
private fun parseLiteralImpl(input: Any, locale: Locale): Long {
private fun parseLiteralImpl(
input: Any,
locale: Locale,
): Long {
if (input !is StringValue) {
throw CoercingParseLiteralException(
CoercingUtil.i18nMsg(
locale,
"Scalar.unexpectedAstType",
"StringValue",
CoercingUtil.typeName(input)
)
CoercingUtil.typeName(input),
),
)
}
return input.value.toLong()
@@ -60,7 +67,7 @@ private class GraphqlLongAsStringCoercing : Coercing<Long, String> {
override fun serialize(
dataFetcherResult: Any,
graphQLContext: GraphQLContext,
locale: Locale
locale: Locale,
): String {
return toStringImpl(dataFetcherResult)
}
@@ -71,7 +78,11 @@ private class GraphqlLongAsStringCoercing : Coercing<Long, String> {
}
@Throws(CoercingParseValueException::class)
override fun parseValue(input: Any, graphQLContext: GraphQLContext, locale: Locale): Long {
override fun parseValue(
input: Any,
graphQLContext: GraphQLContext,
locale: Locale,
): Long {
return parseValueImpl(input, locale)
}
@@ -85,7 +96,7 @@ private class GraphqlLongAsStringCoercing : Coercing<Long, String> {
input: Value<*>,
variables: CoercedVariables,
graphQLContext: GraphQLContext,
locale: Locale
locale: Locale,
): Long {
return parseLiteralImpl(input, locale)
}
@@ -98,7 +109,7 @@ private class GraphqlLongAsStringCoercing : Coercing<Long, String> {
override fun valueToLiteral(
input: Any,
graphQLContext: GraphQLContext,
locale: Locale
locale: Locale,
): Value<*> {
return valueToLiteralImpl(input)
}

View File

@@ -26,7 +26,7 @@ data class PageInfo(
@GraphQLDescription("When paginating backwards, the cursor to continue.")
val startCursor: Cursor?,
@GraphQLDescription("When paginating forwards, the cursor to continue.")
val endCursor: Cursor?
val endCursor: Cursor?,
)
abstract class Edge {

View File

@@ -41,7 +41,7 @@ fun <T : Comparable<T>> greaterNotUnique(
column: Column<T>,
idColumn: Column<EntityID<Int>>,
cursor: Cursor,
toValue: (String) -> T
toValue: (String) -> T,
): Op<Boolean> {
return greaterNotUniqueImpl(column, idColumn, cursor, String::toInt, toValue)
}
@@ -51,7 +51,7 @@ fun <T : Comparable<T>> greaterNotUnique(
column: Column<T>,
idColumn: Column<EntityID<Long>>,
cursor: Cursor,
toValue: (String) -> T
toValue: (String) -> T,
): Op<Boolean> {
return greaterNotUniqueImpl(column, idColumn, cursor, String::toLong, toValue)
}
@@ -61,7 +61,7 @@ private fun <K : Comparable<K>, V : Comparable<V>> greaterNotUniqueImpl(
idColumn: Column<EntityID<K>>,
cursor: Cursor,
toKey: (String) -> K,
toValue: (String) -> V
toValue: (String) -> V,
): Op<Boolean> {
val id = toKey(cursor.value.substringBefore('-'))
val value = toValue(cursor.value.substringAfter('-'))
@@ -73,7 +73,7 @@ fun <T : Comparable<T>> greaterNotUnique(
column: Column<T>,
idColumn: Column<String>,
cursor: Cursor,
toValue: (String) -> T
toValue: (String) -> T,
): Op<Boolean> {
val id = cursor.value.substringBefore("\\-")
val value = toValue(cursor.value.substringAfter("\\-"))
@@ -85,7 +85,7 @@ fun <T : Comparable<T>> lessNotUnique(
column: Column<T>,
idColumn: Column<EntityID<Int>>,
cursor: Cursor,
toValue: (String) -> T
toValue: (String) -> T,
): Op<Boolean> {
return lessNotUniqueImpl(column, idColumn, cursor, String::toInt, toValue)
}
@@ -95,7 +95,7 @@ fun <T : Comparable<T>> lessNotUnique(
column: Column<T>,
idColumn: Column<EntityID<Long>>,
cursor: Cursor,
toValue: (String) -> T
toValue: (String) -> T,
): Op<Boolean> {
return lessNotUniqueImpl(column, idColumn, cursor, String::toLong, toValue)
}
@@ -105,7 +105,7 @@ private fun <K : Comparable<K>, V : Comparable<V>> lessNotUniqueImpl(
idColumn: Column<EntityID<K>>,
cursor: Cursor,
toKey: (String) -> K,
toValue: (String) -> V
toValue: (String) -> V,
): Op<Boolean> {
val id = toKey(cursor.value.substringBefore('-'))
val value = toValue(cursor.value.substringAfter('-'))
@@ -117,7 +117,7 @@ fun <T : Comparable<T>> lessNotUnique(
column: Column<T>,
idColumn: Column<String>,
cursor: Cursor,
toValue: (String) -> T
toValue: (String) -> T,
): Op<Boolean> {
val id = cursor.value.substringBefore("\\-")
val value = toValue(cursor.value.substringAfter("\\-"))

View File

@@ -9,21 +9,25 @@ import graphql.schema.GraphQLScalarType
import io.javalin.http.UploadedFile
import java.util.Locale
val GraphQLUpload = GraphQLScalarType.newScalar()
.name("Upload")
.description("A file part in a multipart request")
.coercing(GraphqlUploadCoercing())
.build()
val GraphQLUpload =
GraphQLScalarType.newScalar()
.name("Upload")
.description("A file part in a multipart request")
.coercing(GraphqlUploadCoercing())
.build()
private class GraphqlUploadCoercing : Coercing<UploadedFile, Void?> {
private fun parseValueImpl(input: Any, locale: Locale): UploadedFile {
private fun parseValueImpl(
input: Any,
locale: Locale,
): UploadedFile {
if (input !is UploadedFile) {
throw CoercingParseValueException(
CoercingUtil.i18nMsg(
locale,
"String.unexpectedRawValueType",
CoercingUtil.typeName(input)
)
CoercingUtil.typeName(input),
),
)
}
return input
@@ -38,7 +42,7 @@ private class GraphqlUploadCoercing : Coercing<UploadedFile, Void?> {
override fun serialize(
dataFetcherResult: Any,
graphQLContext: GraphQLContext,
locale: Locale
locale: Locale,
): Void? {
throw CoercingSerializeException("Upload is an input-only type")
}
@@ -49,7 +53,11 @@ private class GraphqlUploadCoercing : Coercing<UploadedFile, Void?> {
}
@Throws(CoercingParseValueException::class)
override fun parseValue(input: Any, graphQLContext: GraphQLContext, locale: Locale): UploadedFile {
override fun parseValue(
input: Any,
graphQLContext: GraphQLContext,
locale: Locale,
): UploadedFile {
return parseValueImpl(input, locale)
}

View File

@@ -45,7 +45,7 @@ import suwayomi.tachidesk.server.serverConfig
class ApolloSubscriptionProtocolHandler(
private val contextFactory: TachideskGraphQLContextFactory,
private val subscriptionHandler: GraphQLSubscriptionHandler,
private val objectMapper: ObjectMapper
private val objectMapper: ObjectMapper,
) {
private val sessionState = ApolloSubscriptionSessionState()
private val logger = KotlinLogging.logger {}
@@ -68,13 +68,13 @@ class ApolloSubscriptionProtocolHandler(
val operationMessage = convertToMessageOrNull(context.message()) ?: return flowOf(basicConnectionErrorMessage)
logger.debug {
"GraphQL subscription client message, sessionId=${context.sessionId} type=${operationMessage.type} operationName=${
getOperationName(operationMessage.payload)
getOperationName(operationMessage.payload)
} ${
if (serverConfig.gqlDebugLogsEnabled.value) {
"operationMessage=$operationMessage"
} else {
""
}
if (serverConfig.gqlDebugLogsEnabled.value) {
"operationMessage=$operationMessage"
} else {
""
}
}"
}
@@ -108,7 +108,7 @@ class ApolloSubscriptionProtocolHandler(
@Suppress("Detekt.TooGenericExceptionCaught")
private fun startSubscription(
operationMessage: SubscriptionOperationMessage,
context: WsContext
context: WsContext,
): Flow<SubscriptionOperationMessage> {
if (operationMessage.id == null) {
logger.error("GraphQL subscription operation id is required")
@@ -149,7 +149,10 @@ class ApolloSubscriptionProtocolHandler(
}
}
private fun onInit(operationMessage: SubscriptionOperationMessage, context: WsContext): Flow<SubscriptionOperationMessage> {
private fun onInit(
operationMessage: SubscriptionOperationMessage,
context: WsContext,
): Flow<SubscriptionOperationMessage> {
saveContext(operationMessage, context)
return flowOf(acknowledgeMessage)
}
@@ -157,7 +160,10 @@ class ApolloSubscriptionProtocolHandler(
/**
* Generate the context and save it for all future messages.
*/
private fun saveContext(operationMessage: SubscriptionOperationMessage, context: WsContext) {
private fun saveContext(
operationMessage: SubscriptionOperationMessage,
context: WsContext,
) {
runBlocking {
val graphQLContext = contextFactory.generateContextMap(context).toGraphQLContext()
sessionState.saveContext(context, graphQLContext)
@@ -169,7 +175,7 @@ class ApolloSubscriptionProtocolHandler(
*/
private fun onComplete(
operationMessage: SubscriptionOperationMessage,
context: WsContext
context: WsContext,
): Flow<SubscriptionOperationMessage> {
return sessionState.completeOperation(operationMessage)
}
@@ -183,7 +189,10 @@ class ApolloSubscriptionProtocolHandler(
return emptyFlow()
}
private fun onUnknownOperation(operationMessage: SubscriptionOperationMessage, context: WsContext): Flow<SubscriptionOperationMessage> {
private fun onUnknownOperation(
operationMessage: SubscriptionOperationMessage,
context: WsContext,
): Flow<SubscriptionOperationMessage> {
logger.error("Unknown subscription operation $operationMessage")
sessionState.completeOperation(operationMessage)
return emptyFlow()

View File

@@ -19,7 +19,6 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArrayList
internal class ApolloSubscriptionSessionState {
// Operations are saved by web socket session id, then operation id
internal val activeOperations = ConcurrentHashMap<String, Job>()
@@ -33,21 +32,29 @@ internal class ApolloSubscriptionSessionState {
* This allows us to include some initial state to be used when handling all the messages.
* This will be removed in [terminateSession].
*/
fun saveContext(context: WsContext, graphQLContext: GraphQLContext) {
fun saveContext(
context: WsContext,
graphQLContext: GraphQLContext,
) {
cachedGraphQLContext[context.sessionId] = graphQLContext
}
/**
* Return the graphQL context for this session.
*/
fun getGraphQLContext(context: WsContext): GraphQLContext = cachedGraphQLContext[context.sessionId] ?: emptyMap<Any, Any>().toGraphQLContext()
fun getGraphQLContext(context: WsContext): GraphQLContext =
cachedGraphQLContext[context.sessionId] ?: emptyMap<Any, Any>().toGraphQLContext()
/**
* Save the operation that is sending data to the client.
* This will override values without cancelling the subscription so it is the responsibility of the consumer to cancel.
* These messages will be stopped on [stopOperation].
*/
fun saveOperation(context: WsContext, operationMessage: SubscriptionOperationMessage, subscription: Job) {
fun saveOperation(
context: WsContext,
operationMessage: SubscriptionOperationMessage,
subscription: Job,
) {
val id = operationMessage.id
if (id != null) {
activeOperations[id] = subscription
@@ -78,7 +85,10 @@ internal class ApolloSubscriptionSessionState {
/**
* Terminate the session, cancelling the keep alive messages and all operations active for this session.
*/
fun terminateSession(context: WsContext, code: CloseStatus) {
fun terminateSession(
context: WsContext,
code: CloseStatus,
) {
sessionToOperationId.remove(context.sessionId)?.forEach {
activeOperations[it]?.cancel()
}
@@ -89,6 +99,5 @@ internal class ApolloSubscriptionSessionState {
/**
* Looks up the operation for the client, to check if it already exists
*/
fun doesOperationExist(operationMessage: SubscriptionOperationMessage): Boolean =
activeOperations.containsKey(operationMessage.id)
fun doesOperationExist(operationMessage: SubscriptionOperationMessage): Boolean = activeOperations.containsKey(operationMessage.id)
}

View File

@@ -23,11 +23,11 @@ import kotlinx.coroutines.flow.map
open class GraphQLSubscriptionHandler(
private val graphQL: GraphQL,
private val dataLoaderRegistryFactory: KotlinDataLoaderRegistryFactory? = null
private val dataLoaderRegistryFactory: KotlinDataLoaderRegistryFactory? = null,
) {
open fun executeSubscription(
graphQLRequest: GraphQLRequest,
graphQLContext: GraphQLContext = GraphQLContext.of(emptyMap<Any, Any>())
graphQLContext: GraphQLContext = GraphQLContext.of(emptyMap<Any, Any>()),
): Flow<GraphQLResponse<*>> {
val dataLoaderRegistry = dataLoaderRegistryFactory?.generate()
val input = graphQLRequest.toExecutionInput(dataLoaderRegistry, graphQLContext)

View File

@@ -21,22 +21,22 @@ import com.fasterxml.jackson.annotation.JsonInclude
data class SubscriptionOperationMessage(
val type: String,
val id: String? = null,
val payload: Any? = null
val payload: Any? = null,
) {
enum class CommonMessages(val type: String) {
GQL_PING("ping"),
GQL_PONG("pong"),
GQL_COMPLETE("complete")
GQL_COMPLETE("complete"),
}
enum class ClientMessages(val type: String) {
GQL_CONNECTION_INIT("connection_init"),
GQL_SUBSCRIBE("subscribe")
GQL_SUBSCRIBE("subscribe"),
}
enum class ServerMessages(val type: String) {
GQL_CONNECTION_ACK("connection_ack"),
GQL_NEXT("next"),
GQL_ERROR("error")
GQL_ERROR("error"),
}
}

View File

@@ -13,7 +13,6 @@ import suwayomi.tachidesk.graphql.types.DownloadStatus
import suwayomi.tachidesk.manga.impl.download.DownloadManager
class DownloadSubscription {
fun downloadChanged(): Flow<DownloadStatus> {
return DownloadManager.status.map { downloadStatus ->
DownloadStatus(downloadStatus)

View File

@@ -5,31 +5,34 @@ import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
enum class BackupRestoreState {
IDLE,
RESTORING_CATEGORIES,
RESTORING_MANGA
RESTORING_MANGA,
}
data class BackupRestoreStatus(
val state: BackupRestoreState,
val totalManga: Int,
val mangaProgress: Int
val mangaProgress: Int,
)
fun ProtoBackupImport.BackupRestoreState.toStatus(): BackupRestoreStatus {
return when (this) {
ProtoBackupImport.BackupRestoreState.Idle -> BackupRestoreStatus(
state = BackupRestoreState.IDLE,
totalManga = 0,
mangaProgress = 0
)
is ProtoBackupImport.BackupRestoreState.RestoringCategories -> BackupRestoreStatus(
state = BackupRestoreState.RESTORING_CATEGORIES,
totalManga = totalManga,
mangaProgress = 0
)
is ProtoBackupImport.BackupRestoreState.RestoringManga -> BackupRestoreStatus(
state = BackupRestoreState.RESTORING_MANGA,
totalManga = totalManga,
mangaProgress = current
)
ProtoBackupImport.BackupRestoreState.Idle ->
BackupRestoreStatus(
state = BackupRestoreState.IDLE,
totalManga = 0,
mangaProgress = 0,
)
is ProtoBackupImport.BackupRestoreState.RestoringCategories ->
BackupRestoreStatus(
state = BackupRestoreState.RESTORING_CATEGORIES,
totalManga = totalManga,
mangaProgress = 0,
)
is ProtoBackupImport.BackupRestoreState.RestoringManga ->
BackupRestoreStatus(
state = BackupRestoreState.RESTORING_MANGA,
totalManga = totalManga,
mangaProgress = current,
)
}
}

View File

@@ -24,14 +24,14 @@ class CategoryType(
val order: Int,
val name: String,
val default: Boolean,
val includeInUpdate: IncludeInUpdate
val includeInUpdate: IncludeInUpdate,
) : Node {
constructor(row: ResultRow) : this(
row[CategoryTable.id].value,
row[CategoryTable.order],
row[CategoryTable.name],
row[CategoryTable.isDefault],
IncludeInUpdate.fromValue(row[CategoryTable.includeInUpdate])
IncludeInUpdate.fromValue(row[CategoryTable.includeInUpdate]),
)
fun mangas(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<MangaNodeList> {
@@ -47,11 +47,11 @@ data class CategoryNodeList(
override val nodes: List<CategoryType>,
override val edges: List<CategoryEdge>,
override val pageInfo: PageInfo,
override val totalCount: Int
override val totalCount: Int,
) : NodeList() {
data class CategoryEdge(
override val cursor: Cursor,
override val node: CategoryType
override val node: CategoryType,
) : Edge()
companion object {
@@ -59,13 +59,14 @@ data class CategoryNodeList(
return CategoryNodeList(
nodes = this,
edges = getEdges(),
pageInfo = PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString())
),
totalCount = size
pageInfo =
PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString()),
),
totalCount = size,
)
}
@@ -74,12 +75,12 @@ data class CategoryNodeList(
return listOf(
CategoryEdge(
cursor = Cursor("0"),
node = first()
node = first(),
),
CategoryEdge(
cursor = Cursor(lastIndex.toString()),
node = last()
)
node = last(),
),
)
}
}

View File

@@ -35,7 +35,7 @@ class ChapterType(
val realUrl: String?,
val fetchedAt: Long,
val isDownloaded: Boolean,
val pageCount: Int
val pageCount: Int,
// val chapterCount: Int?,
) : Node {
constructor(row: ResultRow) : this(
@@ -54,7 +54,7 @@ class ChapterType(
row[ChapterTable.realUrl],
row[ChapterTable.fetchedAt],
row[ChapterTable.isDownloaded],
row[ChapterTable.pageCount]
row[ChapterTable.pageCount],
// transaction { ChapterTable.select { manga eq chapterEntry[manga].value }.count().toInt() },
)
@@ -74,7 +74,7 @@ class ChapterType(
dataClass.realUrl,
dataClass.fetchedAt,
dataClass.downloaded,
dataClass.pageCount
dataClass.pageCount,
)
fun manga(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<MangaType> {
@@ -90,11 +90,11 @@ data class ChapterNodeList(
override val nodes: List<ChapterType>,
override val edges: List<ChapterEdge>,
override val pageInfo: PageInfo,
override val totalCount: Int
override val totalCount: Int,
) : NodeList() {
data class ChapterEdge(
override val cursor: Cursor,
override val node: ChapterType
override val node: ChapterType,
) : Edge()
companion object {
@@ -102,13 +102,14 @@ data class ChapterNodeList(
return ChapterNodeList(
nodes = this,
edges = getEdges(),
pageInfo = PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString())
),
totalCount = size
pageInfo =
PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString()),
),
totalCount = size,
)
}
@@ -117,12 +118,12 @@ data class ChapterNodeList(
return listOf(
ChapterEdge(
cursor = Cursor("0"),
node = first()
node = first(),
),
ChapterEdge(
cursor = Cursor(lastIndex.toString()),
node = last()
)
node = last(),
),
)
}
}

View File

@@ -23,14 +23,14 @@ import suwayomi.tachidesk.manga.impl.download.model.DownloadState as OtherDownlo
data class DownloadStatus(
val state: DownloaderState,
val queue: List<DownloadType>
val queue: List<DownloadType>,
) {
constructor(downloadStatus: DownloadStatus) : this(
when (downloadStatus.status) {
Status.Stopped -> DownloaderState.STOPPED
Status.Started -> DownloaderState.STARTED
},
downloadStatus.queue.map { DownloadType(it) }
downloadStatus.queue.map { DownloadType(it) },
)
}
@@ -41,7 +41,7 @@ class DownloadType(
val mangaId: Int,
val state: DownloadState,
val progress: Float,
val tries: Int
val tries: Int,
) : Node {
constructor(downloadChapter: DownloadChapter) : this(
downloadChapter.chapter.id,
@@ -53,7 +53,7 @@ class DownloadType(
OtherDownloadState.Error -> DownloadState.ERROR
},
downloadChapter.progress,
downloadChapter.tries
downloadChapter.tries,
)
fun manga(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<MangaType> {
@@ -69,23 +69,23 @@ enum class DownloadState {
QUEUED,
DOWNLOADING,
FINISHED,
ERROR
ERROR,
}
enum class DownloaderState {
STARTED,
STOPPED
STOPPED,
}
data class DownloadNodeList(
override val nodes: List<DownloadType>,
override val edges: List<DownloadEdge>,
override val pageInfo: PageInfo,
override val totalCount: Int
override val totalCount: Int,
) : NodeList() {
data class DownloadEdge(
override val cursor: Cursor,
override val node: DownloadType
override val node: DownloadType,
) : Edge()
companion object {
@@ -93,13 +93,14 @@ data class DownloadNodeList(
return DownloadNodeList(
nodes = this,
edges = getEdges(),
pageInfo = PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString())
),
totalCount = size
pageInfo =
PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString()),
),
totalCount = size,
)
}
@@ -108,12 +109,12 @@ data class DownloadNodeList(
return listOf(
DownloadEdge(
cursor = Cursor("0"),
node = first()
node = first(),
),
DownloadEdge(
cursor = Cursor(lastIndex.toString()),
node = last()
)
node = last(),
),
)
}
}

View File

@@ -22,17 +22,15 @@ import java.util.concurrent.CompletableFuture
class ExtensionType(
val apkName: String,
val iconUrl: String,
val name: String,
val pkgName: String,
val versionName: String,
val versionCode: Int,
val lang: String,
val isNsfw: Boolean,
val isInstalled: Boolean,
val hasUpdate: Boolean,
val isObsolete: Boolean
val isObsolete: Boolean,
) : Node {
constructor(row: ResultRow) : this(
apkName = row[ExtensionTable.apkName],
@@ -45,7 +43,7 @@ class ExtensionType(
isNsfw = row[ExtensionTable.isNsfw],
isInstalled = row[ExtensionTable.isInstalled],
hasUpdate = row[ExtensionTable.hasUpdate],
isObsolete = row[ExtensionTable.isObsolete]
isObsolete = row[ExtensionTable.isObsolete],
)
fun source(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<SourceNodeList> {
@@ -57,11 +55,11 @@ data class ExtensionNodeList(
override val nodes: List<ExtensionType>,
override val edges: List<ExtensionEdge>,
override val pageInfo: PageInfo,
override val totalCount: Int
override val totalCount: Int,
) : NodeList() {
data class ExtensionEdge(
override val cursor: Cursor,
override val node: ExtensionType
override val node: ExtensionType,
) : Edge()
companion object {
@@ -69,13 +67,14 @@ data class ExtensionNodeList(
return ExtensionNodeList(
nodes = this,
edges = getEdges(),
pageInfo = PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString())
),
totalCount = size
pageInfo =
PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString()),
),
totalCount = size,
)
}
@@ -84,12 +83,12 @@ data class ExtensionNodeList(
return listOf(
ExtensionEdge(
cursor = Cursor("0"),
node = first()
node = first(),
),
ExtensionEdge(
cursor = Cursor(lastIndex.toString()),
node = last()
)
node = last(),
),
)
}
}

View File

@@ -39,7 +39,7 @@ class MangaType(
val inLibraryAt: Long,
val realUrl: String?,
var lastFetchedAt: Long?, // todo
var chaptersLastFetchedAt: Long? // todo
var chaptersLastFetchedAt: Long?, // todo
) : Node {
constructor(row: ResultRow) : this(
row[MangaTable.id].value,
@@ -57,7 +57,7 @@ class MangaType(
row[MangaTable.inLibraryAt],
row[MangaTable.realUrl],
row[MangaTable.lastFetchedAt],
row[MangaTable.chaptersLastFetchedAt]
row[MangaTable.chaptersLastFetchedAt],
)
constructor(dataClass: MangaDataClass) : this(
@@ -76,7 +76,7 @@ class MangaType(
dataClass.inLibraryAt,
dataClass.realUrl,
dataClass.lastFetchedAt,
dataClass.chaptersLastFetchedAt
dataClass.chaptersLastFetchedAt,
)
fun downloadCount(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<Int> {
@@ -123,11 +123,11 @@ data class MangaNodeList(
override val nodes: List<MangaType>,
override val edges: List<MangaEdge>,
override val pageInfo: PageInfo,
override val totalCount: Int
override val totalCount: Int,
) : NodeList() {
data class MangaEdge(
override val cursor: Cursor,
override val node: MangaType
override val node: MangaType,
) : Edge()
companion object {
@@ -135,13 +135,14 @@ data class MangaNodeList(
return MangaNodeList(
nodes = this,
edges = getEdges(),
pageInfo = PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString())
),
totalCount = size
pageInfo =
PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString()),
),
totalCount = size,
)
}
@@ -150,12 +151,12 @@ data class MangaNodeList(
return listOf(
MangaEdge(
cursor = Cursor("0"),
node = first()
node = first(),
),
MangaEdge(
cursor = Cursor(lastIndex.toString()),
node = last()
)
node = last(),
),
)
}
}

View File

@@ -22,12 +22,12 @@ interface MetaType : Node {
class ChapterMetaType(
override val key: String,
override val value: String,
val chapterId: Int
val chapterId: Int,
) : MetaType {
constructor(row: ResultRow) : this(
key = row[ChapterMetaTable.key],
value = row[ChapterMetaTable.value],
chapterId = row[ChapterMetaTable.ref].value
chapterId = row[ChapterMetaTable.ref].value,
)
fun chapter(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<ChapterType> {
@@ -38,12 +38,12 @@ class ChapterMetaType(
class MangaMetaType(
override val key: String,
override val value: String,
val mangaId: Int
val mangaId: Int,
) : MetaType {
constructor(row: ResultRow) : this(
key = row[MangaMetaTable.key],
value = row[MangaMetaTable.value],
mangaId = row[MangaMetaTable.ref].value
mangaId = row[MangaMetaTable.ref].value,
)
fun manga(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<MangaType> {
@@ -54,12 +54,12 @@ class MangaMetaType(
class CategoryMetaType(
override val key: String,
override val value: String,
val categoryId: Int
val categoryId: Int,
) : MetaType {
constructor(row: ResultRow) : this(
key = row[CategoryMetaTable.key],
value = row[CategoryMetaTable.value],
categoryId = row[CategoryMetaTable.ref].value
categoryId = row[CategoryMetaTable.ref].value,
)
fun category(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<CategoryType> {
@@ -69,11 +69,11 @@ class CategoryMetaType(
class GlobalMetaType(
override val key: String,
override val value: String
override val value: String,
) : MetaType {
constructor(row: ResultRow) : this(
key = row[GlobalMetaTable.key],
value = row[GlobalMetaTable.value]
value = row[GlobalMetaTable.value],
)
}
@@ -81,11 +81,11 @@ data class GlobalMetaNodeList(
override val nodes: List<GlobalMetaType>,
override val edges: List<MetaEdge>,
override val pageInfo: PageInfo,
override val totalCount: Int
override val totalCount: Int,
) : NodeList() {
data class MetaEdge(
override val cursor: Cursor,
override val node: GlobalMetaType
override val node: GlobalMetaType,
) : Edge()
companion object {
@@ -93,13 +93,14 @@ data class GlobalMetaNodeList(
return GlobalMetaNodeList(
nodes = this,
edges = getEdges(),
pageInfo = PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString())
),
totalCount = size
pageInfo =
PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString()),
),
totalCount = size,
)
}
@@ -108,12 +109,12 @@ data class GlobalMetaNodeList(
return listOf(
MetaEdge(
cursor = Cursor("0"),
node = first()
node = first(),
),
MetaEdge(
cursor = Cursor(lastIndex.toString()),
node = last()
)
node = last(),
),
)
}
}

View File

@@ -69,12 +69,10 @@ interface Settings : Node {
data class PartialSettingsType(
override val ip: String?,
override val port: Int?,
// proxy
override val socksProxyEnabled: Boolean?,
override val socksProxyHost: String?,
override val socksProxyPort: String?,
// webUI
override val webUIFlavor: WebUIFlavor?,
override val initialOpenInBrowserEnabled: Boolean?,
@@ -82,49 +80,40 @@ data class PartialSettingsType(
override val electronPath: String?,
override val webUIChannel: WebUIChannel?,
override val webUIUpdateCheckInterval: Double?,
// downloader
override val downloadAsCbz: Boolean?,
override val downloadsPath: String?,
override val autoDownloadNewChapters: Boolean?,
// requests
override val maxSourcesInParallel: Int?,
// updater
override val excludeUnreadChapters: Boolean?,
override val excludeNotStarted: Boolean?,
override val excludeCompleted: Boolean?,
override val globalUpdateInterval: Double?,
// Authentication
override val basicAuthEnabled: Boolean?,
override val basicAuthUsername: String?,
override val basicAuthPassword: String?,
// misc
override val debugLogsEnabled: Boolean?,
override val systemTrayEnabled: Boolean?,
// backup
override val backupPath: String?,
override val backupTime: String?,
override val backupInterval: Int?,
override val backupTTL: Int?,
// local source
override val localSourcePath: String?
override val localSourcePath: String?,
) : Settings
class SettingsType(
override val ip: String,
override val port: Int,
// proxy
override val socksProxyEnabled: Boolean,
override val socksProxyHost: String,
override val socksProxyPort: String,
// webUI
override val webUIFlavor: WebUIFlavor,
override val initialOpenInBrowserEnabled: Boolean,
@@ -132,77 +121,61 @@ class SettingsType(
override val electronPath: String,
override val webUIChannel: WebUIChannel,
override val webUIUpdateCheckInterval: Double,
// downloader
override val downloadAsCbz: Boolean,
override val downloadsPath: String,
override val autoDownloadNewChapters: Boolean,
// requests
override val maxSourcesInParallel: Int,
// updater
override val excludeUnreadChapters: Boolean,
override val excludeNotStarted: Boolean,
override val excludeCompleted: Boolean,
override val globalUpdateInterval: Double,
// Authentication
override val basicAuthEnabled: Boolean,
override val basicAuthUsername: String,
override val basicAuthPassword: String,
// misc
override val debugLogsEnabled: Boolean,
override val systemTrayEnabled: Boolean,
// backup
override val backupPath: String,
override val backupTime: String,
override val backupInterval: Int,
override val backupTTL: Int,
// local source
override val localSourcePath: String
override val localSourcePath: String,
) : Settings {
constructor(config: ServerConfig = serverConfig) : this(
config.ip.value,
config.port.value,
config.socksProxyEnabled.value,
config.socksProxyHost.value,
config.socksProxyPort.value,
WebUIFlavor.from(config.webUIFlavor.value),
config.initialOpenInBrowserEnabled.value,
WebUIInterface.from(config.webUIInterface.value),
config.electronPath.value,
WebUIChannel.from(config.webUIChannel.value),
config.webUIUpdateCheckInterval.value,
config.downloadAsCbz.value,
config.downloadsPath.value,
config.autoDownloadNewChapters.value,
config.maxSourcesInParallel.value,
config.excludeUnreadChapters.value,
config.excludeNotStarted.value,
config.excludeCompleted.value,
config.globalUpdateInterval.value,
config.basicAuthEnabled.value,
config.basicAuthUsername.value,
config.basicAuthPassword.value,
config.debugLogsEnabled.value,
config.systemTrayEnabled.value,
config.backupPath.value,
config.backupTime.value,
config.backupInterval.value,
config.backupTTL.value,
config.localSourcePath.value
config.localSourcePath.value,
)
}

View File

@@ -43,7 +43,7 @@ class SourceType(
val supportsLatest: Boolean,
val isConfigurable: Boolean,
val isNsfw: Boolean,
val displayName: String
val displayName: String,
) : Node {
constructor(source: SourceDataClass) : this(
id = source.id.toLong(),
@@ -53,7 +53,7 @@ class SourceType(
supportsLatest = source.supportsLatest,
isConfigurable = source.isConfigurable,
isNsfw = source.isNsfw,
displayName = source.displayName
displayName = source.displayName,
)
constructor(row: ResultRow, sourceExtension: ResultRow, catalogueSource: CatalogueSource) : this(
@@ -64,7 +64,7 @@ class SourceType(
supportsLatest = catalogueSource.supportsLatest,
isConfigurable = catalogueSource is ConfigurableSource,
isNsfw = row[SourceTable.isNsfw],
displayName = catalogueSource.toString()
displayName = catalogueSource.toString(),
)
fun manga(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<MangaNodeList> {
@@ -84,17 +84,20 @@ class SourceType(
}
}
@Suppress("ktlint:standard:function-naming")
fun SourceType(row: ResultRow): SourceType? {
val catalogueSource = GetCatalogueSource
.getCatalogueSourceOrNull(row[SourceTable.id].value)
?: return null
val sourceExtension = if (row.hasValue(ExtensionTable.id)) {
row
} else {
ExtensionTable
.select { ExtensionTable.id eq row[SourceTable.extension] }
.first()
}
val catalogueSource =
GetCatalogueSource
.getCatalogueSourceOrNull(row[SourceTable.id].value)
?: return null
val sourceExtension =
if (row.hasValue(ExtensionTable.id)) {
row
} else {
ExtensionTable
.select { ExtensionTable.id eq row[SourceTable.extension] }
.first()
}
return SourceType(row, sourceExtension, catalogueSource)
}
@@ -103,11 +106,11 @@ data class SourceNodeList(
override val nodes: List<SourceType>,
override val edges: List<SourceEdge>,
override val pageInfo: PageInfo,
override val totalCount: Int
override val totalCount: Int,
) : NodeList() {
data class SourceEdge(
override val cursor: Cursor,
override val node: SourceType
override val node: SourceType,
) : Edge()
companion object {
@@ -115,13 +118,14 @@ data class SourceNodeList(
return SourceNodeList(
nodes = this,
edges = getEdges(),
pageInfo = PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString())
),
totalCount = size
pageInfo =
PageInfo(
hasNextPage = false,
hasPreviousPage = false,
startCursor = Cursor(0.toString()),
endCursor = Cursor(lastIndex.toString()),
),
totalCount = size,
)
}
@@ -130,12 +134,12 @@ data class SourceNodeList(
return listOf(
SourceEdge(
cursor = Cursor("0"),
node = first()
node = first(),
),
SourceEdge(
cursor = Cursor(lastIndex.toString()),
node = last()
)
node = last(),
),
)
}
}
@@ -156,7 +160,7 @@ data class CheckBoxFilter(val name: String, val default: Boolean) : Filter
enum class TriState {
IGNORE,
INCLUDE,
EXCLUDE
EXCLUDE,
}
data class TriStateFilter(val name: String, val default: TriState) : Filter
@@ -177,18 +181,20 @@ fun filterOf(filter: SourceFilter<*>): Filter {
is SourceFilter.Select<*> -> SelectFilter(filter.name, filter.displayValues, filter.state)
is SourceFilter.Text -> TextFilter(filter.name, filter.state)
is SourceFilter.CheckBox -> CheckBoxFilter(filter.name, filter.state)
is SourceFilter.TriState -> TriStateFilter(
filter.name,
when (filter.state) {
SourceFilter.TriState.STATE_INCLUDE -> TriState.INCLUDE
SourceFilter.TriState.STATE_EXCLUDE -> TriState.EXCLUDE
else -> TriState.IGNORE
}
)
is SourceFilter.Group<*> -> GroupFilter(
filter.name,
filter.state.map { filterOf(it as SourceFilter<*>) }
)
is SourceFilter.TriState ->
TriStateFilter(
filter.name,
when (filter.state) {
SourceFilter.TriState.STATE_INCLUDE -> TriState.INCLUDE
SourceFilter.TriState.STATE_EXCLUDE -> TriState.EXCLUDE
else -> TriState.IGNORE
},
)
is SourceFilter.Group<*> ->
GroupFilter(
filter.name,
filter.state.map { filterOf(it as SourceFilter<*>) },
)
is SourceFilter.Sort -> SortFilter(filter.name, filter.values.asList(), filter.state?.let(SortFilter::SortSelection))
else -> throw RuntimeException("sealed class cannot have more subtypes!")
}
@@ -239,10 +245,13 @@ data class FilterChange(
val checkBoxState: Boolean? = null,
val triState: TriState? = null,
val sortState: SortFilter.SortSelection? = null,
val groupChange: FilterChange? = null
val groupChange: FilterChange? = null,
)
fun updateFilterList(source: CatalogueSource, changes: List<FilterChange>?): FilterList {
fun updateFilterList(
source: CatalogueSource,
changes: List<FilterChange>?,
): FilterList {
val filterList = source.getFilterList()
changes?.forEach { change ->
@@ -254,32 +263,42 @@ fun updateFilterList(source: CatalogueSource, changes: List<FilterChange>?): Fil
// NOOP
}
is SourceFilter.Select<*> -> {
filter.state = change.selectState ?: throw Exception("Expected select state change at position ${change.position}")
filter.state = change.selectState
?: throw Exception("Expected select state change at position ${change.position}")
}
is SourceFilter.Text -> {
filter.state = change.textState ?: throw Exception("Expected text state change at position ${change.position}")
filter.state = change.textState
?: throw Exception("Expected text state change at position ${change.position}")
}
is SourceFilter.CheckBox -> {
filter.state = change.checkBoxState ?: throw Exception("Expected checkbox state change at position ${change.position}")
filter.state = change.checkBoxState
?: throw Exception("Expected checkbox state change at position ${change.position}")
}
is SourceFilter.TriState -> {
filter.state = change.triState?.ordinal ?: throw Exception("Expected tri state change at position ${change.position}")
filter.state = change.triState?.ordinal
?: throw Exception("Expected tri state change at position ${change.position}")
}
is SourceFilter.Group<*> -> {
val groupChange = change.groupChange ?: throw Exception("Expected group change at position ${change.position}")
val groupChange =
change.groupChange
?: throw Exception("Expected group change at position ${change.position}")
when (val groupFilter = filter.state[groupChange.position]) {
is SourceFilter.CheckBox -> {
groupFilter.state = groupChange.checkBoxState ?: throw Exception("Expected checkbox state change at position ${change.position}")
groupFilter.state = groupChange.checkBoxState
?: throw Exception("Expected checkbox state change at position ${change.position}")
}
is SourceFilter.TriState -> {
groupFilter.state = groupChange.triState?.ordinal ?: throw Exception("Expected tri state change at position ${change.position}")
groupFilter.state = groupChange.triState?.ordinal
?: throw Exception("Expected tri state change at position ${change.position}")
}
is SourceFilter.Text -> {
groupFilter.state = groupChange.textState ?: throw Exception("Expected text state change at position ${change.position}")
groupFilter.state = groupChange.textState
?: throw Exception("Expected text state change at position ${change.position}")
}
is SourceFilter.Select<*> -> {
groupFilter.state = groupChange.selectState ?: throw Exception("Expected select state change at position ${change.position}")
groupFilter.state = groupChange.selectState
?: throw Exception("Expected select state change at position ${change.position}")
}
}
}
@@ -301,7 +320,7 @@ data class SwitchPreference(
val summary: String?,
val visible: Boolean,
val currentValue: Boolean?,
val default: Boolean
val default: Boolean,
) : Preference
data class CheckBoxPreference(
@@ -310,7 +329,7 @@ data class CheckBoxPreference(
val summary: String?,
val visible: Boolean,
val currentValue: Boolean?,
val default: Boolean
val default: Boolean,
) : Preference
data class EditTextPreference(
@@ -322,7 +341,7 @@ data class EditTextPreference(
val default: String?,
val dialogTitle: String?,
val dialogMessage: String?,
val text: String?
val text: String?,
) : Preference
data class ListPreference(
@@ -333,7 +352,7 @@ data class ListPreference(
val currentValue: String?,
val default: String?,
val entries: List<String>,
val entryValues: List<String>
val entryValues: List<String>,
) : Preference
data class MultiSelectListPreference(
@@ -346,60 +365,65 @@ data class MultiSelectListPreference(
val dialogTitle: String?,
val dialogMessage: String?,
val entries: List<String>,
val entryValues: List<String>
val entryValues: List<String>,
) : Preference
fun preferenceOf(preference: SourcePreference): Preference {
return when (preference) {
is SourceSwitchPreference -> SwitchPreference(
preference.key,
preference.title.toString(),
preference.summary?.toString(),
preference.visible,
preference.currentValue as Boolean,
preference.defaultValue as Boolean,
)
is SourceCheckBoxPreference -> CheckBoxPreference(
preference.key,
preference.title.toString(),
preference.summary?.toString(),
preference.visible,
preference.currentValue as Boolean,
preference.defaultValue as Boolean
)
is SourceEditTextPreference -> EditTextPreference(
preference.key,
preference.title?.toString(),
preference.summary?.toString(),
preference.visible,
(preference.currentValue as CharSequence?)?.toString(),
(preference.defaultValue as CharSequence?)?.toString(),
preference.dialogTitle?.toString(),
preference.dialogMessage?.toString(),
preference.text
)
is SourceListPreference -> ListPreference(
preference.key,
preference.title?.toString(),
preference.summary?.toString(),
preference.visible,
(preference.currentValue as CharSequence?)?.toString(),
(preference.defaultValue as CharSequence?)?.toString(),
preference.entries.map { it.toString() },
preference.entryValues.map { it.toString() }
)
is SourceMultiSelectListPreference -> MultiSelectListPreference(
preference.key,
preference.title?.toString(),
preference.summary?.toString(),
preference.visible,
(preference.currentValue as Collection<*>?)?.map { it.toString() },
(preference.defaultValue as Collection<*>?)?.map { it.toString() },
preference.dialogTitle?.toString(),
preference.dialogMessage?.toString(),
preference.entries.map { it.toString() },
preference.entryValues.map { it.toString() }
)
is SourceSwitchPreference ->
SwitchPreference(
preference.key,
preference.title.toString(),
preference.summary?.toString(),
preference.visible,
preference.currentValue as Boolean,
preference.defaultValue as Boolean,
)
is SourceCheckBoxPreference ->
CheckBoxPreference(
preference.key,
preference.title.toString(),
preference.summary?.toString(),
preference.visible,
preference.currentValue as Boolean,
preference.defaultValue as Boolean,
)
is SourceEditTextPreference ->
EditTextPreference(
preference.key,
preference.title?.toString(),
preference.summary?.toString(),
preference.visible,
(preference.currentValue as CharSequence?)?.toString(),
(preference.defaultValue as CharSequence?)?.toString(),
preference.dialogTitle?.toString(),
preference.dialogMessage?.toString(),
preference.text,
)
is SourceListPreference ->
ListPreference(
preference.key,
preference.title?.toString(),
preference.summary?.toString(),
preference.visible,
(preference.currentValue as CharSequence?)?.toString(),
(preference.defaultValue as CharSequence?)?.toString(),
preference.entries.map { it.toString() },
preference.entryValues.map { it.toString() },
)
is SourceMultiSelectListPreference ->
MultiSelectListPreference(
preference.key,
preference.title?.toString(),
preference.summary?.toString(),
preference.visible,
(preference.currentValue as Collection<*>?)?.map { it.toString() },
(preference.defaultValue as Collection<*>?)?.map { it.toString() },
preference.dialogTitle?.toString(),
preference.dialogMessage?.toString(),
preference.entries.map { it.toString() },
preference.entryValues.map { it.toString() },
)
else -> throw RuntimeException("sealed class cannot have more subtypes!")
}
}

View File

@@ -16,7 +16,7 @@ class UpdateStatus(
val runningJobs: UpdateStatusType,
val completeJobs: UpdateStatusType,
val failedJobs: UpdateStatusType,
val skippedJobs: UpdateStatusType
val skippedJobs: UpdateStatusType,
) {
constructor(status: UpdateStatus) : this(
isRunning = status.running,
@@ -26,13 +26,13 @@ class UpdateStatus(
runningJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.RUNNING]?.map { it.id }.orEmpty()),
completeJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.COMPLETE]?.map { it.id }.orEmpty()),
failedJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.FAILED]?.map { it.id }.orEmpty()),
skippedJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.SKIPPED]?.map { it.id }.orEmpty())
skippedJobs = UpdateStatusType(status.mangaStatusMap[JobStatus.SKIPPED]?.map { it.id }.orEmpty()),
)
}
class UpdateStatusCategoryType(
@get:GraphQLIgnore
val categoryIds: List<Int>
val categoryIds: List<Int>,
) {
fun categories(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<CategoryNodeList> {
return dataFetchingEnvironment.getValueFromDataLoader("CategoryForIdsDataLoader", categoryIds)
@@ -41,7 +41,7 @@ class UpdateStatusCategoryType(
class UpdateStatusType(
@get:GraphQLIgnore
val mangaIds: List<Int>
val mangaIds: List<Int>,
) {
fun mangas(dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<MangaNodeList> {
return dataFetchingEnvironment.getValueFromDataLoader<List<Int>, MangaNodeList>("MangaForIdsDataLoader", mangaIds)

View File

@@ -3,18 +3,18 @@ package suwayomi.tachidesk.graphql.types
data class WebUIUpdateInfo(
val channel: String,
val tag: String,
val updateAvailable: Boolean
val updateAvailable: Boolean,
)
enum class UpdateState {
STOPPED,
DOWNLOADING,
FINISHED,
ERROR
ERROR,
}
data class WebUIUpdateStatus(
val info: WebUIUpdateInfo,
val state: UpdateState,
val progress: Int
val progress: Int,
)