publisher removed from the statistics node of the API response
This commit is contained in:
+91
-90
@@ -41,119 +41,120 @@
|
|||||||
:body content})
|
:body content})
|
||||||
|
|
||||||
(defroutes api-routes
|
(defroutes api-routes
|
||||||
(GET "/note" {params :params}
|
(GET "/note" {params :params}
|
||||||
(generate-string (api/version-manager api/get-note params)))
|
(generate-string (api/version-manager api/get-note params)))
|
||||||
|
|
||||||
(POST "/note" {params :params}
|
(POST "/note" {params :params}
|
||||||
(generate-string (api/version-manager api/post-note params)))
|
(generate-string (api/version-manager api/post-note params)))
|
||||||
|
|
||||||
(PUT "/note" {params :params}
|
(PUT "/note" {params :params}
|
||||||
(generate-string (api/version-manager api/update-note params))))
|
(generate-string (api/version-manager api/update-note params))))
|
||||||
|
|
||||||
(defroutes app-routes
|
(defroutes app-routes
|
||||||
(GET "/api" [] (layout :no-js (get-message :api-title)
|
(GET "/api" [] (layout :no-js (get-message :api-title)
|
||||||
[:article (md-to-html (slurp "API.md"))]))
|
[:article (md-to-html (slurp "API.md"))]))
|
||||||
|
|
||||||
(context "/api" []
|
(context "/api" []
|
||||||
#(ring.util.response/content-type (api-routes %) "application/json"))
|
#(ring.util.response/content-type (api-routes %) "application/json"))
|
||||||
|
|
||||||
(GET "/" [] landing-page)
|
(GET "/" [] landing-page)
|
||||||
|
|
||||||
(GET "/:year/:month/:day/:title/export" [year month day title]
|
(GET "/:year/:month/:day/:title/export" [year month day title]
|
||||||
(when-let [md-text (:note (api/get-note {:noteID (api/build-key year month day title)}))]
|
(when-let [md-text (:note (api/get-note {:noteID (api/build-key year month day title)}))]
|
||||||
(return-content-type "text/plain; charset=utf-8" md-text)))
|
(return-content-type "text/plain; charset=utf-8" md-text)))
|
||||||
|
|
||||||
(GET "/:year/:month/:day/:title/stats" [year month day title]
|
(GET "/:year/:month/:day/:title/stats" [year month day title]
|
||||||
(let [note-id (api/build-key year month day title)]
|
(let [note-id (api/build-key year month day title)]
|
||||||
(statistics-page (api/derive-title (storage/get-note note-id))
|
(statistics-page (api/derive-title (storage/get-note note-id))
|
||||||
(storage/get-note-statistics note-id))))
|
(storage/get-note-statistics note-id)
|
||||||
|
(storage/get-publisher note-id))))
|
||||||
|
|
||||||
(GET "/:year/:month/:day/:title/edit" [year month day title]
|
(GET "/:year/:month/:day/:title/edit" [year month day title]
|
||||||
(let [note-id (api/build-key year month day title)]
|
(let [note-id (api/build-key year month day title)]
|
||||||
(note-update-page
|
(note-update-page
|
||||||
note-id
|
note-id
|
||||||
(:note (api/get-note {:noteID note-id})))))
|
(:note (api/get-note {:noteID note-id})))))
|
||||||
|
|
||||||
(GET "/new" [] (new-note-page
|
(GET "/new" [] (new-note-page
|
||||||
(str
|
(str
|
||||||
(current-timestamp)
|
(current-timestamp)
|
||||||
(storage/sign (rand-int Integer/MAX_VALUE)))))
|
(storage/sign (rand-int Integer/MAX_VALUE)))))
|
||||||
|
|
||||||
(GET "/:year/:month/:day/:title" [year month day title :as params]
|
(GET "/:year/:month/:day/:title" [year month day title :as params]
|
||||||
(let [params (assoc (:query-params params)
|
(let [params (assoc (:query-params params)
|
||||||
:year year :month month :day day :title title)
|
:year year :month month :day day :title title)
|
||||||
note-id (api/build-key year month day title)
|
note-id (api/build-key year month day title)
|
||||||
short-url (storage/create-short-url note-id params)]
|
short-url (storage/create-short-url note-id params)]
|
||||||
(when (storage/note-exists? note-id)
|
(when (storage/note-exists? note-id)
|
||||||
(if (cache/has? @page-cache short-url)
|
(if (cache/has? @page-cache short-url)
|
||||||
(do
|
(do
|
||||||
(swap! page-cache cache/hit short-url)
|
(swap! page-cache cache/hit short-url)
|
||||||
(storage/increment-note-view note-id))
|
(storage/increment-note-view note-id))
|
||||||
(swap! page-cache cache/miss short-url
|
(swap! page-cache cache/miss short-url
|
||||||
(note-page (api/get-note {:noteID note-id})
|
(note-page (api/get-note {:noteID note-id})
|
||||||
(api/url short-url))))
|
(api/url short-url))))
|
||||||
(cache/lookup @page-cache short-url))))
|
(cache/lookup @page-cache short-url))))
|
||||||
|
|
||||||
(GET "/:short-url" [short-url]
|
(GET "/:short-url" [short-url]
|
||||||
(when-let [params (storage/resolve-url short-url)]
|
(when-let [params (storage/resolve-url short-url)]
|
||||||
(let [{:keys [year month day title]} params
|
(let [{:keys [year month day title]} params
|
||||||
rest-params (dissoc params :year :month :day :title)
|
rest-params (dissoc params :year :month :day :title)
|
||||||
core-url (api/url year month day title)
|
core-url (api/url year month day title)
|
||||||
long-url (if (empty? rest-params) core-url (util/url core-url rest-params))]
|
long-url (if (empty? rest-params) core-url (util/url core-url rest-params))]
|
||||||
(redirect long-url))))
|
(redirect long-url))))
|
||||||
|
|
||||||
(POST "/post-note" [session note signature password]
|
(POST "/post-note" [session note signature password]
|
||||||
(if (and session
|
(if (and session
|
||||||
(.startsWith session
|
(.startsWith session
|
||||||
(str (current-timestamp)))
|
(str (current-timestamp)))
|
||||||
(= signature (storage/sign session note)))
|
(= signature (storage/sign session note)))
|
||||||
(let [pid "NoteHub"
|
(let [pid "NoteHub"
|
||||||
psk (storage/get-psk pid)
|
psk (storage/get-psk pid)
|
||||||
params {:note note
|
params {:note note
|
||||||
:pid pid
|
:pid pid
|
||||||
:signature (storage/sign pid psk note)
|
:signature (storage/sign pid psk note)
|
||||||
:password password}]
|
:password password}]
|
||||||
(if (storage/valid-publisher? pid)
|
(if (storage/valid-publisher? pid)
|
||||||
(let [resp (api/post-note params)]
|
(let [resp (api/post-note params)]
|
||||||
(if (get-in resp [:status :success])
|
(if (get-in resp [:status :success])
|
||||||
(redirect (:longURL resp))
|
(redirect (:longURL resp))
|
||||||
(response 400)))
|
(response 400)))
|
||||||
(response 500)))
|
(response 500)))
|
||||||
(response 400)))
|
(response 400)))
|
||||||
|
|
||||||
(POST "/update-note" [noteID note password]
|
(POST "/update-note" [noteID note password]
|
||||||
(let [pid "NoteHub"
|
(let [pid "NoteHub"
|
||||||
psk (storage/get-psk pid)
|
psk (storage/get-psk pid)
|
||||||
params {:noteID noteID :note note :password password :pid pid}]
|
params {:noteID noteID :note note :password password :pid pid}]
|
||||||
(if (storage/valid-publisher? pid)
|
(if (storage/valid-publisher? pid)
|
||||||
(let [resp (api/update-note (assoc params
|
(let [resp (api/update-note (assoc params
|
||||||
:signature
|
:signature
|
||||||
(storage/sign pid psk noteID note password)))]
|
(storage/sign pid psk noteID note password)))]
|
||||||
(if (get-in resp [:status :success])
|
(if (get-in resp [:status :success])
|
||||||
(do
|
(do
|
||||||
(doseq [url (storage/get-short-urls noteID)]
|
(doseq [url (storage/get-short-urls noteID)]
|
||||||
(swap! page-cache cache/evict url))
|
(swap! page-cache cache/evict url))
|
||||||
(redirect (:longURL resp)))
|
(redirect (:longURL resp)))
|
||||||
(response 403)))
|
(response 403)))
|
||||||
(response 500))))
|
(response 500))))
|
||||||
|
|
||||||
(route/resources "/")
|
(route/resources "/")
|
||||||
(route/not-found (response 404)))
|
(route/not-found (response 404)))
|
||||||
|
|
||||||
(def app
|
(def app
|
||||||
(let [handler (handler/site app-routes)]
|
(let [handler (handler/site app-routes)]
|
||||||
(fn [request]
|
(fn [request]
|
||||||
(let [{:keys [server-name server-port]} request
|
(let [{:keys [server-name server-port]} request
|
||||||
hostURL (str "https://" server-name
|
hostURL (str "https://" server-name
|
||||||
(when (not= 80 server-port) (str ":" server-port)))
|
(when (not= 80 server-port) (str ":" server-port)))
|
||||||
request (assoc-in request [:params :hostURL] hostURL)]
|
request (assoc-in request [:params :hostURL] hostURL)]
|
||||||
(if (get-setting :dev-mode)
|
(if (get-setting :dev-mode)
|
||||||
(handler request)
|
(handler request)
|
||||||
(try (handler request)
|
(try (handler request)
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(do
|
(do
|
||||||
;TODO (log e)
|
;TODO (log e)
|
||||||
(response 500)))))))))
|
(response 500)))))))))
|
||||||
|
|
||||||
(defn -main [& [port]]
|
(defn -main [& [port]]
|
||||||
(jetty/run-jetty #'app
|
(jetty/run-jetty #'app
|
||||||
|
|||||||
@@ -15,13 +15,13 @@
|
|||||||
(.update md5Instance (.getBytes input))
|
(.update md5Instance (.getBytes input))
|
||||||
(apply str
|
(apply str
|
||||||
(map #(let [c (Integer/toHexString (bit-and 0xff %))]
|
(map #(let [c (Integer/toHexString (bit-and 0xff %))]
|
||||||
(if (= 1 (count c)) (str "0" c) c))
|
(if (= 1 (count c)) (str "0" c) c))
|
||||||
(.digest md5Instance)))))))
|
(.digest md5Instance)))))))
|
||||||
|
|
||||||
(defmacro redis [cmd & body]
|
(defmacro redis [cmd & body]
|
||||||
`(car/wcar conn
|
`(car/wcar conn
|
||||||
(~(symbol "car" (name cmd))
|
(~(symbol "car" (name cmd))
|
||||||
~@body)))
|
~@body)))
|
||||||
|
|
||||||
(defn get-current-date []
|
(defn get-current-date []
|
||||||
(.getTime (java.util.Date.)))
|
(.getTime (java.util.Date.)))
|
||||||
@@ -72,8 +72,7 @@
|
|||||||
(defn get-note-statistics [noteID]
|
(defn get-note-statistics [noteID]
|
||||||
{:views (get-note-views noteID)
|
{:views (get-note-views noteID)
|
||||||
:published (redis :hget :published noteID)
|
:published (redis :hget :published noteID)
|
||||||
:edited (redis :hget :edited noteID)
|
:edited (redis :hget :edited noteID)})
|
||||||
:publisher (get-publisher noteID)})
|
|
||||||
|
|
||||||
(defn note-exists? [noteID]
|
(defn note-exists? [noteID]
|
||||||
(= 1 (redis :hexists :note noteID)))
|
(= 1 (redis :hexists :note noteID)))
|
||||||
|
|||||||
+10
-9
@@ -68,23 +68,24 @@
|
|||||||
[:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]]
|
[:a.landing-button {:href "/new" :style "color: white"} (get-message :new-page)]]
|
||||||
[:div#dashed-line]
|
[:div#dashed-line]
|
||||||
[:article.helvetica.bottom-space
|
[:article.helvetica.bottom-space
|
||||||
{:style "font-size: 1em"}
|
{:style "font-size: 1em"}
|
||||||
(md-to-html (slurp "LANDING.md"))]
|
(md-to-html (slurp "LANDING.md"))]
|
||||||
[:div#footer (md-to-html (get-message :footer))]))
|
[:div#footer (md-to-html (get-message :footer))]))
|
||||||
|
|
||||||
|
|
||||||
(defn statistics-page [note-title stats]
|
(defn statistics-page [note-title stats publisher]
|
||||||
(let [page-title (get-message :statistics)]
|
(let [page-title (get-message :statistics)
|
||||||
|
info (assoc stats :publisher publisher)]
|
||||||
(layout :no-js page-title
|
(layout :no-js page-title
|
||||||
[:h2.central-element note-title]
|
[:h2.central-element note-title]
|
||||||
[:h3.central-element.helvetica page-title]
|
[:h3.central-element.helvetica page-title]
|
||||||
[:table#stats.helvetica.central-element
|
[:table#stats.helvetica.central-element
|
||||||
(map
|
(map
|
||||||
#(when-let [v (% stats)]
|
#(when-let [v (% info)]
|
||||||
[:tr
|
[:tr
|
||||||
[:td (str (get-message %) ":")]
|
[:td (str (get-message %) ":")]
|
||||||
[:td (if (or (= % :published) (= % :edited))
|
[:td (if (or (= % :published) (= % :edited))
|
||||||
(str (java.util.Date. (Long/parseLong v))) v)]])
|
(str (java.util.Date. (Long/parseLong v))) v)]])
|
||||||
[:published :edited :publisher :views])])))
|
[:published :edited :publisher :views])])))
|
||||||
|
|
||||||
(defn note-update-page [note-id note]
|
(defn note-update-page [note-id note]
|
||||||
|
|||||||
Reference in New Issue
Block a user