2021-05-27 01:55:21 +04:30
|
|
|
package suwayomi.tachidesk.impl
|
2020-12-25 13:17:41 +03:30
|
|
|
|
2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-01-26 23:32:12 +03:30
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
2021-03-25 16:53:36 +04:30
|
|
|
import mu.KotlinLogging
|
2020-12-25 13:17:41 +03:30
|
|
|
import org.jetbrains.exposed.sql.select
|
|
|
|
|
import org.jetbrains.exposed.sql.selectAll
|
|
|
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
2021-05-27 01:55:21 +04:30
|
|
|
import suwayomi.tachidesk.impl.extension.Extension.getExtensionIconUrl
|
|
|
|
|
import suwayomi.tachidesk.impl.util.GetHttpSource.getHttpSource
|
2021-05-27 02:21:53 +04:30
|
|
|
import suwayomi.tachidesk.model.table.ExtensionTable
|
|
|
|
|
import suwayomi.tachidesk.model.table.SourceTable
|
2021-05-27 01:55:21 +04:30
|
|
|
import suwayomi.tachidesk.model.dataclass.SourceDataClass
|
2020-12-25 18:45:33 +03:30
|
|
|
|
2021-03-30 21:04:06 +04:30
|
|
|
object Source {
|
2021-03-30 21:10:41 +04:30
|
|
|
private val logger = KotlinLogging.logger {}
|
2021-03-25 16:53:36 +04:30
|
|
|
|
2021-03-30 21:10:41 +04:30
|
|
|
fun getSourceList(): List<SourceDataClass> {
|
|
|
|
|
return transaction {
|
|
|
|
|
SourceTable.selectAll().map {
|
|
|
|
|
SourceDataClass(
|
|
|
|
|
it[SourceTable.id].value.toString(),
|
|
|
|
|
it[SourceTable.name],
|
|
|
|
|
it[SourceTable.lang],
|
|
|
|
|
getExtensionIconUrl(ExtensionTable.select { ExtensionTable.id eq it[SourceTable.extension] }.first()[ExtensionTable.apkName]),
|
|
|
|
|
getHttpSource(it[SourceTable.id].value).supportsLatest
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-12-25 13:17:41 +03:30
|
|
|
}
|
|
|
|
|
}
|
2021-01-22 17:00:33 +03:30
|
|
|
|
2021-03-30 21:10:41 +04:30
|
|
|
fun getSource(sourceId: Long): SourceDataClass {
|
|
|
|
|
return transaction {
|
|
|
|
|
val source = SourceTable.select { SourceTable.id eq sourceId }.firstOrNull()
|
2021-01-22 17:00:33 +03:30
|
|
|
|
2021-03-30 21:10:41 +04:30
|
|
|
SourceDataClass(
|
|
|
|
|
sourceId.toString(),
|
|
|
|
|
source?.get(SourceTable.name),
|
|
|
|
|
source?.get(SourceTable.lang),
|
|
|
|
|
source?.let { ExtensionTable.select { ExtensionTable.id eq source[SourceTable.extension] }.first()[ExtensionTable.iconUrl] },
|
|
|
|
|
source?.let { getHttpSource(sourceId).supportsLatest }
|
|
|
|
|
)
|
|
|
|
|
}
|
2021-01-22 17:00:33 +03:30
|
|
|
}
|
|
|
|
|
}
|