<commit_before>(ns iwaswhere-web.upload
  "Provides upload via REST call."
  (:require [ring.adapter.jetty :as j]
            [compojure.core :refer [routes POST PUT]]
            [clojure.java.io :as io]
            [iwaswhere-web.imports :as i]
            [iwaswhere-web.files :as f]
            [clojure.string :as s]))

(defn state-fn
  "Fires up REST endpoint that accepts import files:
    - /upload/text-entry.json
    - /upload/visits.json"
  [put-fn]
  (let [post-fn (fn [filename req put-fn]
                  (with-open [rdr (io/reader (:body req))]
                    (case filename
                      "text-entries.json" (i/import-text-entries-fn rdr put-fn {} filename)
                      "visits.json" (i/import-visits-fn rdr put-fn {} filename)
                      (prn req))
                    "OK"))
        audio-post-fn (fn [filename req put-fn]
                        (let [filename (str f/data-path "/audio/" filename)]
                          (prn req)
                          (io/copy (:body req) (java.io.File. filename)))
                        "OK")
        app (routes
              (PUT "/upload/audio/:filename" [filename :as r] (audio-post-fn filename r put-fn))
              (POST "/upload/:filename" [filename :as r] (post-fn filename r put-fn)))]
    (future
      (j/run-jetty app {:port 3001 :join? false})))
  {:state (atom {})})

(defn cmp-map
  [cmp-id]
  {:cmp-id   cmp-id
   :state-fn state-fn})
<commit_msg>general endpoint for binary uploads<commit_after>(ns iwaswhere-web.upload
  "Provides upload via REST call."
  (:require [ring.adapter.jetty :as j]
            [compojure.core :refer [routes POST PUT]]
            [clojure.java.io :as io]
            [iwaswhere-web.imports :as i]
            [iwaswhere-web.files :as f]
            [clojure.string :as s]))

(defn state-fn
  "Fires up REST endpoint that accepts import files:
    - /upload/text-entry.json
    - /upload/visits.json"
  [put-fn]
  (let [post-fn (fn [filename req put-fn]
                  (with-open [rdr (io/reader (:body req))]
                    (case filename
                      "text-entries.json" (i/import-text-entries-fn rdr put-fn {} filename)
                      "visits.json" (i/import-visits-fn rdr put-fn {} filename)
                      (prn req))
                    "OK"))
        binary-post-fn (fn [dir filename req]
                         (let [filename (str f/data-path "/" dir "/" filename)]
                           (prn req)
                           (io/copy (:body req) (java.io.File. filename)))
                         "OK")
        app (routes
              (PUT "/upload/:dir/:file" [dir file :as r] (binary-post-fn dir file r))
              (POST "/upload/:filename" [filename :as r] (post-fn filename r put-fn)))]
    (future
      (j/run-jetty app {:port 3001 :join? false})))
  {:state (atom {})})

(defn cmp-map
  [cmp-id]
  {:cmp-id   cmp-id
   :state-fn state-fn})

{'fraction_non_alphanumeric': 0.14276025771447948, 'fraction_numerical': 0.0027127839945744322, 'mean_word_length': 1.587719298245614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '520335', 'n_tokens_mistral': 973, 'n_tokens_neox': 945, 'n_words': 249}