From 08e561b5e876eac0f28126a953986bea53d0d111 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Sat, 7 Jan 2023 16:07:03 -0600 Subject: Add: async zip download and manage link element --- zipper.lisp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'zipper.lisp') 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))) -- cgit v1.2.3