|
|
|
@ -3,10 +3,12 @@ |
|
|
|
[java.util Calendar]) |
|
|
|
[java.util Calendar]) |
|
|
|
(:use |
|
|
|
(:use |
|
|
|
[NoteHub.settings] |
|
|
|
[NoteHub.settings] |
|
|
|
|
|
|
|
[ring.util.codec :only [url-encode]] |
|
|
|
[clojure.string :rename {replace sreplace} |
|
|
|
[clojure.string :rename {replace sreplace} |
|
|
|
:only [replace blank? lower-case split-lines split]]) |
|
|
|
:only [replace blank? lower-case split-lines split]]) |
|
|
|
(:require |
|
|
|
(:require |
|
|
|
[ring.util.codec] |
|
|
|
[ring.util.codec] |
|
|
|
|
|
|
|
[hiccup.util :as util] |
|
|
|
[NoteHub.storage :as storage])) |
|
|
|
[NoteHub.storage :as storage])) |
|
|
|
|
|
|
|
|
|
|
|
(def version "1.1") |
|
|
|
(def version "1.1") |
|
|
|
@ -23,6 +25,11 @@ |
|
|
|
(apply printf (str "%s:" string) (str (storage/get-current-date) ":LOG") args) |
|
|
|
(apply printf (str "%s:" string) (str (storage/get-current-date) ":LOG") args) |
|
|
|
(println)) |
|
|
|
(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 |
|
|
|
; Concatenates all fields to a string |
|
|
|
(defn build-key |
|
|
|
(defn build-key |
|
|
|
"Returns a storage-key for the given note coordinates" |
|
|
|
"Returns a storage-key for the given note coordinates" |
|
|
|
@ -51,7 +58,7 @@ |
|
|
|
(let [[year month day title] (split token #" ")] |
|
|
|
(let [[year month day title] (split token #" ")] |
|
|
|
(if description |
|
|
|
(if description |
|
|
|
(str domain "/" (storage/create-short-url token {:year year :month month :day day :title title})) |
|
|
|
(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")] |
|
|
|
(let [md5Instance (java.security.MessageDigest/getInstance "MD5")] |
|
|
|
(defn get-signature |
|
|
|
(defn get-signature |
|
|
|
@ -99,12 +106,13 @@ |
|
|
|
(map #(str proposed-title "-" (+ 2 %)) (range))))) |
|
|
|
(map #(str proposed-title "-" (+ 2 %)) (range))))) |
|
|
|
noteID (build-key date title) |
|
|
|
noteID (build-key date title) |
|
|
|
new-params (assoc params :year year :month month :day day :title 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 |
|
|
|
(do |
|
|
|
(storage/add-note noteID note pid password) |
|
|
|
(storage/add-note noteID note pid password) |
|
|
|
{:noteID noteID |
|
|
|
{:noteID noteID |
|
|
|
:longURL (get-path noteID) |
|
|
|
:longURL (if (empty? params) long-url (str (util/url long-url params))) |
|
|
|
:shortURL (get-path short-url :url) |
|
|
|
:shortURL short-url |
|
|
|
:status (create-response true)})) |
|
|
|
:status (create-response true)})) |
|
|
|
{:status (create-response false (first errors))})))) |
|
|
|
{:status (create-response false (first errors))})))) |
|
|
|
|
|
|
|
|
|
|
|
|