summaryrefslogtreecommitdiff
path: root/zipper.lisp
diff options
context:
space:
mode:
authorGrant Shangreaux <grant@unabridgedsoftware.com>2023-01-08 16:01:48 -0600
committerGrant Shangreaux <grant@unabridgedsoftware.com>2023-01-08 16:01:48 -0600
commit040a7dc9970f1f402d99934f5cd5398bde4f28f8 (patch)
tree5b518703fb9cc6d293db6dc422a0ff2474f83250 /zipper.lisp
parent08e561b5e876eac0f28126a953986bea53d0d111 (diff)
Clean: code review feedback Add: extra filename cleaning
Removes the legion cluster for zipping and just uses inline zipping in a thunk before adding the link element to the DOM. Cleans more characters from filenames for the zip file. Ensures there aren't errors around deleting the zip file if it isn't there.
Diffstat (limited to 'zipper.lisp')
-rw-r--r--zipper.lisp32
1 files changed, 7 insertions, 25 deletions
diff --git a/zipper.lisp b/zipper.lisp
index f83989f..0271159 100644
--- a/zipper.lisp
+++ b/zipper.lisp
@@ -2,24 +2,6 @@
(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."
(unless (zipped-playlist-exists-p playlist)
@@ -32,12 +14,11 @@
(defun zip-track-filename (track pos)
"Return a filename for a track. `NN-ARTIST-ALBUM-TITLE.CODEC'"
(with-slots (artist album title codec) track
- (format nil "~2,'0d-~a-~a-~a.~a" pos
- (clean-slashes artist) (clean-slashes album) (clean-slashes title) codec)))
+ (clean-filename (format nil "~2,'0d-~a-~a-~a.~a" pos artist album title codec))))
(defun zipped-playlist-filename (playlist)
"Return a url-safe zip filename for a playlist."
- (concatenate 'string (clean-slashes (playlist-title playlist)) ".zip"))
+ (concatenate 'string (clean-filename (playlist-title playlist)) ".zip"))
(defun zipped-playlist-path (playlist)
"Returns the zipped playlist path relative to the configured static directory."
@@ -65,7 +46,8 @@
(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."
- (print "Deleting zipped playlist")
- (uiop:delete-file-if-exists (zipped-playlist-path (playlist playlist-ctl)))
- (destroy (pl-zip playlist-ctl)))
+ "Deletes the zipped playlist file and removes the associated link element.
+Returns T if it was deleted, NIL otherwise."
+ (when (uiop:delete-file-if-exists (zipped-playlist-path (playlist playlist-ctl)))
+ (unless (null (pl-zip playlist-ctl))
+ (destroy (pl-zip playlist-ctl)))))