diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt index 3d6435ea..3589f8d7 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.sync.withPermit import org.openrs2.archive.cache.CacheExporter import org.openrs2.archive.map.MapRenderer import org.openrs2.cache.DiskStoreZipWriter +import org.openrs2.cache.FlatFileStoreZipWriter import java.nio.file.attribute.FileTime import java.time.Instant import java.util.zip.Deflater @@ -53,7 +54,7 @@ public class CachesController @Inject constructor( call.respond(ThymeleafContent("caches/show.html", mapOf("cache" to cache))) } - public suspend fun export(call: ApplicationCall) { + public suspend fun exportDisk(call: ApplicationCall) { val id = call.parameters["id"]?.toIntOrNull() if (id == null) { call.respond(HttpStatusCode.NotFound) @@ -74,6 +75,27 @@ public class CachesController @Inject constructor( } } + public suspend fun exportFlatFile(call: ApplicationCall) { + val id = call.parameters["id"]?.toIntOrNull() + if (id == null) { + call.respond(HttpStatusCode.NotFound) + return + } + + call.response.header( + HttpHeaders.ContentDisposition, + ContentDisposition.Attachment + .withParameter(ContentDisposition.Parameters.FileName, "cache.zip") + .toString() + ) + + call.respondOutputStream(contentType = ContentType.Application.Zip) { + FlatFileStoreZipWriter(ZipOutputStream(this)).use { store -> + exporter.export(id, store) + } + } + } + public suspend fun exportKeysJson(call: ApplicationCall) { val id = call.parameters["id"]?.toIntOrNull() if (id == null) { diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt b/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt index af1b01c2..b9cf9f2e 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt @@ -55,7 +55,17 @@ public class WebServer @Inject constructor( get("/") { call.respond(ThymeleafContent("index.html", emptyMap())) } get("/caches") { cachesController.index(call) } get("/caches/{id}") { cachesController.show(call) } - get("/caches/{id}.zip") { cachesController.export(call) } + get("/caches/{id}.zip") { + val id = call.parameters["id"] + if (id == null) { + call.respond(HttpStatusCode.NotFound) + return@get + } + + call.respondRedirect(permanent = true) { + path("caches", id, "disk.zip") + } + } get("/caches/{id}.json") { val id = call.parameters["id"] if (id == null) { @@ -67,6 +77,8 @@ public class WebServer @Inject constructor( path("caches", id, "keys.json") } } + get("/caches/{id}/disk.zip") { cachesController.exportDisk(call) } + get("/caches/{id}/flat-file.zip") { cachesController.exportFlatFile(call) } get("/caches/{id}/keys.json") { cachesController.exportKeysJson(call) } get("/caches/{id}/keys.zip") { cachesController.exportKeysZip(call) } get("/caches/{id}/map.png") { cachesController.renderMap(call) } diff --git a/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html b/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html index 648e11cb..69a1adb6 100644 --- a/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html +++ b/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html @@ -79,8 +79,10 @@ Download diff --git a/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html b/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html index b81872b6..a2da1217 100644 --- a/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html +++ b/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html @@ -49,15 +49,23 @@ Download -
- Cache - Keys (JSON) - Keys (Text) - Map +
+ + +
+ Map +