mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2025-01-22 21:51:13 +01:00
Manga database classes, api url change, fix source id
This commit is contained in:
parent
5597ad66b4
commit
ab33a0ef1d
@ -20,21 +20,32 @@ class Main {
|
||||
ctx.header("Access-Control-Allow-Origin", "*") // allow the client which is running on another port
|
||||
}
|
||||
|
||||
app.get("/api/v1/extensions") { ctx ->
|
||||
app.get("/api/v1/extension/list") { ctx ->
|
||||
ctx.json(getExtensionList())
|
||||
}
|
||||
|
||||
|
||||
app.get("/api/v1/extensions/install/:apkName") { ctx ->
|
||||
app.get("/api/v1/extension/install/:apkName") { ctx ->
|
||||
val apkName = ctx.pathParam("apkName")
|
||||
println(apkName)
|
||||
ctx.status(
|
||||
installAPK(apkName)
|
||||
)
|
||||
}
|
||||
app.get("/api/v1/sources/") { ctx ->
|
||||
app.get("/api/v1/source/list") { ctx ->
|
||||
ctx.json(getSourceList())
|
||||
}
|
||||
|
||||
app.get("/api/v1/source/:source_id/popular") { ctx ->
|
||||
val sourceId = ctx.pathParam("source_id")
|
||||
ctx.json(getPopularManga(sourceId))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun getPopularManga(sourceId: String): List<Any> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package ir.armor.tachidesk.database
|
||||
|
||||
import ir.armor.tachidesk.Config
|
||||
import ir.armor.tachidesk.database.table.ExtensionsTable
|
||||
import ir.armor.tachidesk.database.table.MangasTable
|
||||
import ir.armor.tachidesk.database.table.SourcesTable
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.jetbrains.exposed.sql.SchemaUtils
|
||||
@ -20,5 +21,6 @@ fun makeDataBaseTables() {
|
||||
transaction {
|
||||
SchemaUtils.create(ExtensionsTable)
|
||||
SchemaUtils.create(SourcesTable)
|
||||
SchemaUtils.create(MangasTable)
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package ir.armor.tachidesk.database.dataclass
|
||||
|
||||
import ir.armor.tachidesk.database.table.MangaStatus
|
||||
|
||||
data class MangaDataClass(
|
||||
val sourceId: Long,
|
||||
|
||||
val url: String,
|
||||
val title: String,
|
||||
val thumbnail_url: String? = null,
|
||||
|
||||
val initialized: Boolean = false,
|
||||
|
||||
val artist: String? = null,
|
||||
val author: String? = null,
|
||||
val description: String? = null,
|
||||
val genre: String? = null,
|
||||
val status: String = MangaStatus.UNKNOWN.name
|
||||
)
|
@ -0,0 +1,24 @@
|
||||
package ir.armor.tachidesk.database.entity
|
||||
|
||||
import ir.armor.tachidesk.database.table.MangasTable
|
||||
import ir.armor.tachidesk.database.table.SourcesTable
|
||||
import org.jetbrains.exposed.dao.IntEntity
|
||||
import org.jetbrains.exposed.dao.IntEntityClass
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
|
||||
class MangaEntity(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<MangaEntity>(MangasTable)
|
||||
|
||||
var url by MangasTable.url
|
||||
var title by MangasTable.title
|
||||
var initialized by MangasTable.initialized
|
||||
|
||||
var artist by MangasTable.artist
|
||||
var author by MangasTable.author
|
||||
var description by MangasTable.description
|
||||
var genre by MangasTable.genre
|
||||
var status by MangasTable.status
|
||||
var thumbnail_url by MangasTable.thumbnail_url
|
||||
|
||||
var sourceReference by MangaEntity referencedOn MangasTable.sourceReference
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
package ir.armor.tachidesk.database.entity
|
||||
|
||||
import ir.armor.tachidesk.database.table.SourcesTable
|
||||
import org.jetbrains.exposed.dao.IntEntity
|
||||
import org.jetbrains.exposed.dao.IntEntityClass
|
||||
import org.jetbrains.exposed.dao.*
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
|
||||
class SourceEntity(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<SourceEntity>(SourcesTable)
|
||||
class SourceEntity(id: EntityID<Long>) : LongEntity(id) {
|
||||
companion object : EntityClass<Long, SourceEntity>(SourcesTable, null)
|
||||
|
||||
var sourceId by SourcesTable.sourceId
|
||||
var sourceId by SourcesTable.id
|
||||
var name by SourcesTable.name
|
||||
var lang by SourcesTable.lang
|
||||
var extension by ExtensionEntity referencedOn SourcesTable.extension
|
||||
|
@ -0,0 +1,26 @@
|
||||
package ir.armor.tachidesk.database.table
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
|
||||
object MangasTable : IntIdTable() {
|
||||
val url = varchar("url", 2048)
|
||||
val title = varchar("title", 512)
|
||||
val initialized = bool("initialized").default(false)
|
||||
|
||||
val artist = varchar("artist", 64).nullable()
|
||||
val author = varchar("author", 64).nullable()
|
||||
val description = varchar("description", 4096).nullable()
|
||||
val genre = varchar("genre", 1024).nullable()
|
||||
val status = enumeration("status", MangaStatus::class).default(MangaStatus.UNKNOWN)
|
||||
val thumbnail_url = varchar("thumbnail_url", 2048).nullable()
|
||||
|
||||
// source is used by some ancestor of IntIdTable
|
||||
val sourceReference = reference("source", SourcesTable)
|
||||
}
|
||||
|
||||
enum class MangaStatus(val status: Int) {
|
||||
UNKNOWN(0),
|
||||
ONGOING(1),
|
||||
COMPLETED(2),
|
||||
LICENSED(3),
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package ir.armor.tachidesk.database.table
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.dao.id.IdTable
|
||||
|
||||
object SourcesTable : IntIdTable() {
|
||||
val sourceId = long("source_id")
|
||||
val name = varchar("name", 128)
|
||||
object SourcesTable : IdTable<Long>() {
|
||||
override val id = long("id").entityId()
|
||||
val name= varchar("name", 128)
|
||||
val lang = varchar("lang", 5)
|
||||
val extension = reference("extension", ExtensionsTable)
|
||||
val partOfFactorySource = bool("part_of_factory_source").default(false)
|
||||
|
@ -68,9 +68,9 @@ fun installAPK(apkName: String): Int {
|
||||
// name = httpSource.name
|
||||
// this.extension = ExtensionEntity.find { ExtensionsTable.name eq extension.name }.first().id
|
||||
// }
|
||||
if (SourcesTable.select { SourcesTable.sourceId eq httpSource.id }.count() == 0L) {
|
||||
if (SourcesTable.select { SourcesTable.id eq httpSource.id }.count() == 0L) {
|
||||
SourcesTable.insert {
|
||||
it[this.sourceId] = httpSource.id
|
||||
it[this.id] = httpSource.id
|
||||
it[name] = httpSource.name
|
||||
it[this.lang] = httpSource.lang
|
||||
it[extension] = extensionId
|
||||
@ -86,9 +86,9 @@ fun installAPK(apkName: String): Int {
|
||||
transaction {
|
||||
sourceFactory.createSources().forEachIndexed { index, source ->
|
||||
val httpSource = source as HttpSource
|
||||
if (SourcesTable.select { SourcesTable.sourceId eq httpSource.id }.count() == 0L) {
|
||||
if (SourcesTable.select { SourcesTable.id eq httpSource.id }.count() == 0L) {
|
||||
SourcesTable.insert {
|
||||
it[this.sourceId] = httpSource.id
|
||||
it[this.id] = httpSource.id
|
||||
it[name] = httpSource.name
|
||||
it[this.lang] = httpSource.lang
|
||||
it[extension] = extensionId
|
||||
|
@ -0,0 +1,2 @@
|
||||
package ir.armor.tachidesk.util
|
||||
|
@ -18,7 +18,7 @@ import java.net.URLClassLoader
|
||||
|
||||
fun getHttpSource(sourceId: Long): HttpSource {
|
||||
return transaction {
|
||||
val sourceRecord = SourceEntity.find { SourcesTable.sourceId eq sourceId }.first()
|
||||
val sourceRecord = SourceEntity.get(sourceId)
|
||||
val extensionId = sourceRecord.extension.id.value
|
||||
val extensionRecord = ExtensionEntity.get(extensionId)
|
||||
val apkName = extensionRecord.apkName
|
||||
@ -44,11 +44,11 @@ fun getSourceList(): List<SourceDataClass> {
|
||||
return transaction {
|
||||
return@transaction SourcesTable.selectAll().map {
|
||||
SourceDataClass(
|
||||
it[SourcesTable.sourceId],
|
||||
it[SourcesTable.id].value,
|
||||
it[SourcesTable.name],
|
||||
it[SourcesTable.lang],
|
||||
ExtensionsTable.select { ExtensionsTable.id eq it[SourcesTable.extension] }.first()[ExtensionsTable.iconUrl],
|
||||
getHttpSource(it[SourcesTable.sourceId]).supportsLatest
|
||||
getHttpSource(it[SourcesTable.id].value).supportsLatest
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ function Extensions() {
|
||||
|
||||
if (extensions.length === 0) {
|
||||
mapped = <h3>wait</h3>;
|
||||
fetch('http://127.0.0.1:4567/api/v1/extensions')
|
||||
fetch('http://127.0.0.1:4567/api/v1/extension/list')
|
||||
.then((response) => response.json())
|
||||
.then((data) => setExtensions(data));
|
||||
} else {
|
||||
@ -31,7 +31,7 @@ function Sources() {
|
||||
|
||||
if (sources.length === 0) {
|
||||
mapped = <h3>wait</h3>;
|
||||
fetch('http://127.0.0.1:4567/api/v1/sources')
|
||||
fetch('http://127.0.0.1:4567/api/v1/source/list')
|
||||
.then((response) => response.json())
|
||||
.then((data) => setSources(data));
|
||||
} else {
|
||||
|
@ -49,7 +49,7 @@ export default function ExtensionCard(props: IProps) {
|
||||
|
||||
function install() {
|
||||
setInstalledState('installing');
|
||||
fetch(`http://127.0.0.1:4567/api/v1/extensions/install/${apkName}`).then(() => {
|
||||
fetch(`http://127.0.0.1:4567/api/v1/extension/install/${apkName}`).then(() => {
|
||||
setInstalledState('installed');
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user