From aa7b59e4b9e9048d4d12dc900833727508b8c6a4 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 20 Feb 2021 00:01:25 +0000 Subject: [PATCH] Add a page for each cache These pages will list missing groups and keys in the future, which we won't be able to fit in the table. Signed-off-by: Graham --- .../openrs2/archive/cache/CacheExporter.kt | 60 +++++++++++++++- .../openrs2/archive/web/CachesController.kt | 16 +++++ .../org/openrs2/archive/web/WebServer.kt | 1 + .../archive/templates/caches/index.html | 20 ++---- .../archive/templates/caches/show.html | 69 +++++++++++++++++++ .../org/openrs2/archive/templates/layout.html | 23 +++++++ 6 files changed, 175 insertions(+), 14 deletions(-) create mode 100644 archive/src/main/resources/org/openrs2/archive/templates/caches/show.html create mode 100644 archive/src/main/resources/org/openrs2/archive/templates/layout.html diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt index fec8cfde03..d570225c79 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt @@ -48,6 +48,7 @@ public class CacheExporter @Inject constructor( val build: Int?, val timestamp: Instant?, val name: String?, + val description: String?, val archiveStats: ArchiveStats?, val groupStats: GroupStats? ) @@ -109,7 +110,7 @@ public class CacheExporter @Inject constructor( null } - caches += Cache(id, game, build, timestamp, name, archiveStats, groupStats) + caches += Cache(id, game, build, timestamp, name, description = null, archiveStats, groupStats) } caches @@ -118,6 +119,63 @@ public class CacheExporter @Inject constructor( } } + public suspend fun get(id: Int): Cache? { + return database.execute { connection -> + connection.prepareStatement( + """ + SELECT + g.name, m.build, m.timestamp, m.name, m.description, + a.indexes, a.valid_indexes, gs.groups, gs.valid_groups, gs.keys, gs.valid_keys + FROM master_indexes m + JOIN games g ON g.id = m.game_id + JOIN containers c ON c.id = m.container_id + LEFT JOIN master_index_archive_stats a ON a.master_index_id = m.id + LEFT JOIN master_index_group_stats gs ON gs.master_index_id = m.id + WHERE m.id = ? + """.trimIndent() + ).use { stmt -> + stmt.setInt(1, id) + + stmt.executeQuery().use { rows -> + if (!rows.next()) { + return@execute null + } + + val game = rows.getString(1) + + var build: Int? = rows.getInt(2) + if (rows.wasNull()) { + build = null + } + + val timestamp = rows.getTimestamp(3)?.toInstant() + val name = rows.getString(4) + val description = rows.getString(5) + + val indexes = rows.getLong(6) + val archiveStats = if (!rows.wasNull()) { + val validIndexes = rows.getLong(7) + ArchiveStats(indexes, validIndexes) + } else { + null + } + + val groups = rows.getLong(8) + val groupStats = if (!rows.wasNull()) { + val validGroups = rows.getLong(9) + val keys = rows.getLong(10) + val validKeys = rows.getLong(11) + GroupStats(groups, validGroups, keys, validKeys) + } else { + null + } + + return@execute Cache(id, game, build, timestamp, name, description, archiveStats, groupStats) + } + } + } + } + public suspend fun export(id: Int, store: Store) { database.execute { connection -> connection.prepareStatement( 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 7e1a7919ae..33a0c05834 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt @@ -26,6 +26,22 @@ public class CachesController @Inject constructor( call.respond(ThymeleafContent("caches/index.html", mapOf("caches" to caches))) } + public suspend fun show(call: ApplicationCall) { + val id = call.parameters["id"]?.toIntOrNull() + if (id == null) { + call.respond(HttpStatusCode.NotFound) + return + } + + val cache = exporter.get(id) + if (cache == null) { + call.respond(HttpStatusCode.NotFound) + return + } + + call.respond(ThymeleafContent("caches/show.html", mapOf("cache" to cache))) + } + public suspend fun export(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 33321d8053..60f85939bd 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/WebServer.kt @@ -43,6 +43,7 @@ public class WebServer @Inject constructor( routing { get("/caches") { cachesController.index(call) } + get("/caches/{id}") { cachesController.show(call) } get("/caches/{id}.zip") { cachesController.export(call) } get("/caches/{id}.json") { cachesController.exportKeys(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 2a5c5d6547..bd63ea56f3 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 @@ -1,21 +1,13 @@ - - OpenRS2 Archive + + Caches - OpenRS2 Archive - +
+

Caches

@@ -27,7 +19,7 @@ - + @@ -62,6 +54,8 @@ class="btn btn-primary btn-sm">CacheKeys + More 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 new file mode 100644 index 0000000000..c4c057815b --- /dev/null +++ b/archive/src/main/resources/org/openrs2/archive/templates/caches/show.html @@ -0,0 +1,69 @@ + + + + Cache - OpenRS2 Archive + + + + +
+

Cache

+ + +
Indexes Groups Keys1DownloadLinks
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Gamerunescape
Build550
Timestamp
Name
Description
Indexes + Calculating... +
Groups + Calculating... +
Keys1 + Calculating... +
Download +
+ Cache + Keys +
+
+
+ + diff --git a/archive/src/main/resources/org/openrs2/archive/templates/layout.html b/archive/src/main/resources/org/openrs2/archive/templates/layout.html new file mode 100644 index 0000000000..e6ba69243a --- /dev/null +++ b/archive/src/main/resources/org/openrs2/archive/templates/layout.html @@ -0,0 +1,23 @@ + + + + + OpenRS2 Archive + + + + +
+
+ +