diff options
author | Grant Shangreaux <grant@unabridgedsoftware.com> | 2023-01-07 16:07:03 -0600 |
---|---|---|
committer | Grant Shangreaux <grant@unabridgedsoftware.com> | 2023-01-07 16:07:03 -0600 |
commit | 08e561b5e876eac0f28126a953986bea53d0d111 (patch) | |
tree | 8269550565fadb1ecaf2f54f4154d4321565fb03 /zipper.lisp | |
parent | 745ada638b3f82b4e3076dd75d0fe8c0a47bfb31 (diff) |
Add: async zip download and manage link element
Diffstat (limited to 'zipper.lisp')
-rw-r--r-- | zipper.lisp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/zipper.lisp b/zipper.lisp index ede4a71..f83989f 100644 --- a/zipper.lisp +++ b/zipper.lisp @@ -2,9 +2,26 @@ (in-package :vampire) +(defvar *zip-cluster*) + +(defun start-zipper-service (config) + (let ((zipped-dir (merge-pathnames "media/bundled-playlists/" (static-directory config)))) + (ensure-directories-exist zipped-dir) + (setf *zip-cluster* (legion:make-cluster (downloader-threads config) + (lambda (job) (funcall job))))) + (legion:start *zip-cluster*)) + +(defun add-zip-playlist-job (playlist ok err) + "PLAYLIST is a PLAYLIST instance. OK ... ERR ..." + (legion:add-job + *zip-cluster* + (lambda () + (handler-case + (funcall ok (zip-playlist playlist)) + (error (e) (funcall err e)))))) + (defun zip-playlist (playlist) "Compresses playlist tracks into a zip archive." - (ensure-directories-exist (merge-pathnames "media/bundled-playlists/" (static-directory *config*))) (unless (zipped-playlist-exists-p playlist) (let ((zip-file (zipped-playlist-path playlist))) (with-temp-dir (tmpdir) @@ -43,7 +60,12 @@ do (uiop:copy-file file dest) collect dest)) -(defun delete-zipped-playlist (playlist) +(defun make-zipped-playlist-link (playlist context) + (when (zipped-playlist-exists-p playlist) + (create-a context :link (zipped-playlist-url playlist) :content "Download" :target "_blank"))) + +(defun delete-zipped-playlist (playlist-ctl) "Deletes the zipped playlist file. Returns T if it was deleted, NIL otherwise." - (princ "Deleting zipped playlist") - (uiop:delete-file-if-exists (zipped-playlist-path playlist))) + (print "Deleting zipped playlist") + (uiop:delete-file-if-exists (zipped-playlist-path (playlist playlist-ctl))) + (destroy (pl-zip playlist-ctl))) |