diff options
| author | sostler <sbostler@gmail.com> | 2010-04-14 07:04:20 -0400 |
|---|---|---|
| committer | sostler <sbostler@gmail.com> | 2010-04-14 07:04:20 -0400 |
| commit | b79243c7d06987672cffea75695e1036911dac13 (patch) | |
| tree | 483f6b710c0b00803ef5d9ea943dd65b6d038b17 /src | |
| parent | bf2f16d125d1905dc5867d371a0324ee09984494 (diff) | |
Mute file uploads
Diffstat (limited to 'src')
| -rw-r--r-- | src/admin.clj | 11 | ||||
| -rw-r--r-- | src/site.clj | 28 |
2 files changed, 24 insertions, 15 deletions
diff --git a/src/admin.clj b/src/admin.clj index 7bde945..0253734 100644 --- a/src/admin.clj +++ b/src/admin.clj @@ -50,9 +50,9 @@ (def *mute-refresh-period-sec* 60) (def fetch-mutes-query " -SELECT mutes.*, ((set_on + duration)) AS expiry -FROM mutes -WHERE (set_on + duration) > now() +SELECT mutes.*, (set_on + duration) AS expiry +FROM mutes +WHERE (set_on + duration) > now() AND NOT is_canceled ") @@ -91,3 +91,8 @@ AND NOT is_canceled user-id admin-id duration reason)] (and (do-cmds q) "OK")))))) + +(defn format-mute [mute] + (format (str "I'm sorry, you've been muted for %s. " + "You'll be able to post again on %s EST.") + (mute :reason) (mute :expiry))) diff --git a/src/site.clj b/src/site.clj index 234f5da..2b1fa94 100644 --- a/src/site.clj +++ b/src/site.clj @@ -642,10 +642,7 @@ now (new Date)] (cond (not room) (resp-error "BAD_ROOM") (not nick) (resp-error "NOT_LOGGED_IN") - mute (resp-error - (format (str "I'm sorry, you've been muted for %s. " - "You'll be able to post again on %s EST.") - (mute :reason) (mute :expiry))) + mute (resp-error (format-mute mute)) :else (let [msg-id (msg-db user-id (room :room_id) content) msg (struct message-struct nick content now msg-id)] @@ -866,12 +863,12 @@ (defn image-url-from-file [dir date file] (str-join "/" [*server-url* dir date (.getName file)])) -(defn validate-upload [f vip] +(defn validate-upload-file [f vip] (or (is-file-too-big? f vip) (is-image-invalid? f))) (defn do-upload [session image room] - (if-let [err (validate-upload (image :tempfile) (is-vip? session))] + (if-let [err (validate-upload-file (image :tempfile) (is-vip? session))] (resp-error err) (let [filename (format-filename (:filename image) (session :nick)) date (today) @@ -883,14 +880,21 @@ (dosync (add-message msg room)) (copy (:tempfile image) dest) - (resp-success url))))) + "OK")))) (defn upload [session params] - (let [room-key (params :room) - nick (session :nick) - image (params :image)] - (cond (not nick) [200 "NOT_LOGGED_IN"] - (not image) [200 "INVALID_REQUEST"] + (let [room-key (params :room) + nick (session :nick) + user-id (session :user_id) + mute ((poll *active-mutes*) user-id) + image (params :image)] + ; --TODO-- + ; Because ajaxupload.js doesn't feature an error-handler, + ; all responses not equal to "OK" signal errors. + (println mute (if mute (format-mute mute) nil)) + (cond (not nick) (resp-success "NOT_LOGGED_IN") + (not image) (resp-success "INVALID_REQUEST") + mute (resp-success (format-mute mute)) (not (validate-room-access room-key session)) [200 "UNKNOWN_ROOM"] :else (do-upload session image (lookup-room room-key))))) |
