Skip to content

Commit

Permalink
Refactor backgrounds to a separated web server
Browse files Browse the repository at this point in the history
  • Loading branch information
WinG4merBR committed Jan 28, 2025
1 parent f3c98c6 commit cc17d6c
Show file tree
Hide file tree
Showing 103 changed files with 25 additions and 24 deletions.
21 changes: 10 additions & 11 deletions common/src/main/kotlin/net/cakeyfox/common/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,23 @@ object Constants {

/* ---- [Profile Assets] ---- */

fun getProfileBackground(backgroundId: String): InputStream {
return javaClass.getResourceAsStream("/profile/backgrounds/$backgroundId")!!
fun getProfileBackground(backgroundId: String): String {
return "https://stuff.foxybot.win/backgrounds/$backgroundId"
}

fun getProfileLayout(layoutId: String): InputStream {
return javaClass.getResourceAsStream("/profile/layouts/$layoutId")!!
fun getProfileLayout(layoutId: String): String {
return "https://stuff.foxybot.win/layouts/$layoutId"
}

fun getProfileDecoration(maskId: String): InputStream {
return javaClass.getResourceAsStream("/profile/decorations/$maskId.png")!!
fun getProfileDecoration(maskId: String): String {
return "https://stuff.foxybot.win/decorations/$maskId.png"
}

fun getMarriedOverlay(layoutId: String): InputStream {
return javaClass.getResourceAsStream("/profile/layouts/${layoutId}-married.png")!!
fun getMarriedOverlay(layoutId: String): String {
return "https://stuff.foxybot.win/layouts/${layoutId}-married.png"
}

fun getProfileBadge(badgeId: String): InputStream {
return javaClass.getResourceAsStream("/profile/badges/$badgeId")!!
fun getProfileBadge(badgeId: String): String {
return "https://stuff.foxybot.win/badges/$badgeId"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.engine.*
import io.ktor.server.http.content.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.response.*
Expand All @@ -13,13 +12,11 @@ import mu.KotlinLogging
import net.cakeyfox.common.Constants
import net.cakeyfox.foxy.FoxyInstance
import net.cakeyfox.foxy.utils.api.routes.*
import java.io.File
import kotlin.reflect.jvm.jvmName

class FoxyInternalAPI(
val foxy: FoxyInstance
) {
private val logger = KotlinLogging.logger(this::class.jvmName)
private val logger = KotlinLogging.logger { }
private val server = embeddedServer(Netty, port = foxy.config.others.internalApi.port) {
install(ContentNegotiation) {
json()
Expand Down Expand Up @@ -48,8 +45,6 @@ class FoxyInternalAPI(
GetClusterInfo().apply { getClusterInfo(foxy) }
UpdateActivityRoute().apply { updateActivity(foxy) }
}

staticFiles("/assets", File(this::class.java.classLoader.getResource("profile")!!.file))
}
}.start(wait = false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.cakeyfox.foxy.utils.profile

import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import net.cakeyfox.foxy.utils.image.ImageUtils
import net.cakeyfox.serializable.database.data.Background
import net.cakeyfox.serializable.database.data.Badge
import net.cakeyfox.serializable.database.data.Decoration
Expand All @@ -19,5 +20,11 @@ object ProfileCacheManager {
.maximumSize(100)
.build()

fun loadImageFromFile(stream: InputStream): BufferedImage = ImageIO.read(stream)
suspend fun loadImageFromCache(url: String): BufferedImage {
return imageCache.getIfPresent(url) ?: run {
val image = ImageUtils.loadProfileAssetFromURL(url)
imageCache.put(url, image)
image
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class ProfileRender(
}

val layoutDeferred = async {
ProfileCacheManager.loadImageFromFile(Constants.getProfileLayout(layoutInfo.filename))
ProfileCacheManager.loadImageFromCache(Constants.getProfileLayout(layoutInfo.filename))
}

val backgroundDeferred = async {
ProfileCacheManager.loadImageFromFile(Constants.getProfileBackground(backgroundInfo.filename))
ProfileCacheManager.loadImageFromCache(Constants.getProfileBackground(backgroundInfo.filename))
}

val layout = layoutDeferred.await()
Expand Down Expand Up @@ -140,7 +140,7 @@ class ProfileRender(

val decorationDeferred = async {
data.userProfile.decoration?.let {
ProfileCacheManager.loadImageFromFile(Constants.getProfileDecoration(it))
ProfileCacheManager.loadImageFromCache(Constants.getProfileDecoration(it))
}
}

Expand Down Expand Up @@ -187,7 +187,7 @@ class ProfileRender(
}

val decorationImage =
ProfileCacheManager.loadImageFromFile(
ProfileCacheManager.loadImageFromCache(
Constants.getProfileDecoration(
decorationInfo.filename.replace(
".png",
Expand Down Expand Up @@ -238,7 +238,7 @@ class ProfileRender(
var y = layoutInfo.profileSettings.positions.badgesPosition.y

for (badge in userBadges) {
val badgeImage = ProfileCacheManager.loadImageFromFile(Constants.getProfileBadge(badge.asset))
val badgeImage = ProfileCacheManager.loadImageFromCache(Constants.getProfileBadge(badge.asset))
graphics.drawImage(badgeImage, x.toInt(), y.toInt(), 50, 50, null)

x += 60
Expand All @@ -251,7 +251,7 @@ class ProfileRender(

private suspend fun drawMarryInfo(userData: FoxyUser, layout: Layout) {
val marriedDateFormatted = context.utils.convertToHumanReadableDate(userData.marryStatus.marriedDate!!)
val marriedOverlay = ProfileCacheManager.loadImageFromFile(Constants.getMarriedOverlay(layout.id))
val marriedOverlay = ProfileCacheManager.loadImageFromCache(Constants.getMarriedOverlay(layout.id))
val color = if (layout.darkText) Color.BLACK else Color.WHITE
val partnerUser = context.jda.retrieveUserById(userData.marryStatus.marriedWith!!).await()

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed foxy/src/main/resources/profile/backgrounds/ena.png
Binary file not shown.
Binary file not shown.
Binary file removed foxy/src/main/resources/profile/backgrounds/fnaf.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/backgrounds/gtr.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/backgrounds/mine.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/backgrounds/yyh.png
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/banned.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/boost.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/donor.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/fhany.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/foxy.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/married.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/member.png
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/rdrbr.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/sally.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/staff.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/support.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/translators.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/upvoters.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/badges/valorant.png
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/decorations/ears.png
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/decorations/halo.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/layouts/blue.png
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/layouts/classic.png
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/layouts/cyan.png
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/layouts/default.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/layouts/foxy.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/layouts/purple.png
Diff not rendered.
Diff not rendered.
Binary file removed foxy/src/main/resources/profile/layouts/red.png
Diff not rendered.

0 comments on commit cc17d6c

Please sign in to comment.