From 58b03ae8f23d5243b37366fb3060e89e9abd8fd1 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 24 Sep 2022 01:13:44 +0100 Subject: [PATCH] add create-time-stamp-id function in utils package. The only intended use for this function is to generate an Id. number which will be used in the Meilisearch database and linking it to Nera's database (I.E. this site's main database). --- src/utils.lisp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/utils.lisp b/src/utils.lisp index ac53f64..50d56ad 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -18,7 +18,8 @@ #:slugify #:get-image-dimensions #:run-bash-command - #:create-thumbnail) + #:create-thumbnail + #:create-timestamp-id) (:documentation "Utilities that do not depend on models.")) (in-package #:utils) @@ -102,7 +103,7 @@ The `FILEPATH' must be already merged with :ignore-error-status t :error-output :string)) -(defun create-thumbnail (file-name) +(defun create-thumbnail (storage-sub-directory file-name) "Runs a Bash command to convert a file to a thumbnail in /storage/media dir. The file is reduced to 512x512 pixels if bigger than that. A new file is then created with a 'thumbnail-' pre-fix. This process relies on @@ -110,5 +111,13 @@ Image Magick. So, it must be installed on the system for this function to operate properly." (run-bash-command (format nil "convert ~a -resize 512x512\\> ~a" - (storage:file-exists-p "" "media" file-name) - (storage:make-path "" "media" (format nil "thumbnail-~a" file-name))))) + (storage:file-exists-p "" storage-sub-directory file-name) + (storage:make-path "" storage-sub-directory + (format nil "thumbnail-~a" file-name))))) + +(defun create-timestamp-id () + "Creates a integer based on time the function is called, in YYYYMMDD format." + (multiple-value-bind + (second minute hour day month year) + (get-decoded-time) + (format nil "~d~2,'0d~d~2,'0d~2,'0d~2,'0d" year month day hour minute second)))