|
|
|
@ -11,7 +11,7 @@ |
|
|
|
[hiccup.util :as util] |
|
|
|
[hiccup.util :as util] |
|
|
|
[notehub.storage :as storage])) |
|
|
|
[notehub.storage :as storage])) |
|
|
|
|
|
|
|
|
|
|
|
(def version "1.3") |
|
|
|
(def version "1.4") |
|
|
|
|
|
|
|
|
|
|
|
(def domain |
|
|
|
(def domain |
|
|
|
(get-setting |
|
|
|
(get-setting |
|
|
|
@ -60,11 +60,20 @@ |
|
|
|
(str domain (url year month day title)))))) |
|
|
|
(str domain (url year month day title)))))) |
|
|
|
|
|
|
|
|
|
|
|
(defn version-manager [f params] |
|
|
|
(defn version-manager [f params] |
|
|
|
(if-let [version (:version params)] |
|
|
|
(if-let [req-version (:version params)] |
|
|
|
(if (and (:noteID params) (< (Double/parseDouble version) 1.3)) |
|
|
|
(let [req-version (Double/parseDouble req-version) |
|
|
|
(let [resp (f (assoc params |
|
|
|
version (Double/parseDouble version)] |
|
|
|
:noteID (sreplace (params :noteID) #" " "/") |
|
|
|
(if (< req-version version) |
|
|
|
:noteID* (params :noteID))) |
|
|
|
(let [args params |
|
|
|
|
|
|
|
args (if (and (:noteID args) (< req-version 1.3)) |
|
|
|
|
|
|
|
(assoc args |
|
|
|
|
|
|
|
:noteID (sreplace (args :noteID) #" " "/") |
|
|
|
|
|
|
|
:noteID* (args :noteID)) |
|
|
|
|
|
|
|
args) |
|
|
|
|
|
|
|
args (if (and (:note args) (< req-version 1.4)) |
|
|
|
|
|
|
|
(assoc args :note* (sreplace (args :note) #"[\n\r]" "")) |
|
|
|
|
|
|
|
args) |
|
|
|
|
|
|
|
resp (f args) |
|
|
|
server-message (get-in resp [:status :message])] |
|
|
|
server-message (get-in resp [:status :message])] |
|
|
|
(assoc-in resp [:status :message] |
|
|
|
(assoc-in resp [:status :message] |
|
|
|
(str |
|
|
|
(str |
|
|
|
@ -72,7 +81,7 @@ |
|
|
|
(when server-message "; ") |
|
|
|
(when server-message "; ") |
|
|
|
"this API version is deprecated and " |
|
|
|
"this API version is deprecated and " |
|
|
|
"will be disabled by the end of June 2014!"))) |
|
|
|
"will be disabled by the end of June 2014!"))) |
|
|
|
(f params)) |
|
|
|
(f params))) |
|
|
|
{:status (create-response false "API version expected")})) |
|
|
|
{:status (create-response false "API version expected")})) |
|
|
|
|
|
|
|
|
|
|
|
(defn get-note [{:keys [noteID]}] |
|
|
|
(defn get-note [{:keys [noteID]}] |
|
|
|
@ -88,11 +97,12 @@ |
|
|
|
{:status (create-response false "noteID '%s' unknown" noteID)})) |
|
|
|
{:status (create-response false "noteID '%s' unknown" noteID)})) |
|
|
|
|
|
|
|
|
|
|
|
(defn post-note |
|
|
|
(defn post-note |
|
|
|
[{:keys [note pid signature password] :as params}] |
|
|
|
[{:keys [note pid signature password note*] :as params}] |
|
|
|
;(log "post-note: %s" {:pid pid :signature signature :password password :note note}) |
|
|
|
;(log "post-note: %s" {:pid pid :signature signature :password password :note note}) |
|
|
|
(let [errors (filter identity |
|
|
|
(let [errors (filter identity |
|
|
|
[(when-not (storage/valid-publisher? pid) "pid invalid") |
|
|
|
[(when-not (storage/valid-publisher? pid) "pid invalid") |
|
|
|
(when-not (= signature (storage/sign pid (storage/get-psk pid) note)) |
|
|
|
; TODO: remove note* after June 2014 |
|
|
|
|
|
|
|
(when-not (= signature (storage/sign pid (storage/get-psk pid) (or note* note))) |
|
|
|
"signature invalid") |
|
|
|
"signature invalid") |
|
|
|
(when (blank? note) "note is empty")])] |
|
|
|
(when (blank? note) "note is empty")])] |
|
|
|
(if (empty? errors) |
|
|
|
(if (empty? errors) |
|
|
|
@ -118,12 +128,14 @@ |
|
|
|
{:status (create-response false (first errors))}))) |
|
|
|
{:status (create-response false (first errors))}))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn update-note [{:keys [noteID note pid signature password noteID*]}] |
|
|
|
(defn update-note [{:keys [noteID note pid signature password noteID* note*]}] |
|
|
|
;(log "update-note: %s" {:pid pid :noteID noteID :signature signature :password password :note note}) |
|
|
|
;(log "update-note: %s" {:pid pid :noteID noteID :signature signature :password password :note note}) |
|
|
|
(let [errors (filter identity |
|
|
|
(let [errors (filter identity |
|
|
|
[(when-not (storage/valid-publisher? pid) "pid invalid") |
|
|
|
[(when-not (storage/valid-publisher? pid) "pid invalid") |
|
|
|
; TODO: noteID* is a hack introduced by backwards-comp. to older APIs |
|
|
|
; TODO: noteID* is a hack introduced by backwards-comp. to older APIs |
|
|
|
(when-not (= signature (storage/sign pid (storage/get-psk pid) (or noteID* noteID) note password)) |
|
|
|
(when-not (= signature (storage/sign pid (storage/get-psk pid) (or noteID* noteID) |
|
|
|
|
|
|
|
; TODO: remove note* after June 2014 |
|
|
|
|
|
|
|
(or note* note) password)) |
|
|
|
"signature invalid") |
|
|
|
"signature invalid") |
|
|
|
(when (blank? note) "note is empty") |
|
|
|
(when (blank? note) "note is empty") |
|
|
|
(when-not (storage/valid-password? noteID password) "password invalid")])] |
|
|
|
(when-not (storage/valid-password? noteID password) "password invalid")])] |
|
|
|
|