summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorckonstanski <carlos.konstanski@olo.com>2024-05-27 16:57:01 -0600
committerckonstanski <carlos.konstanski@olo.com>2024-05-27 16:57:01 -0600
commitebd383b0e0a6168f99857126897b07395e24b41c (patch)
treeb3b37d7dda1d7562ece14e9c2396aa9cf6f72f30 /lisp
parent6f397b2cd6b825a105a06591aa30469aab767591 (diff)
embed youtobe videos
Diffstat (limited to 'lisp')
-rw-r--r--lisp/service/gallery-service.lisp25
-rw-r--r--lisp/sql/gallery.lisp3
-rw-r--r--lisp/sql/general-pkg.lisp22
-rw-r--r--lisp/webapps/woodriverlessons/clojurescript/woodriverlessons/src/core.cljs21
-rw-r--r--lisp/webapps/woodriverlessons/site.lisp8
5 files changed, 45 insertions, 34 deletions
diff --git a/lisp/service/gallery-service.lisp b/lisp/service/gallery-service.lisp
index df709cd..b034075 100644
--- a/lisp/service/gallery-service.lisp
+++ b/lisp/service/gallery-service.lisp
@@ -47,11 +47,12 @@
nil
t
`((:name "description" :label "Description" :field-type "textarea")
- (:name "upload" :label "Image/Video" :field-type "file" :required "required")
+ (:name "video_embed_url" :label "Video embed URL" :field-type "text")
+ (:name "upload" :label "Image" :field-type "file")
(:label "Add Gallery" :field-type "button" :onclick "on_gallery_add_submit_clicked()"))))))
-(defun gallery-add-submit-json (description upload)
- (declare (special description))
+(defun gallery-add-submit-json (description video_embed_url upload)
+ (declare (special description video_embed_url))
(with-auth (instance gallery/add-modify-delete-service "gallery-modify")
(with-woodriverlessons-database
(let ((general-pkg (make-instance 'general-pkg))
@@ -63,12 +64,13 @@
(intersection `(,x) `(upload)))
(sb-introspect:function-lambda-list #'gallery-add-submit-json))
do (setf (slot-value gallery param) (symbol-value param)))
- (let ((tmpdir (tmpdir:mkdtemp :prefix "woodriverlessons-gallery-")))
- (setf new-filepath (format nil "~a~a" tmpdir (file-namestring tmp-filepath)))
- (fad:copy-file tmp-filepath new-filepath)
- (setf (filename gallery) orig-filename)
- (setf (mime_type gallery) (org-ckons-file::get-mime-type new-filepath))
- (setf (content gallery) (org-ckons-file::file-as-hex new-filepath)))
+ (when upload
+ (let ((tmpdir (tmpdir:mkdtemp :prefix "woodriverlessons-gallery-")))
+ (setf new-filepath (format nil "~a~a" tmpdir (file-namestring tmp-filepath)))
+ (fad:copy-file tmp-filepath new-filepath)
+ (setf (filename gallery) orig-filename)
+ (setf (mime_type gallery) (org-ckons-file::get-mime-type new-filepath))
+ (setf (content gallery) (org-ckons-file::file-as-hex new-filepath))))
(insert-gallery general-pkg gallery)
(setf (session-value :message) "Gallery added successfully.")))))
@@ -83,12 +85,13 @@
t
`((:name "id" :field-type "hidden" :value ,(id gallery) :required "required")
(:name "description" :label "Description" :value ,(description gallery) :field-type "textarea")
+ (:name "video_embed_url" :label "Video embed URL" :field-type "text" :value ,(video_embed_url gallery))
(:name "upload" :label "Image/Video" :field-type "file")
(:label "Modify Gallery" :field-type "button" :onclick "on_gallery_modify_submit_clicked()"))))
(setf (session-value :errormsg) "Error: could not modify gallery. Not found."))))))
-(defun gallery-modify-submit-json (id description upload)
- (declare (special description))
+(defun gallery-modify-submit-json (id description video_embed_url upload)
+ (declare (special description video_embed_url))
(with-auth (instance gallery/add-modify-delete-service "gallery-modify")
(with-woodriverlessons-database
(let* ((general-pkg (make-instance 'general-pkg))
diff --git a/lisp/sql/gallery.lisp b/lisp/sql/gallery.lisp
index 2f4231d..501691d 100644
--- a/lisp/sql/gallery.lisp
+++ b/lisp/sql/gallery.lisp
@@ -16,6 +16,9 @@
(mime_type :initarg :mime_type
:initform nil
:accessor mime_type)
+ (video_embed_url :initarg :video_embed_url
+ :initform nil
+ :accessor video_embed_url)
(content :initarg :content
:initform nil
:accessor content)
diff --git a/lisp/sql/general-pkg.lisp b/lisp/sql/general-pkg.lisp
index 5a92ed4..0d1b3db 100644
--- a/lisp/sql/general-pkg.lisp
+++ b/lisp/sql/general-pkg.lisp
@@ -23,20 +23,22 @@
(defmethod insert-gallery ((general-pkg general-pkg) (gallery gallery))
(setf (*table gallery) (format nil
- "general.insert_gallery('~a', '~a', '~a', '~a')"
- (description gallery)
- (filename gallery)
- (mime_type gallery)
- (content gallery)))
+ "general.insert_gallery(~a, ~a, ~a, ~a, ~a)"
+ (org-ckons-sql::sanitize gallery (description gallery))
+ (org-ckons-sql::sanitize gallery (filename gallery))
+ (org-ckons-sql::sanitize gallery (mime_type gallery))
+ (org-ckons-sql::sanitize gallery (video_embed_url gallery))
+ (org-ckons-sql::sanitize gallery (content gallery))))
(setf (id gallery) (caar (call-pg-function general-pkg gallery)))
(id gallery))
(defmethod update-gallery ((general-pkg general-pkg) (gallery gallery))
(setf (*table gallery) (format nil
- "general.update_gallery(~a, '~a', '~a', '~a', '~a')"
+ "general.update_gallery(~a, ~a, ~a, ~a, ~a, ~a)"
(id gallery)
- (description gallery)
- (filename gallery)
- (mime_type gallery)
- (content gallery)))
+ (org-ckons-sql::sanitize gallery (description gallery))
+ (org-ckons-sql::sanitize gallery (filename gallery))
+ (org-ckons-sql::sanitize gallery (mime_type gallery))
+ (org-ckons-sql::sanitize gallery (video_embed_url gallery))
+ (org-ckons-sql::sanitize gallery (content gallery))))
(caar (call-pg-function general-pkg gallery)))
diff --git a/lisp/webapps/woodriverlessons/clojurescript/woodriverlessons/src/core.cljs b/lisp/webapps/woodriverlessons/clojurescript/woodriverlessons/src/core.cljs
index 8a8d325..cc898be 100644
--- a/lisp/webapps/woodriverlessons/clojurescript/woodriverlessons/src/core.cljs
+++ b/lisp/webapps/woodriverlessons/clojurescript/woodriverlessons/src/core.cljs
@@ -607,7 +607,7 @@
[:tr
[:th {:scope "col"} "ID"]
[:th {:scope "col"} "Description"]
- [:th {:scope "col"} "Image/Video"]
+ [:th {:scope "col"} "Content"]
(when (get jsonobj "adminP")
[:th {:scope "col" :style "text-align: right;"} "Del"])]]
[:tbody
@@ -620,14 +620,17 @@
[:td {:onclick onclick} (get rec "id")]
[:td {:onclick onclick} (get rec "description")]
[:td
- (cond (str/includes? (get rec "mime_type") "image/")
- [:img {:height "400"
- :src (str "/gallery/file/view?id=" (get rec "id"))}]
- (str/includes? (get rec "mime_type") "video/")
- [:video {:height "400"
- :controls "controls"}
- [:source {:src (str "/gallery/file/view?id=" (get rec "id"))
- :type (get rec "mime_type")}]])]
+ (cond (not (= (get rec "video_embed_url") "null"))
+ [:iframe {:width "720"
+ :height "405"
+ :src (get rec "video_embed_url")
+ :frameborder "0"
+ :allow "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
+ :referrerpolicy "strict-origin-when-cross-origin"
+ :allowfullscreen "allowfullscreen"}]
+ :else
+ [:img {:height "405"
+ :src (str "/gallery/file/view?id=" (get rec "id"))}])]
(when (get jsonobj "adminP")
[:td {:style "text-align: right;"}
[:img {:src "/static/images/delete.png"
diff --git a/lisp/webapps/woodriverlessons/site.lisp b/lisp/webapps/woodriverlessons/site.lisp
index a1a6a82..d47b2b6 100644
--- a/lisp/webapps/woodriverlessons/site.lisp
+++ b/lisp/webapps/woodriverlessons/site.lisp
@@ -105,13 +105,13 @@
`(gallery-add-json))
(defmacro .gallery-add-submit ()
- `(gallery-add-submit-json description upload))
+ `(gallery-add-submit-json description video_embed_url upload))
(defmacro .gallery-modify ()
`(gallery-modify-json id))
(defmacro .gallery-modify-submit ()
- `(gallery-modify-submit-json id description upload))
+ `(gallery-modify-submit-json id description video_embed_url upload))
(defmacro .gallery-delete ()
`(gallery-delete-json id))
@@ -205,9 +205,9 @@
(define-endpoint :get "/gallery" () .gallery)
(define-endpoint :get "/gallery/view" () .gallery-view)
(define-endpoint :post "/gallery/add" () .gallery-add)
-(define-endpoint :post "/gallery/add/submit" ((description :parameter-type 'string) (upload :parameter-type 'string)) .gallery-add-submit)
+(define-endpoint :post "/gallery/add/submit" ((description :parameter-type 'string) (video_embed_url :parameter-type 'string) (upload :parameter-type 'string)) .gallery-add-submit)
(define-endpoint :post "/gallery/modify" ((id :parameter-type 'integer)) .gallery-modify)
-(define-endpoint :post "/gallery/modify/submit" ((id :parameter-type 'integer) (description :parameter-type 'string) (upload :parameter-type 'string)) .gallery-modify-submit)
+(define-endpoint :post "/gallery/modify/submit" ((id :parameter-type 'integer) (description :parameter-type 'string) (video_embed_url :parameter-type 'string) (upload :parameter-type 'string)) .gallery-modify-submit)
(define-endpoint :post "/gallery/delete" ((id :parameter-type 'integer)) .gallery-delete)
(define-endpoint :get "/gallery/file/view" ((id :parameter-type 'integer)) .gallery-file-view)
(define-endpoint :get "/testimonials" () .testimonials)