-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
214 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
server/src/main/kotlin/suwayomi/tachidesk/manga/model/dataclass/OpdsDataClass.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package suwayomi.tachidesk.manga.model.dataclass | ||
|
||
import kotlinx.serialization.Serializable | ||
import nl.adaptivity.xmlutil.serialization.XmlElement | ||
import nl.adaptivity.xmlutil.serialization.XmlSerialName | ||
import nl.adaptivity.xmlutil.serialization.XmlValue | ||
|
||
@Serializable | ||
@XmlSerialName("feed", "", "") | ||
data class OpdsDataClass( | ||
@XmlElement(true) | ||
val id: String, | ||
@XmlElement(true) | ||
val title: String, | ||
@XmlElement(true) | ||
val icon: String? = null, | ||
@XmlElement(true) | ||
val updated: String, // ISO-8601 | ||
@XmlElement(true) | ||
val author: Author? = null, | ||
@XmlElement(true) | ||
val links: List<Link>, | ||
@XmlElement(true) | ||
val entries: List<Entry>, | ||
@XmlSerialName("xmlns", "", "") | ||
val xmlns: String = "http://www.w3.org/2005/Atom", | ||
@XmlSerialName("xmlns:xsd", "", "") | ||
val xmlnsXsd: String = "http://www.w3.org/2001/XMLSchema", | ||
@XmlSerialName("xmlns:xsi", "", "") | ||
val xmlnsXsi: String = "http://www.w3.org/2001/XMLSchema-instance", | ||
@XmlSerialName("xmlns:opds", "", "") | ||
val xmlnsOpds: String = "http://opds-spec.org/2010/catalog", | ||
@XmlSerialName("xmlns:dcterms", "", "") | ||
val xmlnsDublinCore: String = "http://purl.org/dc/terms/", | ||
@XmlSerialName("xmlns:pse", "", "") | ||
val xmlnsPse: String = "http://vaemendis.net/opds-pse/ns", | ||
@XmlElement(true) | ||
@XmlSerialName("totalResults", "http://a9.com/-/spec/opensearch/1.1/", "") | ||
val totalResults: Long? = null, | ||
@XmlElement(true) | ||
@XmlSerialName("itemsPerPage", "http://a9.com/-/spec/opensearch/1.1/", "") | ||
val itemsPerPage: Int? = null, | ||
@XmlElement(true) | ||
@XmlSerialName("startIndex", "http://a9.com/-/spec/opensearch/1.1/", "") | ||
val startIndex: Int? = null, | ||
) { | ||
@Serializable | ||
@XmlSerialName("author", "", "") | ||
data class Author( | ||
@XmlElement(true) | ||
val name: String, | ||
@XmlElement(true) | ||
val uri: String? = null, | ||
@XmlElement(true) | ||
val email: String? = null, | ||
) | ||
|
||
@Serializable | ||
@XmlSerialName("link", "", "") | ||
data class Link( | ||
val rel: String, | ||
val href: String, | ||
val type: String? = null, | ||
val title: String? = null, | ||
@XmlSerialName("pse:count", "", "") | ||
val pseCount: Int? = null, | ||
) | ||
|
||
@Serializable | ||
@XmlSerialName("entry", "", "") | ||
data class Entry( | ||
@XmlElement(true) | ||
val id: String, | ||
@XmlElement(true) | ||
val title: String, | ||
@XmlElement(true) | ||
val updated: String, | ||
@XmlElement(true) | ||
val summary: Summary? = null, | ||
@XmlElement(true) | ||
val content: Content? = null, | ||
@XmlElement(true) | ||
val link: List<Link>, | ||
@XmlElement(true) | ||
val authors: List<Author>? = null, | ||
@XmlElement(true) | ||
val categories: List<Category>? = null, | ||
@XmlElement(true) | ||
@XmlSerialName("language", "http://purl.org/dc/terms/", "dc") | ||
val extent: String? = null, | ||
@XmlElement(true) | ||
@XmlSerialName("format", "http://purl.org/dc/terms/format", "dc") | ||
val format: String? = null, | ||
) | ||
|
||
@Serializable | ||
@XmlSerialName("summary", "", "") | ||
data class Summary( | ||
val type: String = "text", | ||
@XmlValue(true) val value: String = "", | ||
) | ||
|
||
@Serializable | ||
@XmlSerialName("content", "", "") | ||
data class Content( | ||
val type: String = "text", | ||
@XmlValue(true) val value: String = "", | ||
) | ||
|
||
@Serializable | ||
@XmlSerialName("category", "", "") | ||
data class Category( | ||
val scheme: String? = null, | ||
val term: String, | ||
val label: String, | ||
) | ||
} |
86 changes: 86 additions & 0 deletions
86
server/src/main/kotlin/suwayomi/tachidesk/opds/controller/OpdsController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package suwayomi.tachidesk.opds.controller | ||
|
||
import io.javalin.http.HttpStatus | ||
import suwayomi.tachidesk.opds.impl.Opds | ||
import suwayomi.tachidesk.server.JavalinSetup.future | ||
import suwayomi.tachidesk.server.util.handler | ||
import suwayomi.tachidesk.server.util.pathParam | ||
import suwayomi.tachidesk.server.util.queryParam | ||
import suwayomi.tachidesk.server.util.withOperation | ||
|
||
object OpdsController { | ||
private const val OPDS_MIME = "application/xml;profile=opds-catalog;charset=UTF-8" | ||
private const val BASE_URL = "/api/opds/v1.2" | ||
|
||
val rootFeed = | ||
handler( | ||
documentWith = { | ||
withOperation { | ||
summary("OPDS Root Feed") | ||
description("OPDS feed for the list of available manga sources") | ||
} | ||
}, | ||
behaviorOf = { ctx -> | ||
ctx.future { | ||
future { | ||
Opds.getRootFeed(BASE_URL) | ||
}.thenApply { xml -> | ||
ctx.contentType(OPDS_MIME).result(xml) | ||
} | ||
} | ||
}, | ||
withResults = { | ||
httpCode(HttpStatus.OK) | ||
}, | ||
) | ||
|
||
val sourceFeed = | ||
handler( | ||
pathParam<Long>("sourceId"), | ||
queryParam<Int?>("pageNumber"), | ||
documentWith = { | ||
withOperation { | ||
summary("OPDS Source Feed") | ||
description("OPDS feed for a specific manga source") | ||
} | ||
}, | ||
behaviorOf = { ctx, sourceId, pageNumber -> | ||
ctx.future { | ||
future { | ||
Opds.getSourceFeed(sourceId, BASE_URL, pageNumber ?: 1) | ||
}.thenApply { xml -> | ||
ctx.contentType(OPDS_MIME).result(xml) | ||
} | ||
} | ||
}, | ||
withResults = { | ||
httpCode(HttpStatus.OK) | ||
httpCode(HttpStatus.NOT_FOUND) | ||
}, | ||
) | ||
|
||
val mangaFeed = | ||
handler( | ||
pathParam<Int>("mangaId"), | ||
queryParam<Int?>("pageNumber"), | ||
documentWith = { | ||
withOperation { | ||
summary("OPDS Manga Feed") | ||
description("OPDS feed for chapters of a specific manga") | ||
} | ||
}, | ||
behaviorOf = { ctx, mangaId, pageNumber -> | ||
ctx.future { | ||
future { | ||
Opds.getMangaFeed(mangaId, BASE_URL, pageNumber ?: 1) | ||
}.thenApply { xml -> | ||
ctx.contentType(OPDS_MIME).result(xml) | ||
} | ||
} | ||
}, | ||
withResults = { | ||
httpCode(HttpStatus.OK) | ||
httpCode(HttpStatus.NOT_FOUND) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters