;;;; vampire.lisp (in-package #:vampire) ;;; SYSTEM CONFIG COMPONENT (defvar *config* nil) (defclass/std config () ((datastore-directory :ir :std #P"/srv/parasite/store/") (static-directory :ir :std #P"/srv/parasite/static/") (port :ir :std 4919) (downloader-threads :ir :std 5))) (defun config-from-file (path) "PATH should be a path to a file containing a PLIST suitable for passing as the keyword arguments to (MAKE-INSTANCE 'CONFIG ...)" (apply #'make-instance 'config (read-from-file path))) ;;; RESOURCE MODEL ;;; TRANSACTIONS ;;; CLIENT (defun create-new-playlist-form (parent &rest args) (declare (ignorable args)) (with-clog-create parent (div () (section (:h2 :content "Create New Playlist")) (label (:content "Playlist Title:")) (form-element (:text :bind pl-title)) (button (:content "Create" :bind btn))) (set-on-click btn (thunk* (new-playlist (session-user parent) :title (value pl-title)) (reload (location (connection-body parent))))))) (defun url-to-playlist (pl location) (format nil "~a//~a/playlist/~a" (protocol location) (host location) (key pl))) (defun create-playlist-listing (parent &rest args) (declare (ignorable args)) (dolist (pl (user-playlists (session-user parent))) (let ((url (url-to-playlist pl (location (connection-body parent))))) (with-clog-create parent (div () (section (:h4) (a (:link url :content (playlist-title pl) :bind pl-link)))) (set-on-click pl-link (thunk* (setf (url (location (connection-body parent))) url))))))) (defun main (body) (if (session-user body) (setf (url (location body)) "/home") (setf (url (location body)) "/login"))) ;;; STARTUP (defun initialize-database (config) (ensure-directories-exist (datastore-directory config)) (make-instance 'bknr.datastore:mp-store :directory (datastore-directory config) :subsystems (list (make-instance 'bknr.datastore:store-object-subsystem)))) (defun start (config) (setf *config* config) (initialize-database config ) (start-downloader-service config) (initialize 'main :extended-routing t :static-root (static-directory config)) (set-on-new-window 'user-home-page :path "/home") (set-on-new-window 'login-page :path "/login") (set-on-new-window 'playlist-page :path "/playlist") (set-on-new-window 'new-accout-page :path "/new-account") (open-browser)) (defun hacking-start () (start (make-instance 'config :static-directory (merge-pathnames "vampire-static/" (user-homedir-pathname)) :datastore-directory (merge-pathnames "vampire-store/" (user-homedir-pathname)))))