Open-source multiplayer game server compatible with the RuneScape client https://www.openrs2.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
openrs2/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt

41 lines
1.4 KiB

package org.openrs2.archive.web
import io.ktor.application.ApplicationCall
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.response.header
import io.ktor.response.respond
import io.ktor.response.respondOutputStream
import io.ktor.thymeleaf.ThymeleafContent
import io.netty.buffer.ByteBufAllocator
import org.openrs2.archive.cache.CacheExporter
import org.openrs2.cache.DiskStoreZipWriter
import java.util.zip.ZipOutputStream
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
public class CachesController @Inject constructor(
private val exporter: CacheExporter,
private val alloc: ByteBufAllocator
) {
public suspend fun index(call: ApplicationCall) {
val caches = exporter.list()
call.respond(ThymeleafContent("caches/index.html", mapOf("caches" to caches)))
}
public suspend fun export(call: ApplicationCall) {
val id = call.parameters["id"]?.toLongOrNull()
if (id == null) {
call.respond(HttpStatusCode.NotFound)
return
}
call.response.header("Content-Disposition", "attachment; filename=\"cache.zip\"")
call.respondOutputStream(contentType = ContentType.Application.Zip) {
DiskStoreZipWriter(ZipOutputStream(this), alloc = alloc).use { store ->
exporter.export(id, store)
}
}
}
}