Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Feb 7, 2024
1 parent dbee116 commit fc4a9d0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fr.shikkanime.controllers.site

import com.google.inject.Inject
import fr.shikkanime.entities.SortParameter
import fr.shikkanime.entities.enums.ConfigPropertyKey
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.entities.enums.Link
import fr.shikkanime.services.caches.AnimeCacheService
Expand Down Expand Up @@ -37,7 +36,6 @@ class SiteController {
return Response.template(
Link.HOME,
mutableMapOf(
"description" to configCacheService.getValueAsString(ConfigPropertyKey.SEO_DESCRIPTION),
"animes" to animeCacheService.findAllBy(
CountryCode.FR,
null,
Expand Down Expand Up @@ -99,7 +97,6 @@ class SiteController {
return Response.template(
Link.CATALOG,
mutableMapOf(
"description" to configCacheService.getValueAsString(ConfigPropertyKey.SEO_DESCRIPTION),
"simulcasts" to findAll,
"currentSimulcast" to currentSimulcast,
"animes" to animeCacheService.findAllBy(
Expand All @@ -118,7 +115,7 @@ class SiteController {
private fun error404(): Response {
return Response.template(
"/site/404.ftl",
"Page introuvable",
"Page introuvable"

Check warning on line 118 in src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt#L118

Added line #L118 was not covered by tests
)
}

Expand All @@ -131,7 +128,6 @@ class SiteController {
"/site/anime.ftl",
anime.shortName,
mutableMapOf(
"description" to configCacheService.getValueAsString(ConfigPropertyKey.SEO_DESCRIPTION),
"anime" to anime,
"episodes" to episodeCacheService.findAllBy(
CountryCode.FR,
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/fr/shikkanime/plugins/Routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package fr.shikkanime.plugins

import fr.shikkanime.dtos.TokenDto
import fr.shikkanime.entities.LinkObject
import fr.shikkanime.entities.enums.ConfigPropertyKey
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.entities.enums.Platform
import fr.shikkanime.services.caches.ConfigCacheService
import fr.shikkanime.utils.Constant
import fr.shikkanime.utils.LoggerFactory
import fr.shikkanime.utils.routes.*
Expand Down Expand Up @@ -216,6 +218,11 @@ private suspend fun handleRequest(
try {
val response = callMethodWithParameters(method, controller, call, parameters)

if (method.hasAnnotation<Cached>()) {
val cached = method.findAnnotation<Cached>()!!.maxAgeSeconds
call.caching = CachingOptions(CacheControl.MaxAge(maxAgeSeconds = cached))

Check warning on line 223 in src/main/kotlin/fr/shikkanime/plugins/Routing.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/fr/shikkanime/plugins/Routing.kt#L222-L223

Added lines #L222 - L223 were not covered by tests
}

response.session?.let { call.sessions.set(it) }

when (response.type) {
Expand All @@ -236,6 +243,7 @@ private suspend fun handleMultipartResponse(call: ApplicationCall, response: Res
}

private suspend fun handleTemplateResponse(call: ApplicationCall, controller: Any, replacedPath: String, response: Response) {
val configCacheService = Constant.injector.getInstance(ConfigCacheService::class.java)
val map = response.data as Map<String, Any>
val modelMap = (map["model"] as Map<String, Any>).toMutableMap()

Expand All @@ -251,6 +259,7 @@ private suspend fun handleTemplateResponse(call: ApplicationCall, controller: An

val title = map["title"] as String?
modelMap["title"] = if (title?.contains(Constant.NAME) == true) title else (if (!title.isNullOrBlank()) "$title - " else "") + Constant.NAME
modelMap["description"] = configCacheService.getValueAsString(ConfigPropertyKey.SEO_DESCRIPTION) ?: ""

call.respond(FreeMarkerContent(map["template"] as String, modelMap, "", response.contentType))
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/site/anime.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="container">
<div class="row g-3 mt-3">
<div class="col-md-4 col-12 mt-0 text-center">
<img src="https://api.shikkanime.fr/v1/attachments?uuid=${anime.uuid}&type=image"
<img loading="lazy" src="https://api.shikkanime.fr/v1/attachments?uuid=${anime.uuid}&type=image"
alt="${anime.shortName?replace("\"", "'")} anime image" class="w-50">
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/site/components/anime.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<article>
<a href="/animes/${anime.uuid}" class="text-decoration-none text-white">
<div class="hover-card position-relative">
<img src="https://api.shikkanime.fr/v1/attachments?uuid=${anime.uuid}&type=image"
<img loading="lazy" src="https://api.shikkanime.fr/v1/attachments?uuid=${anime.uuid}&type=image"
alt="${anime.shortName?replace("\"", "'")} anime image" class="w-100">
<span class="h6 mt-2 text-truncate-2">${anime.shortName}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/site/components/episode.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a href="${episode.url}" target="_blank" class="text-decoration-none text-white">
<div class="hover-card position-relative">
<div class="position-relative">
<img src="https://api.shikkanime.fr/v1/attachments?uuid=${episode.uuid}&type=image"
<img loading="lazy" src="https://api.shikkanime.fr/v1/attachments?uuid=${episode.uuid}&type=image"
alt="${episode.anime.shortName?replace("\"", "'")} episode preview image"
class="w-100<#if episode.uncensored> blur</#if>">
<img src="https://www.shikkanime.fr/assets/img/platforms/${episode.platform.image}"
Expand Down

0 comments on commit fc4a9d0

Please sign in to comment.