Skip to content

Commit

Permalink
Remove DreamStorageService dependency because we are now using Ethere…
Browse files Browse the repository at this point in the history
…alGambi
  • Loading branch information
MrPowerGamerBR committed Oct 14, 2024
1 parent 0568a6a commit b194b50
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 630 deletions.
24 changes: 10 additions & 14 deletions backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,28 @@ dependencies {
implementation("org.jsoup:jsoup:1.16.1")

// Databases
implementation("org.jetbrains.exposed:exposed-core:0.37.3")
implementation("org.jetbrains.exposed:exposed-jdbc:0.37.3")
implementation("org.jetbrains.exposed:exposed-dao:0.37.3")
implementation("org.jetbrains.exposed:exposed-kotlin-datetime:0.36.2")
implementation("org.postgresql:postgresql:42.3.3")
implementation("com.zaxxer:HikariCP:5.0.1")
implementation("org.jetbrains.exposed:exposed-core:0.55.0")
implementation("org.jetbrains.exposed:exposed-jdbc:0.55.0")
implementation("org.jetbrains.exposed:exposed-dao:0.55.0")
implementation("org.jetbrains.exposed:exposed-kotlin-datetime:0.55.0")
implementation("org.jetbrains.exposed:exposed-json:0.55.0")
implementation("org.postgresql:postgresql:42.7.4")
implementation("com.zaxxer:HikariCP:6.0.0")
implementation("io.github.microutils:kotlin-logging:2.1.21")
implementation("net.perfectdreams.dreamstorageservice:client:2.0.2")
implementation("pw.forst", "exposed-upsert", "1.1.0")

// Caching
implementation("com.github.ben-manes.caffeine:caffeine:3.0.5")

// Internationalization + LanguageManager
api("net.perfectdreams.i18nhelper.formatters:icu-messageformat-jvm:${Versions.I18N_HELPER}")
implementation("com.charleskorn.kaml:kaml:0.35.0")
implementation("com.charleskorn.kaml:kaml:0.61.0")
implementation("com.ibm.icu:icu4j:71.1")
implementation("org.yaml:snakeyaml:1.30")
implementation("org.yaml:snakeyaml:2.3")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${Versions.KOTLINX_SERIALIZATION}")

// https://mvnrepository.com/artifact/club.minnced/discord-webhooks
implementation("club.minnced:discord-webhooks:0.8.2")

testImplementation("io.ktor:ktor-server-tests:${Versions.KTOR}")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.5.31")
implementation("club.minnced:discord-webhooks:0.8.4")
}

jib {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ import io.ktor.server.routing.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import net.perfectdreams.dreamstorageservice.client.DreamStorageServiceClient
import net.perfectdreams.galleryofdreams.backend.plugins.configureRouting
import net.perfectdreams.galleryofdreams.backend.routes.*
import net.perfectdreams.galleryofdreams.backend.routes.api.GetFanArtArtistByDiscordIdRoute
import net.perfectdreams.galleryofdreams.backend.routes.api.GetFanArtsRoute
import net.perfectdreams.galleryofdreams.backend.routes.api.GetLanguageInfoRoute
import net.perfectdreams.galleryofdreams.backend.routes.api.PatchFanArtRoute
import net.perfectdreams.galleryofdreams.backend.routes.api.PostArtistWithFanArtRoute
import net.perfectdreams.galleryofdreams.backend.routes.api.PostCheckFanArtRoute
import net.perfectdreams.galleryofdreams.backend.routes.api.PostFanArtRoute
import net.perfectdreams.galleryofdreams.backend.tables.AuthorizationTokens
import net.perfectdreams.galleryofdreams.backend.tables.FanArtArtists
import net.perfectdreams.galleryofdreams.backend.tables.FanArtTags
Expand Down Expand Up @@ -71,9 +67,6 @@ class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
GetFanArtsRoute(this),
GetLanguageInfoRoute(this),
GetFanArtArtistByDiscordIdRoute(this),
PostArtistWithFanArtRoute(this),
PostFanArtRoute(this),
PostCheckFanArtRoute(this),
PatchFanArtRoute(this)
)

Expand All @@ -97,11 +90,6 @@ class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
this.socketTimeoutMillis = 120_000
}
}
val dreamStorageServiceClient = DreamStorageServiceClient(
System.getenv("GALLERYOFDREAMS_DSS_URL"),
System.getenv("GALLERYOFDREAMS_DSS_TOKEN"),
http
)

