<commit_before>(ns clj-codetip.handler
  (:require [liberator.core :refer [resource]]
            [liberator.dev :refer [wrap-trace]]
            [ring.middleware.params :refer [wrap-params]]
            [ring.server.standalone :refer [serve]]
            [clojure.java.jdbc :refer [with-db-connection]]
            [clojure.tools.logging :as log]
            [compojure.core :refer [defroutes ANY GET POST]]
            [compojure.route :as route]
            [clj-time.core :as t]
            [clj-codetip.database :as db]
            [clj-codetip.view :as view]))


(defn- expiry-name->date
  "Convert an expiration name into an absolute date."
  [expiry now]
  (t/plus now
          (condp = expiry
            "hour" (t/hours 1)
            "day"  (t/days 1)
            "week" (t/weeks 1))))


(defn- paste-title
  "Determine a suitable title for a paste."
  [{:keys [filename content-type]}]
  (format "Codetip \u2013 %s (%s)"
          filename
          (view/syntax-mime-modes content-type)))


(defroutes app
  (route/resources "/static")

  (GET  "/:id" [id]
        (resource
         :available-media-types ["text/html"]

         :service-available?
         (fn [{{conn :db-conn} :request}]
           {::paste (db/paste-by-id conn id)})

         :exists?
         (fn [{paste ::paste}]
           (not (nil? paste)))

         :handle-ok
         (fn [{paste ::paste}]
           (view/application (paste-title paste)<commit_msg>Implement a default expiration time if an invalid one is specified.<commit_after>(ns clj-codetip.handler
  (:require [liberator.core :refer [resource]]
            [liberator.dev :refer [wrap-trace]]
            [ring.middleware.params :refer [wrap-params]]
            [ring.server.standalone :refer [serve]]
            [clojure.java.jdbc :refer [with-db-connection]]
            [clojure.tools.logging :as log]
            [compojure.core :refer [defroutes ANY GET POST]]
            [compojure.route :as route]
            [clj-time.core :as t]
            [clj-codetip.database :as db]
            [clj-codetip.view :as view]))


(defn- expiry-name->date
  "Convert an expiration name into an absolute date."
  [expiry now]
  (t/plus now
          (condp = expiry
            "hour" (t/hours 1)
            "day"  (t/days 1)
            "week" (t/weeks 1)
            (t/hours 1))))


(defn- paste-title
  "Determine a suitable title for a paste."
  [{:keys [filename content-type]}]
  (format "Codetip \u2013 %s (%s)"
          filename
          (view/syntax-mime-modes content-type)))


(defroutes app
  (route/resources "/static")

  (GET  "/:id" [id]
        (resource
         :available-media-types ["text/html"]

         :service-available?
         (fn [{{conn :db-conn} :request}]
           {::paste (db/paste-by-id conn id)})

         :exists?
         (fn [{paste ::paste}]
           (not (nil? paste)))

         :handle-ok
         (fn [{paste ::paste}]
           (view/application (paste-title paste)
{'fraction_non_alphanumeric': 0.14535666218034993, 'fraction_numerical': 0.0050471063257065945, 'mean_word_length': 1.9406528189910979, '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': '3367684', 'n_tokens_mistral': 1018, 'n_tokens_neox': 958, 'n_words': 245}