<commit_before>;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 <NAME> <<EMAIL>>

(ns uxbox.frontend
  (:require [mount.core :refer [defstate]]
            [catacumba.core :as ct]
            [catacumba.http :as http]
            [catacumba.serializers :as sz]
            [catacumba.handlers.auth :as cauth]
            [catacumba.handlers.parse :as cparse]
            [catacumba.handlers.misc :as cmisc]
            [uxbox.config :as cfg]
            [uxbox.frontend.auth :as auth]
            [uxbox.frontend.users :as users]
            [uxbox.frontend.errors :as errors]
            [uxbox.frontend.projects :as projects]
            [uxbox.frontend.pages :as pages]
            [uxbox.frontend.images :as images]
            [uxbox.frontend.icons :as icons]
            [uxbox.frontend.kvstore :as kvstore]
            [uxbox.frontend.svgparse :as svgparse]
            [uxbox.frontend.debug-emails :as dbgemails]
            [uxbox.util.response :refer [rsp]]
            [uxbox.util.uuid :as uuid]))

;; --- Top Level Handlers

(defn- welcome-api
  "A GET entry point for the api that shows
  a welcome message."
  [context]
  (let [body {:message "Welcome to UXBox api."}]
    (-> (sz/encode body :json)
        (http/ok {:content-type "application/json"}))))

(defn- debug-only
  [context]
  (if (-> cfg/config :server :debug)
    (ct/delegate)
    (http/not-found "")))

;; --- Config

