From 3c5999a892f575205401e683f90b219ecb35d2c1 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Fri, 16 Dec 2022 13:32:33 +0100 Subject: [PATCH] Provide HTML cap count --- Sources/App/CapServer.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sources/App/CapServer.swift b/Sources/App/CapServer.swift index 285f66d..5ab2b1d 100644 --- a/Sources/App/CapServer.swift +++ b/Sources/App/CapServer.swift @@ -9,6 +9,9 @@ final class CapServer { /// The file where the database of caps is stored private let dbFile: URL + + /// The file to store the HTML info of the cap count + private let htmlFile: URL private let classifierVersionFile: URL @@ -70,6 +73,7 @@ final class CapServer { init(in folder: URL, writers: [String]) throws { self.imageFolder = folder.appendingPathComponent("images") self.dbFile = folder.appendingPathComponent("caps.json") + self.htmlFile = folder.appendingPathComponent("count.html") self.classifierVersionFile = folder.appendingPathComponent("classifier.version") self.classifierFile = folder.appendingPathComponent("classifier.mlmodel") self.writers = Set(writers) @@ -83,6 +87,7 @@ final class CapServer { try loadCaps() try updateCounts() + saveCapCountHTML() } private func loadCaps() throws { @@ -127,6 +132,19 @@ final class CapServer { try data.write(to: dbFile) } + private func saveCapCountHTML() { + let count = caps.count + let content = + """ + +
+
\(count)
+
+ + """ + try? content.data(using: .utf8)!.write(to: htmlFile) + } + // MARK: Paths func folder(of cap: Int) -> URL { @@ -235,6 +253,7 @@ final class CapServer { cap.count = 0 cap.classifierVersion = nextClassifierVersion caps[cap.id] = cap + saveCapCountHTML() log("Added cap \(cap.id) '\(cap.name)'") }