Add support for downloading caches in flat file format

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 6aea0cfc8e
commit ba60fecb50
  1. 24
      archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt
  2. 14
      archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt
  3. 9
      archive/src/main/resources/org/openrs2/archive/templates/caches/index.html
  4. 26
      archive/src/main/resources/org/openrs2/archive/templates/caches/show.html

@ -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) {

@ -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) }

@ -79,8 +79,10 @@
Download
</button>
<ul class="dropdown-menu">
<li><a th:href="${'/caches/' + cache.id + '.zip'}"
class="dropdown-item">Cache</a></li>
<li><a th:href="${'/caches/' + cache.id + '/disk.zip'}"
class="dropdown-item">Cache (.dat2/.idx)</a></li>
<li><a th:href="${'/caches/' + cache.id + '/flat-file.zip'}"
class="dropdown-item">Cache (Flat file)</a></li>
<li>
<hr class="dropdown-divider" />
</li>
@ -88,6 +90,9 @@
class="dropdown-item">Keys (JSON)</a></li>
<li><a th:href="${'/caches/' + cache.id + '/keys.zip'}"
class="dropdown-item">Keys (Text)</a></li>
<li>
<hr class="dropdown-divider" />
</li>
<li><a th:href="${'/caches/' + cache.id + '/map.png'}"
class="dropdown-item">Map</a></li>
</ul>

@ -49,15 +49,23 @@
<tr class="thead-dark">
<th>Download</th>
<td>
<div class="btn-group">
<a th:href="${'/caches/' + cache.id + '.zip'}"
class="btn btn-primary btn-sm">Cache</a>
<a th:href="${'/caches/' + cache.id + '/keys.json'}"
class="btn btn-primary btn-sm">Keys (JSON)</a>
<a th:href="${'/caches/' + cache.id + '/keys.zip'}"
class="btn btn-primary btn-sm">Keys (Text)</a>
<a th:href="${'/caches/' + cache.id + '/map.png'}"
class="btn btn-primary btn-sm">Map</a>
<div class="btn-toolbar">
<div class="btn-group mr-2">
<a th:href="${'/caches/' + cache.id + '/disk.zip'}"
class="btn btn-primary btn-sm">Cache (.dat2/.idx)</a>
<a th:href="${'/caches/' + cache.id + '/flat-file.zip'}"
class="btn btn-primary btn-sm">Cache (Flat file)</a>
</div>
<div class="btn-group mr-2">
<a th:href="${'/caches/' + cache.id + '/keys.json'}"
class="btn btn-primary btn-sm">Keys (JSON)</a>
<a th:href="${'/caches/' + cache.id + '/keys.zip'}"
class="btn btn-primary btn-sm">Keys (Text)</a>
</div>
<div class="btn-group">
<a th:href="${'/caches/' + cache.id + '/map.png'}"
class="btn btn-primary btn-sm">Map</a>
</div>
</div>
</td>
</tr>

Loading…
Cancel
Save