Move SSD tree MIME selection to typed Kotlin

ober

07aa3ee26694fdb9a4de40108012e1c9438e9235

diff --git a/templates/ssd-review.ss b/templates/ssd-review.ss
index 9318ba2..0f791e0 100644
--- a/templates/ssd-review.ss
+++ b/templates/ssd-review.ss
@@ -4546,7 +4546,8 @@
 
     (typed-kotlin-file "com/sfb/ssdreview/PathSafety.kt"
       (typed-library (com sfb ssdreview)
-        (export safePathComponent safeLeaf safeZipEntryName validSourceKey validatedSourceKey)
+        (export safePathComponent safeLeaf safeZipEntryName validSourceKey
+                validatedSourceKey treeFileMime)
         (def (safePathComponent (name : String)) : Bool
           (let ((n (string-length name)))
             (and (and (>= n 1) (<= n 128))
@@ -4557,6 +4558,12 @@
           (and (safePathComponent name)
                (or (string-ends-with? name ".json")
                    (string-ends-with? name ".jsonl"))))
+        (def (treeFileMime (name : String)) : String
+          (if (string-ends-with? name ".json")
+            "application/json"
+            (if (string-ends-with? name ".jsonl")
+              "application/x-ndjson"
+              "application/octet-stream")))
         (def (safeZipEntryName (name : String)) : Bool
           (let ((n (string-length name)))
             (and (and (>= n 1) (<= n 240))
@@ -7799,11 +7806,7 @@
        "        var dir = parent"
        "        parts.dropLast(1).forEach { dir = ensureTreeDir(dir, it) }"
        "        dir.findFile(fileName)?.delete()"
-       "        val mime = when {"
-       "            fileName.endsWith(\".json\") -> \"application/json\""
-       "            fileName.endsWith(\".jsonl\") -> \"application/x-ndjson\""
-       "            else -> \"application/octet-stream\""
-       "        }"
+       "        val mime = treeFileMime(fileName)"
        "        val doc = dir.createFile(mime, fileName)"
        "            ?: throw IllegalStateException(\"Unable to create $fileName\")"
        "        context.contentResolver.openOutputStream(doc.uri)?.use { output ->"