params added to long urls as well
This commit is contained in:
+18
-10
@@ -1,13 +1,15 @@
|
||||
(ns NoteHub.api
|
||||
(:import
|
||||
[java.util Calendar])
|
||||
[java.util Calendar])
|
||||
(:use
|
||||
[NoteHub.settings]
|
||||
[clojure.string :rename {replace sreplace}
|
||||
:only [replace blank? lower-case split-lines split]])
|
||||
[NoteHub.settings]
|
||||
[ring.util.codec :only [url-encode]]
|
||||
[clojure.string :rename {replace sreplace}
|
||||
:only [replace blank? lower-case split-lines split]])
|
||||
(:require
|
||||
[ring.util.codec]
|
||||
[NoteHub.storage :as storage]))
|
||||
[ring.util.codec]
|
||||
[hiccup.util :as util]
|
||||
[NoteHub.storage :as storage]))
|
||||
|
||||
(def version "1.1")
|
||||
|
||||
@@ -23,6 +25,11 @@
|
||||
(apply printf (str "%s:" string) (str (storage/get-current-date) ":LOG") args)
|
||||
(println))
|
||||
|
||||
(defn url
|
||||
"Creates a local url from the given substrings"
|
||||
[& args]
|
||||
(apply str (interpose "/" (cons "" (map url-encode args)))))
|
||||
|
||||
; Concatenates all fields to a string
|
||||
(defn build-key
|
||||
"Returns a storage-key for the given note coordinates"
|
||||
@@ -51,7 +58,7 @@
|
||||
(let [[year month day title] (split token #" ")]
|
||||
(if description
|
||||
(str domain "/" (storage/create-short-url token {:year year :month month :day day :title title}))
|
||||
(apply str (interpose "/" [domain year month day (ring.util.codec/url-encode title)]))))))
|
||||
(str domain (url year month day title))))))
|
||||
|
||||
(let [md5Instance (java.security.MessageDigest/getInstance "MD5")]
|
||||
(defn get-signature
|
||||
@@ -99,12 +106,13 @@
|
||||
(map #(str proposed-title "-" (+ 2 %)) (range)))))
|
||||
noteID (build-key date title)
|
||||
new-params (assoc params :year year :month month :day day :title title)
|
||||
short-url (storage/create-short-url noteID new-params)]
|
||||
short-url (get-path (storage/create-short-url noteID new-params) :url)
|
||||
long-url (get-path noteID)]
|
||||
(do
|
||||
(storage/add-note noteID note pid password)
|
||||
{:noteID noteID
|
||||
:longURL (get-path noteID)
|
||||
:shortURL (get-path short-url :url)
|
||||
:longURL (if (empty? params) long-url (str (util/url long-url params)))
|
||||
:shortURL short-url
|
||||
:status (create-response true)}))
|
||||
{:status (create-response false (first errors))}))))
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
[noir.util.crypt :only [encrypt]]
|
||||
[hiccup.form]
|
||||
[hiccup.core]
|
||||
[ring.util.codec :only [url-encode]]
|
||||
[hiccup.element]
|
||||
[hiccup.util :only [escape-html]]
|
||||
[hiccup.page :only [include-js html5]]
|
||||
@@ -54,11 +53,6 @@
|
||||
[code]
|
||||
(status code (get-page code)))
|
||||
|
||||
(defn url
|
||||
"Creates a local url from the given substrings"
|
||||
[& args]
|
||||
(apply str (interpose "/" (cons "" (map url-encode args)))))
|
||||
|
||||
; input form for the markdown text with a preview area
|
||||
(defpartial input-form [form-url command fields content passwd-msg]
|
||||
(let [css-class (when (= :publish command) :hidden)]
|
||||
@@ -113,7 +107,7 @@
|
||||
(md-node :article.bottom-space (:note note))
|
||||
(let [links (map #(link-to
|
||||
(if (= :short-url %)
|
||||
(url (storage/create-short-url noteID params))
|
||||
(api/url (storage/create-short-url noteID params))
|
||||
(str (:longURL note) "/" (name %)))
|
||||
(get-message %))
|
||||
[:stats :edit :export :short-url])
|
||||
@@ -137,7 +131,7 @@
|
||||
(when-let [params (storage/resolve-url short-url)]
|
||||
(let [{:keys [year month day title]} params
|
||||
rest-params (dissoc params :year :month :day :title)
|
||||
core-url (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))]
|
||||
(redirect long-url))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user