Skip to content

Commit

Permalink
Add language detection and global anime status
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziedelth committed Jan 5, 2024
1 parent 4720735 commit 44a66cc
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 18 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-okhttp:$ktor_version")
implementation("io.ktor:ktor-client-okhttp-jvm:$ktor_version")
implementation("io.github.smiley4:ktor-swagger-ui:2.7.2")
implementation("org.hibernate.orm:hibernate-core:6.4.1.Final")
implementation("org.hibernate.search:hibernate-search-mapper-orm:7.1.0.Alpha1")
Expand All @@ -55,7 +56,8 @@ dependencies {
implementation("org.openpnp:opencv:4.9.0-0")
implementation("org.bouncycastle:bcprov-jdk18on:1.77")
implementation("com.mortennobel:java-image-scaling:0.8.6")
implementation("io.ktor:ktor-client-okhttp-jvm:2.3.7")
implementation("org.apache.tika:tika-core:3.0.0-BETA")
implementation("org.apache.tika:tika-langdetect-optimaize:3.0.0-BETA")
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
testImplementation("io.ktor:ktor-client-mock:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ktor_version=2.3.6
kotlin_version=1.9.21
ktor_version=2.3.7
kotlin_version=1.9.22
kotlin.code.style=official
1 change: 1 addition & 0 deletions hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<property name="hibernate.search.backend.type">lucene</property>
<property name="hibernate.search.backend.directory.type">local-filesystem</property>
<property name="hibernate.search.backend.analysis.configurer">fr.shikkanime.modules.CustomLuceneAnalysisDefinitionProvider</property>
<property name="hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS">20</property>
</session-factory>
</hibernate-configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ package fr.shikkanime.converters.anime
import fr.shikkanime.converters.AbstractConverter
import fr.shikkanime.dtos.AnimeDto
import fr.shikkanime.dtos.SimulcastDto
import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.entities.Anime
import org.apache.tika.language.detect.LanguageDetector
import java.time.ZoneId
import java.time.format.DateTimeFormatter

class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
private val languageDetector: LanguageDetector = LanguageDetector.getDefaultLanguageDetector().loadModels()
private val utcZone = ZoneId.of("UTC")

override fun convert(from: Anime): AnimeDto {
val status = if (
from.image.isNullOrBlank() ||
from.description.isNullOrBlank() ||
from.description?.startsWith("(") == true ||
languageDetector.detect(from.description).language.lowercase() != from.countryCode!!.name.lowercase()
) Status.INVALID else Status.VALID

return AnimeDto(
uuid = from.uuid,
releaseDateTime = from.releaseDateTime.withZoneSameInstant(utcZone).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME),
Expand All @@ -19,6 +29,7 @@ class AnimeToAnimeDtoConverter : AbstractConverter<Anime, AnimeDto>() {
name = from.name!!,
description = from.description,
simulcasts = convert(from.simulcasts, SimulcastDto::class.java),
status = status,
)
}
}
2 changes: 2 additions & 0 deletions src/main/kotlin/fr/shikkanime/dtos/AnimeDto.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.shikkanime.dtos

import fr.shikkanime.dtos.enums.Status
import fr.shikkanime.entities.enums.CountryCode
import java.io.Serializable
import java.util.*
Expand All @@ -12,4 +13,5 @@ data class AnimeDto(
val image: String? = null,
val description: String?,
val simulcasts: List<SimulcastDto>?,
val status: Status? = null,
) : Serializable
6 changes: 6 additions & 0 deletions src/main/kotlin/fr/shikkanime/dtos/enums/Status.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fr.shikkanime.dtos.enums

enum class Status {
VALID,
INVALID,
}
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin/_navigation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</ul>
</div>

<div class="p-4 container-fluid">
<div class="p-4 container-fluid" style="max-height: 100vh; overflow-y: auto;">
<#nested 1>
</div>
</@layout.main>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin/anime_view.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<input type="text" class="form-control disabled" id="uuid" name="uuid" value="${anime.uuid.toString()}" aria-label="UUID"
aria-describedby="basic-addon" disabled>
<span class="input-group-text" id="basic-addon" onclick="copyToClipboard('${anime.uuid.toString()}')" style="cursor: pointer"><i
class="bi bi-clipboard-fill"></i></span>
class="bi bi-clipboard"></i></span>
</div>
</div>
<div class="col-md-6">
Expand Down
20 changes: 7 additions & 13 deletions src/main/resources/templates/admin/animes.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
<@navigation.display>
<div class="row g-3 align-items-center mb-3">
<div class="col-auto">
<div class="form-floating">
<input type="text" class="form-control" id="floatingInput" placeholder="One Piece">
<label for="floatingInput">Name</label>
</div>
<label class="form-label" for="nameInput">Name</label>
<input type="text" class="form-control" id="nameInput" placeholder="One Piece">
</div>
</div>

Expand All @@ -15,7 +13,6 @@
<tr>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
</thead>
Expand All @@ -25,15 +22,12 @@
</table>

<script>
function buildTableElement(uuid, name, image, description) {
const isInvalid = (image == null || image === '') || (description == null || description === '' || description?.startsWith('('));
function buildTableElement(uuid, name, image, description, status) {
const isInvalid = status === 'INVALID';
return `<tr>
<th scope="row">` + name + `</th>
<th scope="row"><span class="me-2 badge bg-` + (isInvalid ? 'danger' : 'success') + `">` + (isInvalid ? 'Invalid' : 'Valid') + `</span>` + name + `</th>
<td>` + description + `</td>
<td>
<span class="badge bg-` + (isInvalid ? 'danger' : 'success') + `">` + (isInvalid ? 'Invalid' : 'Valid') + `</span>
</td>
<td>
<a href="/admin/animes/` + uuid + `" class="btn btn-warning">
<i class="bi bi-pencil-square"></i>
Expand Down Expand Up @@ -61,7 +55,7 @@
table.innerHTML = '';
animes.forEach(anime => {
table.innerHTML += buildTableElement(anime.uuid, anime.name, anime.image, anime.description);
table.innerHTML += buildTableElement(anime.uuid, anime.name, anime.image, anime.description, anime.status);
});
}
Expand All @@ -72,7 +66,7 @@
let timeout = null;
document.getElementById('floatingInput').addEventListener('input', async (event) => {
document.getElementById('nameInput').addEventListener('input', async (event) => {
// Avoids calling the API on every key press
clearTimeout(timeout);
Expand Down

0 comments on commit 44a66cc

Please sign in to comment.