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)'") }