note deletion completed
This commit is contained in:
+2
-2
@@ -48,7 +48,7 @@
|
||||
(defn- get-path [noteID & description]
|
||||
(let [[year month day title] (split noteID #" ")]
|
||||
(if description
|
||||
(str domain "/" (storage/create-short-url {:year year :month month :day day :title title}))
|
||||
(str domain "/" (storage/create-short-url noteID {:year year :month month :day day :title title}))
|
||||
(apply str (interpose "/" [domain year month day (ring.util.codec/url-encode title)])))))
|
||||
|
||||
(let [md5Instance (java.security.MessageDigest/getInstance "MD5")]
|
||||
@@ -94,7 +94,7 @@
|
||||
(cons proposed-title
|
||||
(map #(str proposed-title "-" (+ 2 %)) (range)))))
|
||||
noteID (build-key date title)
|
||||
short-url (storage/create-short-url {:year year :month month :day day :title title})]
|
||||
short-url (storage/create-short-url noteID {:year year :month month :day day :title title})]
|
||||
(do
|
||||
(storage/add-note noteID note pid password)
|
||||
{:noteID noteID
|
||||
|
||||
+16
-12
@@ -78,11 +78,6 @@
|
||||
(redis :hincrby :views noteID 1)
|
||||
(redis :hget :note noteID))))
|
||||
|
||||
(defn delete-note [noteID]
|
||||
(doseq [kw [:password :views :note :published :edited :publisher]]
|
||||
; TODO: delete short url by looking for the title
|
||||
(redis :hdel kw noteID)))
|
||||
|
||||
(defn short-url-exists? [url]
|
||||
(= 1 (redis :hexists :short-url url)))
|
||||
|
||||
@@ -94,16 +89,23 @@
|
||||
(when value ; TODO: necessary?
|
||||
(read-string value))))
|
||||
|
||||
(defn delete-short-url [noteID]
|
||||
(let [value (redis :hget :short-url noteID)]
|
||||
(redis :hdel :short-url noteID)
|
||||
(redis :hdel :short-url value)))
|
||||
(defn delete-short-url [url]
|
||||
(when-let [params (redis :hget :short-url url)]
|
||||
(redis :hdel :short-url params)
|
||||
(redis :hdel :short-url url)))
|
||||
|
||||
(defn delete-note [noteID]
|
||||
(doseq [kw [:password :views :note :published :edited :publisher]]
|
||||
(redis :hdel kw noteID))
|
||||
(doseq [url (redis :smembers (str noteID :urls))]
|
||||
(delete-short-url url))
|
||||
(redis :del (str noteID :urls)))
|
||||
|
||||
(defn create-short-url
|
||||
"Creates a short url for the given request metadata or extracts
|
||||
one if it was already created"
|
||||
[arg]
|
||||
(let [key (str (into (sorted-map) arg))]
|
||||
[noteID params]
|
||||
(let [key (str (into (sorted-map) params))]
|
||||
(if (short-url-exists? key)
|
||||
(redis :hget :short-url key)
|
||||
(let [hash-stream (partition 5 (repeatedly #(rand-int 36)))
|
||||
@@ -119,4 +121,6 @@
|
||||
; s.t. we can later easily check whether a short url already exists
|
||||
(redis :hset :short-url url key)
|
||||
(redis :hset :short-url key url)
|
||||
url))))
|
||||
; we save all short urls of a note for removal later
|
||||
(redis :sadd (str noteID :urls) url)
|
||||
url))))
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
(md-node :article.bottom-space (:note note))
|
||||
(let [links (map #(link-to
|
||||
(if (= :short-url %)
|
||||
(url (storage/create-short-url params))
|
||||
(url (storage/create-short-url noteID params))
|
||||
(str (:longURL note) "/" (name %)))
|
||||
(get-message %))
|
||||
[:stats :edit :export :short-url])
|
||||
|
||||
Reference in New Issue
Block a user