[Slight source reorganization clinton@unknownlamer.org**20070823202959] { addfile ./start.lisp hunk ./src/golf.lisp 2 + +;;; Interview Database + +;; Database + +(defvar *db-spec* '(:bdb #P"/home/clinton/misc/bdb/golf/") + "Location of the Elephant Database") + +(defvar *db-store* nil + "Connection to the Elephant database") + +(defun connect () + (setq *db-store* (open-store *db-spec*))) + +(defun disconnect () + (setq *db-store* (close-store *db-spec*))) + +;; Audio Files + +;; TODO: check content-type against list of known audio file types +(defpclass audio-file () + ((type :initarg :type :accessor content-type) + (data :initarg :data :accessor raw-audio-data))) + +(defmethod content-length ((file audio-file)) + (length (raw-audio-data file))) + +(defmethod audio-file-stream ((file audio-file)) + (make-in-memory-input-stream (raw-audio-data file))) + +;; Shows + +(defpclass radio-show () + ((date :initarg :date :accessor show-date :index t :initform (get-universal-time)) + (audio :initarg :audio :accessor audio-data + :initform nil :type (or nil audio-file)) + (transcript :initarg :transcript :accessor transcript :initform ""))) + +;;; Web Application + +(defclass golf-application (modular-application + cookie-session-application-module + cms:lame-cms-application-module) + ()) + +;; Chooser + +(defcomponent choose-show () + ((shows :initarg :shows :accessor shows))) + +(defmethod render ((self choose-show)) + (<:ul + (mapc #'(lambda (show) + (<:li (bytes (mime-part-body (value audio-file)))))) + (setf (transcript show) (value transcript)))) + +(defmethod render ((editor show-editor)) + (with-slots (date audio-file transcript) + editor + (render date) + (render audio-file) + (render transcript) + (bytes (stream) + (let ((byte-buffer (make-array + (file-length stream) + :element-type 'unsigned-byte))) + (read-sequence byte-buffer stream) + byte-buffer)) + +(defentry-point "^(audio.ucw|)$" (:application *golf-test-app* + :class regexp-dispatcher) + (file) + (call 'audio-file-window + :audio-file (make-instance 'audio-file + :type :vorbis + :data (file->bytes (open + file + :element-type 'unsigned-byte))))) + +(defentry-point "dojo/dojo.js" (:application *golf-test-app* + :class url-dispatcher) + () + (ucw::serve-file #p"/home/clinton/local/var/wwwroot/dojo/dojo.js" + (context.request *context*) + (context.response *context*))) + + +(defun start-site () + (connect) + (ucw:create-server :backend '(:mod-lisp :port 3001 + :host "0.0.0.0") + :applications (list *golf-test-app*) + :log-level ucw::+dribble+)) hunk ./tee-it-up.asd 12 - (:file "tee-it-up") + (:file "golf") hunk ./tee-it-up.asd 15 - :depends-on (:fiveam :elephant :ucw)) + :depends-on (:elephant :ucw :cms :flexi-streams :metatilities)) }