Skip to content

Commit

Permalink
Merge pull request #412 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ziedelth authored Apr 23, 2024
2 parents 679a8b6 + be3c077 commit a9a4ba0
Show file tree
Hide file tree
Showing 25 changed files with 133 additions and 53 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ on:
schedule:
- cron: '33 14 * * 5'

env:
GRADLE_OPTS: -Dorg.gradle.daemon=false -Dkotlin.incremental=false -Dorg.gradle.jvmargs="-Xmx4g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=1024m"

jobs:
analyze:
name: Analyze (${{ matrix.language }})
Expand All @@ -41,8 +44,8 @@ jobs:
fail-fast: false
matrix:
include:
#- language: java-kotlin
# build-mode: autobuild
# - language: java-kotlin
# build-mode: autobuild
- language: javascript-typescript
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
Expand Down
14 changes: 11 additions & 3 deletions src/main/kotlin/fr/shikkanime/controllers/site/SiteController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import fr.shikkanime.utils.routes.Path
import fr.shikkanime.utils.routes.Response
import fr.shikkanime.utils.routes.method.Get
import fr.shikkanime.utils.routes.param.PathParam
import fr.shikkanime.utils.routes.param.QueryParam
import io.ktor.http.*
import java.time.ZonedDateTime

Expand All @@ -39,7 +40,7 @@ class SiteController {
private fun error404(): Response {
return Response.template(
HttpStatusCode.NotFound,
"/site/404.ftl",
"/site/errors/404.ftl",
"Page introuvable"
)
}
Expand Down Expand Up @@ -148,8 +149,15 @@ class SiteController {

@Path("search")
@Get
private fun search(): Response {
return Response.template(Link.SEARCH)
private fun search(
@QueryParam("q") query: String?,
): Response {
return Response.template(
Link.SEARCH,
mutableMapOf(
"query" to query
)
)
}

@Path("calendar")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/fr/shikkanime/jobs/FetchCalendarJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FetchCalendarJob : AbstractJob {
val episodes = getEpisodes(elements, httpRequest)

val backgroundImage = getBackgroundImage() ?: return@use
val calendarImage = BufferedImage(backgroundImage.width, 800, BufferedImage.TYPE_INT_ARGB)
val calendarImage = BufferedImage(backgroundImage.width, 900, BufferedImage.TYPE_INT_ARGB)
val graphics = calendarImage.createGraphics()
graphics.setRenderingHints()
graphics.drawImage(backgroundImage, 0, 0, null)
Expand Down
18 changes: 6 additions & 12 deletions src/main/kotlin/fr/shikkanime/modules/HTTP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,8 @@ fun Application.configureHTTP() {
}
status(HttpStatusCode.NotFound) { call, _ ->
val path = call.request.path()

if (path.contains(".")) {
return@status
}

if (path.startsWith("/404")) {
return@status
}

if (!path.startsWith("/api") && !path.startsWith("/admin")) {
call.respondRedirect("/404")
}
if (isNotSiteRoute(path, "404")) return@status
call.respondRedirect("/404")
}
}
install(ContentNegotiation) {
Expand Down Expand Up @@ -77,3 +67,7 @@ fun Application.configureHTTP() {
}
}
}

private fun isNotSiteRoute(path: String, errorCode: String): Boolean {
return path.contains(".") || path.startsWith("/$errorCode") || (path.startsWith("/api") && path.startsWith("/admin"))
}
2 changes: 1 addition & 1 deletion src/main/kotlin/fr/shikkanime/modules/Routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private suspend fun handleRequest(
}
} catch (e: Exception) {
logger.log(Level.SEVERE, "Error while calling method $method", e)
call.respond(HttpStatusCode.BadRequest)
call.respond(HttpStatusCode.InternalServerError)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class PrimeVideoPlatform :
val releaseDateTimeUTC = zonedDateTime.withUTC()
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "T${key.primeVideoSimulcast.releaseTime}Z"
val releaseDateTime = ZonedDateTime.parse(releaseDateTimeUTC)

val episodes = PrimeVideoWrapper.getShowVideos(key.countryCode.name, key.countryCode.locale, id)

return episodes.map {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/assets/css/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
@font-face {
font-family: Satoshi;
src: url(/assets/fonts/Satoshi-Regular.woff2) format('woff2'),
url(/assets/fonts/Satoshi-Regular.woff) format('woff'),
url(/assets/fonts/Satoshi-Regular.ttf) format('truetype'),
url(/assets/fonts/Satoshi-Regular.eot) format('embedded-opentype');
}

body {
background-color: #000;
font-family: Satoshi, sans-serif;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/css/purged/bootstrap.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/assets/css/purged/main.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 11 additions & 0 deletions src/main/resources/purge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ echo "Removing old purged css..."
rm -rf $CSS_PURGED_PATH
echo "Creating new purged css directory..."
mkdir -p $CSS_PURGED_PATH

# Moving the excludes files
echo "Moving the excludes files..."
mv ./templates/site/_layout.ftl .
mv ./templates/site/presentation.ftl .

echo "Purging css..."
purgecss --config ./purgecss.config.js

# Moving back the excludes files
echo "Moving back the excludes files..."
mv _layout.ftl ./templates/site
mv presentation.ftl ./templates/site

# Minify the purged css
echo "Minifying purged css..."
minify $CSS_PURGED_PATH/main.css > $CSS_PURGED_PATH/main.min.css
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/_freemarker_implicit.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[#-- @ftlvariable name="seoLinks" type="kotlin.collections.AbstractList<fr.shikkanime.entities.enums.Link>" --]
[#-- @ftlvariable name="su" type="fr.shikkanime.utils.StringUtils" --]
[#-- @ftlvariable name="weeklyAnimes" type="kotlin.collections.AbstractList<fr.shikkanime.dtos.WeeklyAnimesDto>" --]
[#-- @ftlvariable name="query" type="java.lang.String" --]

[#-- @ftlvariable name="analyticsDomain" type="java.lang.String" --]
[#-- @ftlvariable name="analyticsApi" type="java.lang.String" --]
Expand Down
12 changes: 0 additions & 12 deletions src/main/resources/templates/site/404.ftl

This file was deleted.

2 changes: 0 additions & 2 deletions src/main/resources/templates/site/_layout.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@
</head>
<body>
<#nested 0>

<script src="/assets/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
</body>
</html>
</#macro>
6 changes: 4 additions & 2 deletions src/main/resources/templates/site/_navigation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
style="backdrop-filter: blur(0.5rem);">
<div class="container-fluid px-md-5 d-md-flex">
<a class="navbar-brand" href="/">
<img src="/assets/img/light_banner.webp" alt="Logo" width="181" height="24"
<img src="/assets/img/light_banner.webp" alt="Shikkanime" width="181" height="24"
class="d-inline-block align-text-top">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
Expand Down Expand Up @@ -44,7 +44,7 @@
<div class="col-md-4 d-flex align-items-center">
<div>
<a href="/" class="mb-3 me-2 mb-md-0 text-muted text-decoration-none lh-1">
<img src="/assets/img/favicons/favicon-64x64.png" alt="Logo" width="24" height="24">
<img src="/assets/img/favicons/favicon-64x64.png" alt="Shikkanime" width="24" height="24">
</a>

<#if seoDescription?? && seoDescription?length != 0>
Expand Down Expand Up @@ -117,5 +117,7 @@
</div>
</footer>
</div>

<script src="/assets/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
</@layout.main>
</#macro>
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 @@ -7,7 +7,7 @@
<div class="row g-3 mt-3">
<div class="col-md-4 col-12 mt-0 text-center">
<img src="${apiUrl}/v1/attachments?uuid=${anime.uuid}&type=image"
alt="${su.sanitizeXSS(anime.shortName)} anime image" class="img-fluid w-50 rounded-4"
alt="${su.sanitizeXSS(anime.shortName)} anime" class="img-fluid w-50 rounded-4"
width="480"
height="720">
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/templates/site/calendar.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
@mouseleave="hover = false">
<div class="position-relative">
<div class="position-relative">
<img src="${apiUrl}/v1/attachments?uuid=${release.anime.uuid}&type=banner"
alt="${su.sanitizeXSS(release.anime.shortName)} anime banner"
<img loading="lazy" src="${apiUrl}/v1/attachments?uuid=${release.anime.uuid}&type=banner"
alt="${su.sanitizeXSS(release.anime.shortName)} anime"
class="img-fluid rounded-top-4" width="640"
height="360">

<div class="position-absolute top-0 end-0 p-1">
<div class="d-flex">
<#list release.platforms as platform>
<img src="${baseUrl}/assets/img/platforms/${platform.image}"
alt="${platform.name} platform image"
alt="${platform.name}"
class="rounded-circle me-1" width="20"
height="20">
</#list>
Expand All @@ -54,7 +54,7 @@
</div>

<div class="bg-black bg-opacity-75 bg-blur position-absolute top-0 start-0 w-100 h-100 mh-100 p-3 rounded-4"
x-show="hover">
style="display: none;" x-show="hover">
<#if release.anime.description??>
<div class="text-truncate-6">
${release.anime.description}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/site/components/anime.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@mouseleave="hover = false">
<div class="position-relative">
<img src="${apiUrl}/v1/attachments?uuid=${anime.uuid}&type=image"
alt="${su.sanitizeXSS(anime.shortName)} anime image" class="img-fluid rounded-top-4"
alt="${su.sanitizeXSS(anime.shortName)} anime" class="img-fluid rounded-top-4"
width="480"
height="720">

Expand All @@ -20,7 +20,7 @@
</div>

<div class="bg-black bg-opacity-75 bg-blur position-absolute top-0 start-0 w-100 h-100 mh-100 p-3 rounded-top-4"
x-show="hover">
style="display: none;" x-show="hover">
<div class="h6 text-truncate-2 fw-bold">
${anime.shortName?upper_case}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
<div class="position-relative">
<div class="position-relative">
<img src="${apiUrl}/v1/attachments?uuid=${episodeMapping.uuid}&type=image"
alt="${su.sanitizeXSS(episodeMapping.anime.shortName)} episode preview image"
alt="${su.sanitizeXSS(episodeMapping.anime.shortName)} episode preview"
class="<#if cover>w-100 object-fit-cover<#else>img-fluid</#if> rounded-top-4"
width="640" height="360">

<div class="position-absolute top-0 end-0 mt-1 d-flex">
<#list episodeMapping.platforms as platform>
<img src="${baseUrl}/assets/img/platforms/${platform.image}"
alt="${platform.name} platform image"
alt="${platform.name}"
class="rounded-circle me-1" width="20"
height="20">
</#list>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/site/errors/404.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<#import "../_navigation.ftl" as navigation />

<@navigation.display>
<div class="mt-3 d-flex justify-content-center align-items-center" style="min-height: 65vh;">
<div>
<h1 class="h1">Oops!</h1>
<p class="lead">La page que vous cherchez n'existe pas.</p>

<a href="/" class="btn btn-secondary mt-5">Retour à l'accueil</a>
</div>
</div>
</@navigation.display>
21 changes: 15 additions & 6 deletions src/main/resources/templates/site/search.ftl
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
<#import "_navigation.ftl" as navigation />

<@navigation.display canonicalUrl="${baseUrl}/search">
<div x-data="{animes: []}">
<div x-data="{
animes: [],
value: <#if query?? && query?has_content>'${query}'<#else>''</#if>
}" <#if query?? && query?has_content>x-init="animes = (await search(value)).data"</#if>>
<div class="container my-3">
<input type="text" id="search" class="form-control-lg w-100 bg-dark text-white"
placeholder="Rechercher" autofocus @input="animes = (await search($event.target.value)).data">
placeholder="Rechercher" autofocus
x-model="value" @input="animes = (await search(value)).data">
</div>

<div class="row g-3 justify-content-center" style="min-height: 50vh;">
<div class="row g-3 mt-3 justify-content-center" style="min-height: 60vh;">
<template x-for="anime in animes">
<div class="col-md-2 col-6 mt-0">
<div class="col-md-2 col-6 mt-0 mb-4">
<article x-data="{hover:false}" class="shikk-element">
<a x-bind:href="'/animes/' + anime.slug" class="text-decoration-none text-white"
@mouseenter="hover = true" @mouseleave="hover = false">
<div class="position-relative">
<img x-bind:src="'${apiUrl}/v1/attachments?uuid=' + anime.uuid + '&type=image'"
x-bind:alt="anime.shortName + ' anime image'" class="img-fluid rounded-top-4"
x-bind:alt="anime.shortName + ' anime'"
loading="lazy"
class="img-fluid rounded-top-4"
width="480"
height="720">

Expand Down Expand Up @@ -43,7 +49,7 @@
</div>

<div class="bg-black bg-opacity-75 bg-blur position-absolute top-0 start-0 w-100 h-100 mh-100 p-3 rounded-top-4"
x-show="hover">
style="display: none;" x-show="hover">
<div class="h6 text-truncate-2 fw-bold" x-text="anime.name.toUpperCase()"></div>
<hr>
<div class="text-truncate-6" x-text="anime.description"></div>
Expand All @@ -70,9 +76,12 @@
const trimmedQuery = query.trim();
if (trimmedQuery.length === 0) {
window.history.pushState({}, '', '/search');
return [];
}
window.history.pushState({}, '', '/search?q=' + encodeURIComponent(trimmedQuery));
return axios.get('/api/v1/animes?name=' + trimmedQuery + '&limit=12', {signal: abortController.signal})
.then(response => response.data)
.catch(error => {
Expand Down
47 changes: 47 additions & 0 deletions src/test/kotlin/fr/shikkanime/platforms/PrimeVideoPlatformTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package fr.shikkanime.platforms

import com.google.inject.Inject
import com.microsoft.playwright.junit.UsePlaywright
import fr.shikkanime.caches.CountryCodePrimeVideoSimulcastKeyCache
import fr.shikkanime.entities.enums.CountryCode
import fr.shikkanime.platforms.configuration.PrimeVideoConfiguration
import fr.shikkanime.utils.Constant
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.time.ZonedDateTime

@UsePlaywright
class PrimeVideoPlatformTest {
@Inject
private lateinit var primeVideoPlatform: PrimeVideoPlatform

@BeforeEach
fun setUp() {
Constant.injector.injectMembers(this)
}

@Test
fun fetchApiContent() {
val countryCode = CountryCode.FR
val zonedDateTime = ZonedDateTime.parse("2024-04-22T18:15:00Z")
val key = CountryCodePrimeVideoSimulcastKeyCache(countryCode, PrimeVideoConfiguration.PrimeVideoSimulcast(
1,
"https://cdn.myanimelist.net/images/anime/1142/141351.jpg",
"16:01:00"
).apply {
name = "0QN9ZXJ935YBTNK8U9FV5OAX5B"
})
val episodes = runBlocking { primeVideoPlatform.fetchApiContent(key, zonedDateTime) }

assertTrue(episodes.isNotEmpty())

episodes.forEach {
assertTrue(it.image.startsWith("https://m.media-amazon.com"))
assertTrue(it.url.isNotBlank())
assertFalse(it.getIdentifier().contains("https://"))
}
}
}

0 comments on commit a9a4ba0

Please sign in to comment.