summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsostler <sbostler@gmail.com>2010-04-14 07:04:20 -0400
committersostler <sbostler@gmail.com>2010-04-14 07:04:20 -0400
commitb79243c7d06987672cffea75695e1036911dac13 (patch)
tree483f6b710c0b00803ef5d9ea943dd65b6d038b17
parentbf2f16d125d1905dc5867d371a0324ee09984494 (diff)
Mute file uploads
-rw-r--r--src/admin.clj11
-rw-r--r--src/site.clj28
-rw-r--r--static/js/pichat.js20
3 files changed, 37 insertions, 22 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)))))
diff --git a/static/js/pichat.js b/static/js/pichat.js
index d52212d..dc91a51 100644
--- a/static/js/pichat.js
+++ b/static/js/pichat.js
@@ -244,7 +244,8 @@ function submitMessage() {
var onSuccess = function(json) {
if (typeof pageTracker !== 'undefined') {
- pageTracker._trackEvent('Message', 'Submit', typeof Room !== 'undefined' ? Room : 'UnknownRoom');
+ pageTracker._trackEvent('Message', 'Submit',
+ typeof Room !== 'undefined' ? Room : 'UnknownRoom');
}
div.attr('id', 'message-' + json)
.removeClass('loading').addClass('loaded');
@@ -628,21 +629,26 @@ function setupUpload(elementId, roomKey) {
}
};
var onComplete = function(file, response) {
- if (response.match(/FILE_TOO_BIG/)) {
- var maxSize = response.split(" ")[1] / 1024;
+ r = $.trim(response);
+ if (r.match(/FILE_TOO_BIG/)) {
+ var maxSize = r.split(" ")[1] / 1024;
alert("Sorry. Your file is just too fucking big. "
+ maxSize + "KB or less please.");
return;
- } else if (response.match(/FILE_NOT_IMAGE/)) {
+ } else if (r.match(/FILE_NOT_IMAGE/)) {
alert("What did you upload? Doesn't seem like an image. Sorry.");
return;
- } else if (response.match(/INVALID_RESOLUTION/)) {
- var maxWidth = response.split(" ")[1];
- var maxHeight = response.split(" ")[2];
+ } else if (r.match(/INVALID_RESOLUTION/)) {
+ var maxWidth = r.split(" ")[1];
+ var maxHeight = r.split(" ")[2];
alert("Sorry, the maximum image resolution is "
+ maxWidth + "x" + maxHeight);
return;
+ } else if (r != "OK") {
+ alert(r);
+ return;
}
+
if (typeof pageTracker !== 'undefined') {
var r = typeof Room !== 'undefined' ? Room : 'UnknownRoom';
pageTracker._trackEvent('Message', 'Upload', r);