Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from Z-Jais/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Ziedelth authored Nov 7, 2022
2 parents 591125b + 70c0d90 commit c2681fc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
46 changes: 40 additions & 6 deletions src/main/kotlin/fr/ziedelth/controllers/MangaController.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package fr.ziedelth.controllers

import com.google.gson.Gson
import fr.ziedelth.entities.Manga
import fr.ziedelth.entities.isNullOrNotValid
import fr.ziedelth.events.MangasReleaseEvent
import fr.ziedelth.utils.Database
import fr.ziedelth.utils.Decoder
import fr.ziedelth.utils.ImageCache
import fr.ziedelth.utils.RequestCache
import fr.ziedelth.utils.plugins.PluginManager
Expand All @@ -20,6 +22,7 @@ object MangaController : IController<Manga>("/mangas") {
search()
getWithPage()
getAnimeWithPage()
getWatchlistWithPage()
getAttachment()
create()
}
Expand All @@ -35,8 +38,8 @@ object MangaController : IController<Manga>("/mangas") {

try {
val query = session.createQuery(
"FROM Manga WHERE anime.country.tag = :tag AND ean = :ean",
Manga::class.java
"FROM $entityName WHERE anime.country.tag = :tag AND ean = :ean",
entityClass
)
query.maxResults = 1
query.setParameter("tag", country)
Expand Down Expand Up @@ -67,8 +70,8 @@ object MangaController : IController<Manga>("/mangas") {

try {
val query = session.createQuery(
"FROM Manga WHERE anime.country.tag = :tag AND ean IS NOT NULL ORDER BY releaseDate DESC, anime.name",
Manga::class.java
"FROM $entityName WHERE anime.country.tag = :tag AND ean IS NOT NULL ORDER BY releaseDate DESC, anime.name",
entityClass
)
query.setParameter("tag", country)
query.firstResult = (limit * page) - limit
Expand Down Expand Up @@ -104,8 +107,8 @@ object MangaController : IController<Manga>("/mangas") {

try {
val query = session.createQuery(
"FROM Manga WHERE anime.uuid = :uuid ORDER BY releaseDate DESC, anime.name",
Manga::class.java
"FROM $entityName WHERE anime.uuid = :uuid ORDER BY releaseDate DESC, anime.name",
entityClass
)
query.setParameter("uuid", UUID.fromString(animeUuid))
query.firstResult = (limit * page) - limit
Expand All @@ -120,6 +123,37 @@ object MangaController : IController<Manga>("/mangas") {
}
}

private fun Route.getWatchlistWithPage() {
post("/watchlist/page/{page}/limit/{limit}") {
val watchlist = call.receive<String>()
val page = call.parameters["page"]?.toInt() ?: return@post call.respond(HttpStatusCode.BadRequest)
val limit = call.parameters["limit"]?.toInt() ?: return@post call.respond(HttpStatusCode.BadRequest)
if (page < 1 || limit < 1) return@post call.respond(HttpStatusCode.BadRequest)
if (limit > 30) return@post call.respond(HttpStatusCode.BadRequest)
println("POST $prefix/watchlist/page/$page/limit/$limit")
val session = Database.getSession()

try {
val dataFromGzip =
Gson().fromJson(Decoder.fromGzip(watchlist), Array<String>::class.java).map { UUID.fromString(it) }

val query = session.createQuery(
"FROM $entityName WHERE uuid IN :list ORDER BY releaseDate DESC, anime.name",
entityClass
)
query.setParameter("list", dataFromGzip)
query.firstResult = (limit * page) - limit
query.maxResults = limit
call.respond(query.list())
} catch (e: Exception) {
e.printStackTrace()
call.respond(HttpStatusCode.InternalServerError, e.message ?: "Unknown error")
} finally {
session.close()
}
}
}


private fun merge(manga: Manga) {
manga.platform =
Expand Down
14 changes: 13 additions & 1 deletion src/main/kotlin/fr/ziedelth/utils/plugins/JaisPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@ package fr.ziedelth.utils.plugins

import org.pf4j.Plugin
import org.pf4j.PluginWrapper
import java.io.File

abstract class JaisPlugin(pluginWrapper: PluginWrapper) : Plugin(pluginWrapper)
abstract class JaisPlugin(pluginWrapper: PluginWrapper) : Plugin(pluginWrapper) {
private val pluginsFolder = File("plugins")
get() {
if (!field.exists()) {
field.mkdirs()
}

return field
}

val dataFolder = File(pluginsFolder, pluginWrapper.pluginId)
}

0 comments on commit c2681fc

Please sign in to comment.