Skip to content

Commit

Permalink
Add cache-buster string to Cover Image filenames
Browse files Browse the repository at this point in the history
Add a random 8 character string into filename paths when downloading or
saving new cover images. This random string will break any caching
(browser or especially useful for Cloudflare/proxies) and serve the new
image with a different URL.

Backwards compatible as it only applies on save. Current covers will
serve with their name until a new image is uploaded instead.
  • Loading branch information
DarthNerdus committed Apr 27, 2024
1 parent 01023b0 commit d0bfa62
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/kotlin/io/github/bayang/jelu/utils/FileUtils.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package io.github.bayang.jelu.utils

fun imageName(title: String, bookId: String, extension: String): String = "$title-$bookId.$extension"
fun imageName(title: String, bookId: String, extension: String): String {
// Generate 8 character random string
val cacheBuster = List(8) { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".random() }.joinToString("")
val imageName = "$title-$bookId.$cacheBuster.$extension"
return imageName
}

0 comments on commit d0bfa62

Please sign in to comment.