mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2025-01-23 22:21:09 +01:00
pages api done
This commit is contained in:
parent
21c0ea4e90
commit
5d9173d3f7
@ -1,6 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.source.model
|
package eu.kanade.tachiyomi.source.model
|
||||||
|
|
||||||
//import android.net.Uri
|
import android.net.Uri
|
||||||
import eu.kanade.tachiyomi.network.ProgressListener
|
import eu.kanade.tachiyomi.network.ProgressListener
|
||||||
import rx.subjects.Subject
|
import rx.subjects.Subject
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ open class Page(
|
|||||||
val index: Int,
|
val index: Int,
|
||||||
val url: String = "",
|
val url: String = "",
|
||||||
var imageUrl: String? = null,
|
var imageUrl: String? = null,
|
||||||
// @Transient var uri: Uri? = null // Deprecated but can't be deleted due to extensions
|
@Transient var uri: Uri? = null // Deprecated but can't be deleted due to extensions
|
||||||
): ProgressListener {
|
): ProgressListener {
|
||||||
|
|
||||||
val number: Int
|
val number: Int
|
||||||
|
@ -12,7 +12,7 @@ interface SChapter : Serializable {
|
|||||||
|
|
||||||
var chapter_number: Float
|
var chapter_number: Float
|
||||||
|
|
||||||
var scanlator: String?
|
var scanlator: String?
|
||||||
|
|
||||||
fun copyFrom(other: SChapter) {
|
fun copyFrom(other: SChapter) {
|
||||||
name = other.name
|
name = other.name
|
||||||
|
@ -76,12 +76,15 @@ class Main {
|
|||||||
ctx.json(getManga(mangaId))
|
ctx.json(getManga(mangaId))
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get("/api/v1/chapters/:mangaId/") { ctx ->
|
app.get("/api/v1/manga/:mangaId/chapters") { ctx ->
|
||||||
val mangaId = ctx.pathParam("mangaId").toInt()
|
val mangaId = ctx.pathParam("mangaId").toInt()
|
||||||
ctx.json(getChapterList(mangaId))
|
ctx.json(getChapterList(mangaId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.get("/api/v1/chapter/:chapterId") { ctx ->
|
||||||
|
val chapterId = ctx.pathParam("chapterId").toInt()
|
||||||
|
ctx.json(getPages(chapterId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package ir.armor.tachidesk.database
|
package ir.armor.tachidesk.database
|
||||||
|
|
||||||
import ir.armor.tachidesk.Config
|
import ir.armor.tachidesk.Config
|
||||||
|
import ir.armor.tachidesk.database.table.ChapterTable
|
||||||
import ir.armor.tachidesk.database.table.ExtensionsTable
|
import ir.armor.tachidesk.database.table.ExtensionsTable
|
||||||
import ir.armor.tachidesk.database.table.MangaTable
|
import ir.armor.tachidesk.database.table.MangaTable
|
||||||
import ir.armor.tachidesk.database.table.SourceTable
|
import ir.armor.tachidesk.database.table.SourceTable
|
||||||
@ -22,5 +23,6 @@ fun makeDataBaseTables() {
|
|||||||
SchemaUtils.create(ExtensionsTable)
|
SchemaUtils.create(ExtensionsTable)
|
||||||
SchemaUtils.create(SourceTable)
|
SchemaUtils.create(SourceTable)
|
||||||
SchemaUtils.create(MangaTable)
|
SchemaUtils.create(MangaTable)
|
||||||
|
SchemaUtils.create(ChapterTable)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,11 @@
|
|||||||
package ir.armor.tachidesk.database.dataclass
|
package ir.armor.tachidesk.database.dataclass
|
||||||
|
|
||||||
data class ChapterDataClass(
|
data class ChapterDataClass(
|
||||||
|
val id: Int,
|
||||||
val url: String,
|
val url: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
val date_upload: String,
|
val date_upload: Long,
|
||||||
val chapter_number: Float,
|
val chapter_number: Float,
|
||||||
val scanlator: String?,
|
val scanlator: String?,
|
||||||
|
val mangaId: Int,
|
||||||
)
|
)
|
@ -0,0 +1,6 @@
|
|||||||
|
package ir.armor.tachidesk.database.dataclass
|
||||||
|
|
||||||
|
data class PageDataClass(
|
||||||
|
val index: Int,
|
||||||
|
var imageUrl: String,
|
||||||
|
)
|
@ -0,0 +1,14 @@
|
|||||||
|
package ir.armor.tachidesk.database.table
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
|
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||||
|
|
||||||
|
object ChapterTable : IntIdTable() {
|
||||||
|
val url = varchar("url", 2048)
|
||||||
|
val name = varchar("name", 512)
|
||||||
|
val date_upload = long("date_upload").default(0)
|
||||||
|
val chapter_number = float("chapter_number").default(-1f)
|
||||||
|
val scanlator = varchar("scanlator",128).nullable()
|
||||||
|
|
||||||
|
val manga = reference("manga", MangaTable)
|
||||||
|
}
|
87
server/src/main/kotlin/ir/armor/tachidesk/util/Chapter.kt
Normal file
87
server/src/main/kotlin/ir/armor/tachidesk/util/Chapter.kt
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package ir.armor.tachidesk.util
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
|
import ir.armor.tachidesk.database.dataclass.ChapterDataClass
|
||||||
|
import ir.armor.tachidesk.database.dataclass.PageDataClass
|
||||||
|
import ir.armor.tachidesk.database.entity.MangaEntity
|
||||||
|
import ir.armor.tachidesk.database.table.ChapterTable
|
||||||
|
import ir.armor.tachidesk.database.table.MangaTable
|
||||||
|
import org.jetbrains.exposed.sql.insertAndGetId
|
||||||
|
import org.jetbrains.exposed.sql.select
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
|
|
||||||
|
fun getChapterList(mangaId: Int): List<ChapterDataClass> {
|
||||||
|
val mangaDetails = getManga(mangaId)
|
||||||
|
val source = getHttpSource(mangaDetails.sourceId)
|
||||||
|
|
||||||
|
val chapterList = source.fetchChapterList(
|
||||||
|
SManga.create().apply {
|
||||||
|
title = mangaDetails.title
|
||||||
|
url = mangaDetails.url
|
||||||
|
}
|
||||||
|
).toBlocking().first()
|
||||||
|
|
||||||
|
return transaction {
|
||||||
|
chapterList.forEach { fetchedChapter ->
|
||||||
|
val chapterEntry = ChapterTable.select { ChapterTable.url eq fetchedChapter.url }.firstOrNull()
|
||||||
|
if (chapterEntry == null) {
|
||||||
|
ChapterTable.insertAndGetId {
|
||||||
|
it[url] = fetchedChapter.url
|
||||||
|
it[name] = fetchedChapter.name
|
||||||
|
it[date_upload] = fetchedChapter.date_upload
|
||||||
|
it[chapter_number] = fetchedChapter.chapter_number
|
||||||
|
it[scanlator] = fetchedChapter.scanlator
|
||||||
|
|
||||||
|
it[manga] = mangaId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return@transaction chapterList.map {
|
||||||
|
ChapterDataClass(
|
||||||
|
ChapterTable.select { ChapterTable.url eq it.url }.firstOrNull()!![ChapterTable.id].value,
|
||||||
|
it.url,
|
||||||
|
it.name,
|
||||||
|
it.date_upload,
|
||||||
|
it.chapter_number,
|
||||||
|
it.scanlator,
|
||||||
|
mangaId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getPages(chapterId: Int): List<PageDataClass> {
|
||||||
|
return transaction {
|
||||||
|
val chapterEntry = ChapterTable.select { ChapterTable.id eq chapterId }.firstOrNull()!!
|
||||||
|
val mangaId = chapterEntry[ChapterTable.manga].value
|
||||||
|
val mangaEntry = MangaTable.select { MangaTable.id eq mangaId }.firstOrNull()!!
|
||||||
|
val source = getHttpSource(mangaEntry[MangaTable.sourceReference].value)
|
||||||
|
|
||||||
|
val pagesList = source.fetchPageList(
|
||||||
|
SChapter.create().apply {
|
||||||
|
url = chapterEntry[ChapterTable.url]
|
||||||
|
name = chapterEntry[ChapterTable.name]
|
||||||
|
}
|
||||||
|
).toBlocking().first()
|
||||||
|
|
||||||
|
return@transaction pagesList.map {
|
||||||
|
PageDataClass(
|
||||||
|
it.index,
|
||||||
|
getTrueImageUrl(it,source)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTrueImageUrl(page: Page, source: HttpSource): String {
|
||||||
|
return if ( page.imageUrl == null){
|
||||||
|
source.fetchImageUrl(page).toBlocking().first()!!
|
||||||
|
} else page.imageUrl!!
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package ir.armor.tachidesk.util
|
package ir.armor.tachidesk.util
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import ir.armor.tachidesk.database.dataclass.ChapterDataClass
|
|
||||||
import ir.armor.tachidesk.database.dataclass.MangaDataClass
|
import ir.armor.tachidesk.database.dataclass.MangaDataClass
|
||||||
import ir.armor.tachidesk.database.table.MangaStatus
|
import ir.armor.tachidesk.database.table.MangaStatus
|
||||||
import ir.armor.tachidesk.database.table.MangaTable
|
import ir.armor.tachidesk.database.table.MangaTable
|
||||||
@ -77,24 +76,3 @@ fun getManga(mangaId: Int): MangaDataClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getChapterList(mangaId: Int): List<ChapterDataClass> {
|
|
||||||
val mangaDetails = getManga(mangaId)
|
|
||||||
val source = getHttpSource(mangaDetails.sourceId)
|
|
||||||
|
|
||||||
val chapterList = source.fetchChapterList(
|
|
||||||
SManga.create().apply {
|
|
||||||
title = mangaDetails.title
|
|
||||||
url = mangaDetails.url
|
|
||||||
}
|
|
||||||
).toBlocking().first()
|
|
||||||
|
|
||||||
return chapterList.map {
|
|
||||||
ChapterDataClass(
|
|
||||||
it.url,
|
|
||||||
it.name,
|
|
||||||
it.date_upload.toString(),
|
|
||||||
it.chapter_number,
|
|
||||||
it.scanlator,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -39,6 +39,8 @@ export default function ChapterCard(props: IProps) {
|
|||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { chapter } = props;
|
const { chapter } = props;
|
||||||
|
|
||||||
|
const dateStr = chapter.date_upload && new Date(chapter.date_upload).toISOString().slice(0, 10);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<li>
|
<li>
|
||||||
@ -53,13 +55,12 @@ export default function ChapterCard(props: IProps) {
|
|||||||
<Typography variant="caption" display="block" gutterBottom>
|
<Typography variant="caption" display="block" gutterBottom>
|
||||||
{chapter.scanlator}
|
{chapter.scanlator}
|
||||||
{chapter.scanlator && ' '}
|
{chapter.scanlator && ' '}
|
||||||
{chapter.date_upload
|
{dateStr}
|
||||||
&& new Date(chapter.date_upload).toISOString().slice(0, 10)}
|
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: 'flex' }}>
|
<div style={{ display: 'flex' }}>
|
||||||
<Button variant="outlined" style={{ marginLeft: 20 }} onClick={() => { /* window.location.href = 'sources/popular/'; */ }}>open</Button>
|
<Button variant="outlined" style={{ marginLeft: 20 }} onClick={() => { window.location.href = `http://127.0.0.1:4567/api/v1/chapter/${chapter.id}`; }}>open</Button>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
@ -16,7 +16,7 @@ export default function Manga() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`http://127.0.0.1:4567/api/v1/chapters/${id}/`)
|
fetch(`http://127.0.0.1:4567/api/v1/manga/${id}/chapters`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => setChapters(data));
|
.then((data) => setChapters(data));
|
||||||
}, []);
|
}, []);
|
||||||
|
4
webUI/react/src/typings.d.ts
vendored
4
webUI/react/src/typings.d.ts
vendored
@ -23,9 +23,11 @@ interface IManga {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IChapter {
|
interface IChapter {
|
||||||
|
id: number
|
||||||
url: string
|
url: string
|
||||||
name: string
|
name: string
|
||||||
date_upload: string
|
date_upload: number
|
||||||
chapter_number: number
|
chapter_number: number
|
||||||
scanlator: String
|
scanlator: String
|
||||||
|
mangaId: number
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user