<commit_before>(ns mirror.middleware
  (:require [mirror.core :as c]
            [mirror.ws :as ws]
            [aleph.http :as http]
            [manifold.stream :as s]
            [ring.middleware.file :refer (wrap-file)]
            [ring.middleware.resource :refer (wrap-resource)]
            [ring.util.response :refer (response header redirect status)]))

(defn wrap-pages [h pages-path static-path]
  (fn [req]
    (if (not (c/page-exists? pages-path (c/extract-path-kw req)))
      (h req)
      (c/serve-page pages-path static-path (c/extract-path-kw req)))))

(defn handler [req]
  (if (= "/_ws" (:uri req))
    (do
      (let [s @(http/websocket-connection req)]
        (println "websocket connection")
        (swap! ws/ws-conns conj s))))
  (response "page not found"))

(defn make-handler [pages-path static-path]
  (-> #'handler
      (wrap-pages pages-path static-path)
      (wrap-file static-path)
      (wrap-image-crop static-path)
      (wrap-resource "/")))

<commit_msg>add required middleware<commit_after>(ns mirror.middleware
  (:require [mirror.core :as c]
            [mirror.ws :as ws]
            [aleph.http :as http]
            [manifold.stream :as s]
            [ring.middleware.params :refer (wrap-params)]
            [ring.middleware.keyword-params :refer (wrap-keyword-params)]
            [ring.middleware.file :refer (wrap-file)]
            [ring.middleware.resource :refer (wrap-resource)]
            [ring.util.response :refer (response header redirect status)]
            [ring-image-crop.core :refer (wrap-image-crop)]))

(defn wrap-pages [h pages-path static-path]
  (fn [req]
    (if (not (c/page-exists? pages-path (c/extract-path-kw req)))
      (h req)
      (c/serve-page pages-path static-path (c/extract-path-kw req)))))

(defn handler [req]
  (if (= "/_ws" (:uri req))
    (do
      (let [s @(http/websocket-connection req)]
        (println "websocket connection")
        (swap! ws/ws-conns conj s))))
  (response "page not found"))

(defn make-handler [pages-path static-path]
  (-> #'handler
      (wrap-pages pages-path static-path)
      (wrap-file static-path)
      (wrap-image-crop static-path)
      (wrap-keyword-params)
      (wrap-params)
      (wrap-resource "/")))


{'fraction_non_alphanumeric': 0.1575892857142857, 'fraction_numerical': 0.0, 'mean_word_length': 2.4476923076923076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1847584', 'n_tokens_mistral': 759, 'n_tokens_neox': 748, 'n_words': 179}