(def cors-conf
  {:origin "*"
   :max-age 3600
   :allow-methods #{:post :put :get :delete :trace}
   :allow-headers #{:x-requested-with :content-type :authorization}})

;; --- Routes

(defn routes
  ([] (routes cfg/config))
  ([config]
   (let [auth-opts {:secret cfg/secret
                    :options (:auth-options cfg/config)}]
     (ct/routes
      [[:any (cauth/auth (cauth/jwe-backend auth-opts))]
       [:any (cmisc/autoreloader)]

       [:get "api" #'welcome-api]
       [:assets "media" {:dir "public/media"}]
       [:assets "static" {:dir "public/static"}]

       [:prefix "debug"
        [:any debug-only]
        [:get "emails" #'dbgemails/list-emails]
        [:get "emails/email" #'dbgemails/show-email]]

       [:prefix "api"
        [:any (cmisc/cors cors-conf)]
        [:any (cparse/body-params)]
        [:error #'errors/handler]

        [:post "auth/token" #'auth/login]
        [:post "auth/register" #'users/register-user]
        [:get  "auth/recovery/:token" #'users/validate-recovery-token]
        [:post "auth/recovery" #'users/request-recovery]
        [:put  "auth/recovery" #'users/recover-password]

        [:get "projects-by-token/:token" #'projects/retrieve-project-by-share-token]

        ;; SVG Parse
        [:post "svg/parse" #'svgparse/parse]

        [:any #'auth/authorization]

        ;; KVStore
        [:put "kvstore" #'kvstore/update]
        [:get "kvstore/:key" #'kvstore/retrieve]
        [:delete "kvstore/:key" #'kvstore/delete]

        ;; Projects
        [:get "projects/:id/pages" #'pages/list-pages-by-project]
        [:put "projects/:id" #'projects/update-project]
        [:delete "projects/:id" #'projects/delete-project]
        [:post "projects" #'projects/create-project]
        [:get "projects" #'projects/list-projects]

        ;; Image Collections
        [:put "library/image-collections/:id" #'images/update-collection]
        [:delete "library/image-collections/:id" #'images/delete-collection]
        [:get "library/image-collections" #'images/list-collections]
        [:post "library/image-collections" #'images/create-collection]
        [:get "library/image-collections/:id/images" #'images/list-images]
        [:get "library/image-collections/images" #'images/list-images]

        ;; Images
        [:put "library/images/copy" #'images/copy-image]
        [:delete "library/images/:id" #'images/delete-image]
        [:get "library/images/:id" #'images/retrieve-image]
        [:put "library/images/:id" #'images/update-image]
        [:post "library/images" #'images/create-image]

        ;; Icon Collections
        [:put "library/icon-collections/:id" #'icons/update-collection]
        [:delete "library/icon-collections/:id" #'icons/delete-collection]
        [:get "library/icon-collections" #'icons/list-collections]
        [:post "library/icon-collections" #'icons/create-collection]
        [:get "library/icon-collections/:id/icons" #'icons/list-icons]
        [:get "library/icon-collections/icons" #'icons/list-icons]

        ;; Icons
        [:put "library/icons/copy" #'icons/copy-icon]<commit_msg>Make image retrieve endpoint public (without auth).<commit_after>;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 <NAME> <<EMAIL>>

(ns uxbox.frontend
  (:require [mount.core :refer [defstate]]
            [catacumba.core :as ct]
            [catacumba.http :as http]
            [catacumba.serializers :as sz]
            [catacumba.handlers.auth :as cauth]
            [catacumba.handlers.parse :as cparse]
            [catacumba.handlers.misc :as cmisc]
            [uxbox.config :as cfg]
            [uxbox.frontend.auth :as auth]
            [uxbox.frontend.users :as users]
            [uxbox.frontend.errors :as errors]
            [uxbox.frontend.projects :as projects]
            [uxbox.frontend.pages :as pages]
            [uxbox.frontend.images :as images]
            [uxbox.frontend.icons :as icons]
            [uxbox.frontend.kvstore :as kvstore]
            [uxbox.frontend.svgparse :as svgparse]
            [uxbox.frontend.debug-emails :as dbgemails]
            [uxbox.util.response :refer [rsp]]
            [uxbox.util.uuid :as uuid]))

;; --- Top Level Handlers

(defn- welcome-api
  "A GET entry point for the api that shows
  a welcome message."
  [context]
  (let [body {:message "Welcome to UXBox api."}]
    (-> (sz/encode body :json)
        (http/ok {:content-type "application/json"}))))

(defn- debug-only
  [context]
  (if (-> cfg/config :server :debug)
    (ct/delegate)
    (http/not-found "")))

;; --- Config

(def cors-conf
  {:origin "*"
   :max-age 3600
   :allow-methods #{:post :put :get :delete :trace}
   :allow-headers #{:x-requested-with :content-type :authorization}})

;; --- Routes

(defn routes
  ([] (routes cfg/config))
  ([config]
   (let [auth-opts {:secret cfg/secret
                    :options (:auth-options cfg/config)}]
     (ct/routes
      [[:any (cauth/auth (cauth/jwe-backend auth-opts))]
       [:any (cmisc/autoreloader)]

       [:get "api" #'welcome-api]
       [:assets "media" {:dir "public/media"}]
       [:assets "static" {:dir "public/static"}]

       [:prefix "debug"
        [:any debug-only]
        [:get "emails" #'dbgemails/list-emails]
        [:get "emails/email" #'dbgemails/show-email]]

       [:prefix "api"
        [:any (cmisc/cors cors-conf)]
        [:any (cparse/body-params)]
        [:error #'errors/handler]

        [:post "auth/token" #'auth/login]
        [:post "auth/register" #'users/register-user]
        [:get  "auth/recovery/:token" #'users/validate-recovery-token]
        [:post "auth/recovery" #'users/request-recovery]
        [:put  "auth/recovery" #'users/recover-password]

        [:get "library/images/:id" #'images/retrieve-image]

        [:get "projects-by-token/:token" #'projects/retrieve-project-by-share-token]

        ;; SVG Parse
        [:post "svg/parse" #'svgparse/parse]

        [:any #'auth/authorization]

        ;; KVStore
        [:put "kvstore" #'kvstore/update]
        [:get "kvstore/:key" #'kvstore/retrieve]
        [:delete "kvstore/:key" #'kvstore/delete]

        ;; Projects
        [:get "projects/:id/pages" #'pages/list-pages-by-project]
        [:put "projects/:id" #'projects/update-project]
        [:delete "projects/:id" #'projects/delete-project]
        [:post "projects" #'projects/create-project]
        [:get "projects" #'projects/list-projects]

        ;; Image Collections
        [:put "library/image-collections/:id" #'images/update-collection]
        [:delete "library/image-collections/:id" #'images/delete-collection]
        [:get "library/image-collections" #'images/list-collections]
        [:post "library/image-collections" #'images/create-collection]
        [:get "library/image-collections/:id/images" #'images/list-images]
        [:get "library/image-collections/images" #'images/list-images]

        ;; Images
        [:put "library/images/copy" #'images/copy-image]
        [:delete "library/images/:id" #'images/delete-image]
        [:put "library/images/:id" #'images/update-image]
        [:post "library/images" #'images/create-image]

        ;; Icon Collections
        [:put "library/icon-collections/:id" #'icons/update-collection]
        [:delete "library/icon-collections/:id" #'icons/delete-collection]
        [:get "library/icon-collections" #'icons/list-collections]
        [:post "library/icon-collections" #'icons/create-collection]
        [:get "library/icon-collections/:id/icons" #'icons/list-icons]
        [:get "library/icon-collections/icons" #'icons/list-icons]

        ;; Icons
        [:put "library/icons/copy" #'icons/copy-icon]
{'fraction_non_alphanumeric': 0.16430926300116985, 'fraction_numerical': 0.0025523769009890463, 'mean_word_length': 2.5313556139692075, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '5370664', 'n_tokens_mistral': 3223, 'n_tokens_neox': 3079, 'n_words': 645}