private val typesToCache = listOf(
ContentType.Text.CSS,
Expand Down Expand Up @@ -208,7 +196,7 @@ class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
Database.connect(
HikariDataSource(dataSource),
databaseConfig = DatabaseConfig {
defaultRepetitionAttempts = DEFAULT_REPETITION_ATTEMPTS
this.defaultMaxAttempts = 5
defaultIsolationLevel = ISOLATION_LEVEL.levelId // Change our default isolation level
}
)
Expand Down Expand Up @@ -277,19 +265,14 @@ class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
}

results.map {
val discordSocialConnections = FanArtArtistDiscordConnections.select {
FanArtArtistDiscordConnections.artist eq it[FanArtArtists.id]
}
val twitterSocialConnections = FanArtArtistTwitterConnections.select {
FanArtArtistTwitterConnections.artist eq it[FanArtArtists.id]
}
val deviantArtSocialConnections = FanArtArtistDeviantArtConnections.select {
FanArtArtistDeviantArtConnections.artist eq it[FanArtArtists.id]
}
val discordSocialConnections = FanArtArtistDiscordConnections.selectAll()
.where { FanArtArtistDiscordConnections.artist eq it[FanArtArtists.id] }
val twitterSocialConnections = FanArtArtistTwitterConnections.selectAll()
.where { FanArtArtistTwitterConnections.artist eq it[FanArtArtists.id] }
val deviantArtSocialConnections = FanArtArtistDeviantArtConnections.selectAll()
.where { FanArtArtistDeviantArtConnections.artist eq it[FanArtArtists.id] }

val count = FanArts.select {
FanArts.artist eq it[FanArtArtists.id]
}.count()
val count = FanArts.selectAll().where { FanArts.artist eq it[FanArtArtists.id] }.count()

FanArtArtistWithFanArtCount(
FanArtArtistX(
Expand All @@ -304,9 +287,8 @@ class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
} + deviantArtSocialConnections.map {
DeviantArtSocialConnection(it[FanArtArtistDeviantArtConnections.handle])
},
FanArts.select {
FanArts.artist eq it[FanArtArtists.id].value
}.orderBy(FanArts.createdAt, SortOrder.DESC).limit(1).firstOrNull()?.let {
FanArts.selectAll().where { FanArts.artist eq it[FanArtArtists.id].value }
.orderBy(FanArts.createdAt, SortOrder.DESC).limit(1).firstOrNull()?.let {
convertToFanArt(it)
}
),
Expand All @@ -325,9 +307,8 @@ class GalleryOfDreamsBackend(val languageManager: LanguageManager) {
fanArt[FanArts.dreamStorageServiceImageId],
fanArt[FanArts.file],
fanArt[FanArts.preferredMediaType],
FanArtTags.slice(FanArtTags.tag).select {
FanArtTags.fanArt eq fanArt[FanArts.id]
}.map { it[FanArtTags.tag] }
FanArtTags.select(FanArtTags.tag).where { FanArtTags.fanArt eq fanArt[FanArts.id] }
.map { it[FanArtTags.tag] }
)

fun <T:Any> execAndMap(string: String, transform : (ResultSet) -> T) : List<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import net.perfectdreams.i18nhelper.core.I18nContext

fun FlowContent.fanArtArtist(
i18nContext: I18nContext,
dssBaseUrl: String,
namespace: String,
artist: FanArtArtistX,
fanArtCount: Long
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import net.perfectdreams.galleryofdreams.common.data.FanArtArtistX
import net.perfectdreams.galleryofdreams.common.i18n.I18nKeysData
import net.perfectdreams.i18nhelper.core.I18nContext

fun FlowContent.fanArtCard(m: GalleryOfDreamsBackend, i18nContext: I18nContext, dssBaseUrl: String, namespace: String, fanArtArtist: FanArtArtistX, fanArt: FanArt) {
fun FlowContent.fanArtCard(m: GalleryOfDreamsBackend, i18nContext: I18nContext, fanArtArtist: FanArtArtistX, fanArt: FanArt) {
aHtmx(classes = "fan-art-card", href = "/${i18nContext.websiteLocaleIdPath}/artists/${fanArtArtist.slug}/${fanArt.slug}", hxTarget = "#content") {
div(classes = "fan-art-info-card") {
div(classes = "fan-art-tags") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import net.perfectdreams.galleryofdreams.backend.GalleryOfDreamsBackend
import net.perfectdreams.galleryofdreams.backend.utils.FanArtArtistWithFanArt
import net.perfectdreams.i18nhelper.core.I18nContext

fun FlowContent.fanArtCardGrid(m: GalleryOfDreamsBackend, i18nContext: I18nContext, dssBaseUrl: String, namespace: String, fanArts: List<FanArtArtistWithFanArt>) {
fun FlowContent.fanArtCardGrid(m: GalleryOfDreamsBackend, i18nContext: I18nContext, fanArts: List<FanArtArtistWithFanArt>) {
if (fanArts.isEmpty()) {
div {
h1 {
Expand All @@ -21,7 +21,7 @@ fun FlowContent.fanArtCardGrid(m: GalleryOfDreamsBackend, i18nContext: I18nConte
"display: grid; grid-template-columns: repeat(auto-fill, minmax(192px, 1fr)); grid-template-rows: repeat(auto-fill, minmax(192px, 1fr)); gap: 1em; justify-content: space-between; width: 100%;"

for (fanArt in fanArts) {
fanArtCard(m, i18nContext, dssBaseUrl, namespace, fanArt.fanArtArtist, fanArt.fanArt)
fanArtCard(m, i18nContext, fanArt.fanArtArtist, fanArt.fanArt)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import net.perfectdreams.galleryofdreams.common.i18n.I18nKeysData
import net.perfectdreams.i18nhelper.core.I18nContext
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inSubQuery

class GetFanArtArtistRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/artists/{artistSlug}") {
override suspend fun onLocalizedRequest(call: ApplicationCall, i18nContext: I18nContext) {
Expand All @@ -33,22 +35,19 @@ class GetFanArtArtistRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/arti
val zeroIndexedPage = page - 1

val fanArts = m.transaction {
val fanArtArtist = FanArtArtists.select {
FanArtArtists.slug eq artistSlug
}.first()
val fanArtArtist = FanArtArtists.selectAll().where { FanArtArtists.slug eq artistSlug }.first()

val discordSocialConnections = FanArtArtistDiscordConnections.select {
FanArtArtistDiscordConnections.artist eq fanArtArtist[FanArtArtists.id]
}
val twitterSocialConnections = FanArtArtistTwitterConnections.select {
FanArtArtistTwitterConnections.artist eq fanArtArtist[FanArtArtists.id]
}
val deviantArtSocialConnections = FanArtArtistDeviantArtConnections.select {
FanArtArtistDeviantArtConnections.artist eq fanArtArtist[FanArtArtists.id]
}
val discordSocialConnections = FanArtArtistDiscordConnections.selectAll()
.where { FanArtArtistDiscordConnections.artist eq fanArtArtist[FanArtArtists.id] }
val twitterSocialConnections = FanArtArtistTwitterConnections.selectAll()
.where { FanArtArtistTwitterConnections.artist eq fanArtArtist[FanArtArtists.id] }
val deviantArtSocialConnections = FanArtArtistDeviantArtConnections.selectAll()
.where { FanArtArtistDeviantArtConnections.artist eq fanArtArtist[FanArtArtists.id] }

val query = FanArts.select {
FanArts.artist eq fanArtArtist[FanArtArtists.id] and (if (tags == null) Op.TRUE eq Op.TRUE else FanArts.id inSubQuery FanArtTags.slice(FanArtTags.fanArt).select { FanArtTags.tag inList tags })
val query = FanArts.selectAll().where {
FanArts.artist eq fanArtArtist[FanArtArtists.id] and (if (tags == null) Op.TRUE eq Op.TRUE else FanArts.id inSubQuery FanArtTags.select(
FanArtTags.fanArt
).where { FanArtTags.tag inList tags })
}.orderBy(
FanArts.createdAt, when (sortOrder) {
FanArtSortOrder.DATE_ASCENDING -> SortOrder.ASC
Expand All @@ -58,7 +57,8 @@ class GetFanArtArtistRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/arti

// YES THE ORDER MATTERS BECAUSE THE QUERY IS MUTABLE
val totalFanArts = query.count()
val fanArts = query.limit(GalleryOfDreamsBackend.FAN_ARTS_PER_PAGE, (zeroIndexedPage * 20).toLong()).toList()
val fanArts =
query.limit(GalleryOfDreamsBackend.FAN_ARTS_PER_PAGE, (zeroIndexedPage * 20).toLong()).toList()

QueryResult(
FanArtArtistX(
Expand All @@ -73,9 +73,8 @@ class GetFanArtArtistRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/arti
} + deviantArtSocialConnections.map {
DeviantArtSocialConnection(it[FanArtArtistDeviantArtConnections.handle])
},
FanArts.select {
FanArts.artist eq fanArtArtist[FanArtArtists.id].value
}.orderBy(FanArts.createdAt, SortOrder.DESC).limit(1).firstOrNull()?.let {
FanArts.selectAll().where { FanArts.artist eq fanArtArtist[FanArtArtists.id].value }
.orderBy(FanArts.createdAt, SortOrder.DESC).limit(1).firstOrNull()?.let {
m.convertToFanArt(it)
}
),
Expand All @@ -89,9 +88,8 @@ class GetFanArtArtistRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/arti
it[FanArts.dreamStorageServiceImageId],
it[FanArts.file],
it[FanArts.preferredMediaType],
FanArtTags.slice(FanArtTags.tag).select {
FanArtTags.fanArt eq it[FanArts.id]
}.map { it[FanArtTags.tag] }
FanArtTags.select(FanArtTags.tag).where { FanArtTags.fanArt eq it[FanArts.id] }
.map { it[FanArtTags.tag] }
)
},
totalFanArts
Expand All @@ -103,8 +101,6 @@ class GetFanArtArtistRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/arti
i18nContext,
i18nContext.get(I18nKeysData.WebsiteTitle),
call.request.pathWithoutLocale(),
m.dreamStorageServiceClient.baseUrl,
m.dreamStorageServiceClient.getCachedNamespaceOrRetrieve(),
artistSlug,
sortOrder,
tags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,26 @@ import net.perfectdreams.galleryofdreams.common.data.FanArtArtistX
import net.perfectdreams.galleryofdreams.common.data.TwitterSocialConnection
import net.perfectdreams.galleryofdreams.common.i18n.I18nKeysData
import net.perfectdreams.i18nhelper.core.I18nContext
import org.jetbrains.exposed.sql.SortOrder
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll

class GetFanArtRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/artists/{artistSlug}/{fanArtSlug}") {
override suspend fun onLocalizedRequest(call: ApplicationCall, i18nContext: I18nContext) {
val fanArtAndArtist = m.transaction {
val data = FanArts.innerJoin(FanArtArtists)
.select { FanArtArtists.slug eq call.parameters.getOrFail("artistSlug") and (FanArts.slug eq call.parameters.getOrFail("fanArtSlug")) }
.selectAll().where {
FanArtArtists.slug eq call.parameters.getOrFail("artistSlug") and (FanArts.slug eq call.parameters.getOrFail(
"fanArtSlug"
))
}
.first()

val discordSocialConnections = FanArtArtistDiscordConnections.select {
FanArtArtistDiscordConnections.artist eq data[FanArtArtists.id]
}
val twitterSocialConnections = FanArtArtistTwitterConnections.select {
FanArtArtistTwitterConnections.artist eq data[FanArtArtists.id]
}
val deviantArtSocialConnections = FanArtArtistDeviantArtConnections.select {
FanArtArtistDeviantArtConnections.artist eq data[FanArtArtists.id]
}
val discordSocialConnections = FanArtArtistDiscordConnections.selectAll()
.where { FanArtArtistDiscordConnections.artist eq data[FanArtArtists.id] }
val twitterSocialConnections = FanArtArtistTwitterConnections.selectAll()
.where { FanArtArtistTwitterConnections.artist eq data[FanArtArtists.id] }
val deviantArtSocialConnections = FanArtArtistDeviantArtConnections.selectAll()
.where { FanArtArtistDeviantArtConnections.artist eq data[FanArtArtists.id] }

FanArtArtistWithFanArt(
FanArtArtistX(
Expand All @@ -70,9 +68,8 @@ class GetFanArtRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/artists/{a
} + deviantArtSocialConnections.map {
DeviantArtSocialConnection(it[FanArtArtistDeviantArtConnections.handle])
},
FanArts.select {
FanArts.artist eq data[FanArtArtists.id].value
}.orderBy(FanArts.createdAt, SortOrder.DESC).limit(1).firstOrNull()?.let {
FanArts.selectAll().where { FanArts.artist eq data[FanArtArtists.id].value }
.orderBy(FanArts.createdAt, SortOrder.DESC).limit(1).firstOrNull()?.let {
m.convertToFanArt(it)
}
),
Expand All @@ -85,8 +82,6 @@ class GetFanArtRoute(m: GalleryOfDreamsBackend) : LocalizedRoute(m, "/artists/{a
i18nContext,
i18nContext.get(I18nKeysData.WebsiteTitle),
call.request.pathWithoutLocale(),
m.dreamStorageServiceClient.baseUrl,
m.dreamStorageServiceClient.getCachedNamespaceOrRetrieve(),
fanArtAndArtist.fanArtArtist,
fanArtAndArtist.fanArt
)
Expand Down
Loading

0 comments on commit b194b50

Please sign in to comment.