Endpoint for serving recording JSON file
parent
be4995c9f9
commit
0eda5c040c
@ -0,0 +1,21 @@
|
||||
(ns asciinema.endpoint.asciicasts
|
||||
(:require [asciinema.boundary
|
||||
[asciicast-database :as adb]
|
||||
[file-server :as fserver]]
|
||||
[asciinema.model.asciicast :as asciicast]
|
||||
[compojure.api.sweet :refer :all]
|
||||
[ring.util.http-response :as response]
|
||||
[schema.core :as s]))
|
||||
|
||||
(defn asciicasts-endpoint [{:keys [db file-server]}]
|
||||
(api
|
||||
(context
|
||||
"/a" []
|
||||
(GET "/:token.json" []
|
||||
:path-params [token :- String]
|
||||
:query-params [{dl :- s/Bool false}]
|
||||
(if-let [asciicast (adb/get-asciicast-by-token db token)]
|
||||
(let [path (asciicast/json-store-path asciicast)
|
||||
filename (str "asciicast-" (:id asciicast) ".json")]
|
||||
(fserver/serve file-server path (when dl {:filename filename})))
|
||||
(response/not-found))))))
|
Loading…
Reference in New Issue