From f1c347386eceb02f60f41792e8b0e00601977446 Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Thu, 9 Sep 2010 03:07:50 -0400 Subject: Add roomlist, per-room image limits --- src/admin.clj | 20 ++++++++++++++++++++ src/rooms.clj | 23 +++++++++++++---------- src/site.clj | 16 ++++++---------- 3 files changed, 39 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/admin.clj b/src/admin.clj index 7c7721e..9dbc65c 100644 --- a/src/admin.clj +++ b/src/admin.clj @@ -4,9 +4,29 @@ (:use compojure email scheduled-agent + rooms user utils)) +;; Rooms + +(defn count-room-users [key] + (if-let [r (rooms/lookup-room key)] + (count @(:users r)) + 0)) + + +(defn show-rooms [session] + (if-vip + (let [rooms (do-select ["SELECT * FROM ROOMS ORDER BY CREATED_ON ASC"]) + st (fetch-template "roomlist" session)] + (.setAttribute st "rooms" (for [r rooms] + (stringify-and-escape + (assoc r + :created_on (format-yyyy-mm-dd (:created_on r)) + :users (count-room-users (:key r)))))) + (.toString st)))) + ;; Muting (def *mute-refresh-period-sec* 60) diff --git a/src/rooms.clj b/src/rooms.clj index 4f7d6c4..e919557 100644 --- a/src/rooms.clj +++ b/src/rooms.clj @@ -1,6 +1,7 @@ (ns rooms (:import java.util.Date) (:use clojure.contrib.str-utils + clojure.contrib.def utils user)) @@ -68,15 +69,18 @@ (do-select [query room-id *dumps-per-page* offset])))) (defn build-room-map-from-db [room-db] - {:admin_only (room-db :admin_only) - :room_id (room-db :room_id) - :key (room-db :key) - :name (room-db :name) - :description (room-db :description) - :history_size (room-db :history_size) - :users (ref {}) - :messages (ref (fetch-messages-by-room (room-db :room_id) false)) - :topic (ref nil) + {:admin_only (room-db :admin_only) + :room_id (room-db :room_id) + :key (room-db :key) + :name (room-db :name) + :description (room-db :description) + :max_file_size (room-db :max_file_size) + :max_image_width (room-db :max_image_width) + :max_image_height (room-db :max_image_height) + :history_size (room-db :history_size) + :users (ref {}) + :messages (ref (fetch-messages-by-room (room-db :room_id) false)) + :topic (ref nil) }) @@ -97,7 +101,6 @@ (defn build-msg [nick content msg-id] (struct message-struct nick content (new Date) msg-id)) - (def message-count-limit 200) (defn add-message [msg room] diff --git a/src/site.clj b/src/site.clj index 30aa90e..560565a 100644 --- a/src/site.clj +++ b/src/site.clj @@ -1096,10 +1096,7 @@ WHERE u.user_id = ANY(?)" ;; Upload -(def max-upload-dimensions [2000 2000]) (def max-avatar-dimensions [800 800]) -(def max-vip-file-size (mbytes 5)) ; don't be nuts guys -(def max-file-size (mbytes 1)) (def max-avatar-size (kbytes 500)) (defn is-file-too-big? [f limit] @@ -1125,12 +1122,10 @@ WHERE u.user_id = ANY(?)" (defn image-url-from-file [dir date file] (str-join "/" [*server-url* dir date (.getName file)])) -(defn validate-upload-file [f vip] - (let [file-limit (if vip - max-vip-file-size - max-file-size)] - (or (is-file-too-big? f file-limit) - (invalid-image-dimensions? f max-upload-dimensions)))) +(defn validate-upload-file [f room] + (or (is-file-too-big? f (:max_file_size room)) + (invalid-image-dimensions? f [(:max_image_width room) + (:max_image_height room)]))) (defn validate-avatar-file [f] (or (is-file-too-big? f max-avatar-size) @@ -1145,7 +1140,7 @@ WHERE u.user_id = ANY(?)" ; responses. Therefore, return strings should not be JSON-encoded. (defn do-upload [session image room] - (if-let [err (validate-upload-file (image :tempfile) (is-vip? session))] + (if-let [err (validate-upload-file (image :tempfile) room)] (resp-error err) (let [filename (format-filename (:filename image) (session :nick)) date (today) @@ -1290,6 +1285,7 @@ WHERE u.user_id = ANY(?)" (GET "/debug" (debug-page session flash)) (POST "/debug" (debug-commmand! session params)) (GET "/mutes" (show-mutes session)) + (GET "/roomlist" (show-rooms session)) (POST "/mute" (mute! session params)) (POST "/cancel-mute" (handle-cancel-mute! session params)) (GET "/profile-test/:t" (profile session "ryder" (params :t))) -- cgit v1.2.3-70-g09d2