Browse Source

fix rails-to-caveman.storage function calls (Ch 13).

I was not using the full name for the 'storage' package and was
getting errors -- most notably when trying to rebuild the database
after applying the new features from Chapter 13.
master
Craig Oates 2 years ago
parent
commit
3907dcc699
  1. 4
      src/model.lisp
  2. 15
      src/storage.lisp
  3. 24
      src/web.lisp
  4. BIN
      storage/1/account/IygicHJvZmlsZS5wbmciIE5JTCAiaW1hZ2UvcG5nIik=

4
src/model.lisp

@ -572,9 +572,9 @@ reference for future projects. This is a learning project after all.
(file-length s)
:element-type '(unsigned-byte 8))))
(read-sequence vector s)
(storage::write
(rails-to-caveman.storage::write
(make-instance 'flex::vector-input-stream :vector vector) 1 "account"
(storage::make-file :name "profile.png" :content-type "image/png"))
(rails-to-caveman.storage::make-file :name "profile.png" :content-type "image/png"))
;; PROBLEM IS IN HERE....
))))))

15
src/storage.lisp

@ -28,18 +28,19 @@
rails-to-caveman.config::*application-root*))
(defun write (stream id subdirectory file)
;; (let ((path (ensure-directories-exist
;; (make-storage-pathname id subdirectory file))))
(let ((path "/home/craig/Desktop/test.png"))
(let ((path (ensure-directories-exist
(make-storage-pathname id subdirectory file))))
;; (let ((path "/home/craig/Desktop/test.png"))
(with-open-file (s path
:direction :output
:if-does-not-exist :create
:element-type '(unsigned-byte 8)
:if-exists nil)
(write-sequence (slot-value stream 'vector) s :start 0))))
;; (if s
;; (write-sequence (slot-value stream 'vector) s)
;; (warn "File already exists ~S~&Ignored." path))))
;; (write-sequence (slot-value stream 'vector) s :start 0))))
(format t "[INFO] The Stream is: " s)
(if s
(write-sequence (slot-value stream 'vector) s)
(warn "File already exists ~S~&Ignored." path)))))
(defun read (id subdirectory file)
(with-open-file (s (make-storage-pathname id subdirectory file)

24
src/web.lisp

@ -692,7 +692,7 @@ nil "/users/~D"(mito:object-id user))))))))
(rails-to-caveman.model::filename-of user))))
((_ nil) ; when specify new one, always remove old one.
(rails-to-caveman.model::purge user "account" image-file)
(storage::write (car image)
(rails-to-caveman.storage::write (car image)
(mito:object-id user) "account"
(make-image-file image)))
((nil _)) ; do not remove, no new one, so do nothing.
@ -707,12 +707,12 @@ nil "/users/~D"(mito:object-id user))))))))
(defun purge (user subdirectory filename)
(let (deletedp (id (mito:object-id user)))
(dolist (pathname (uiop:directory-files
(storage::make-storage-pathname id subdirectory))
(rails-to-caveman.storage::make-storage-pathname id subdirectory))
deletedp)
(let ((file (storage::read-from-base64-string (pathname-name pathname))))
(when (equal filename (storage::file-name file))
(let ((file (rails-to-caveman.storage::read-from-base64-string (pathname-name pathname))))
(when (equal filename (rails-to-caveman.storage::file-name file))
(setf deletedp t)
(storage::remove id subdirectory file))))))
(rails-to-caveman.storage::remove id subdirectory file))))))
(defroute("/account" :method :put)() )
(defroute("/account" :method :delete)() )
@ -764,7 +764,7 @@ nil "/users/~D"(mito:object-id user))))))))
:token ,(token)
:news ,(articles 5)
:blogs ,(entries :limit 5)))))
(progn (storage::write (car image)
(progn (rails-to-caveman.storage::write (car image)
(mito:object-id user)
(format nil "entry~A"entry-id)
(make-image-file image))
@ -832,7 +832,7 @@ nil "/users/~D"(mito:object-id user))))))))
(progn (unless (equal old
(rails-to-caveman.model::filename-of entry-image))
(rails-to-caveman.model::purge user subdirectory old)
(storage::write (car image)
(rails-to-caveman.storage::write (car image)
(mito:object-id user)
subdirectory (make-image-file image)))
(mito:save-dao entry-image)
@ -1184,17 +1184,17 @@ nil "/users/~D"(mito:object-id user))))))))
filename
size
content-type)
(let* ((original-file (storage::make-file :name filename
(let* ((original-file (rails-to-caveman.storage::make-file :name filename
:content-type content-type))
(to-load original-file))
(when size (let ((converted-file (storage::make-file :name filename
(when size (let ((converted-file (rails-to-caveman.storage::make-file :name filename
:size size
:content-type content-type)))
(unless (storage::probe-file id subdirectory converted-file)
(storage::convert id subdirectory original-file converted-file))
(unless (rails-to-caveman.storage::probe-file id subdirectory converted-file)
(rails-to-caveman.storage::convert id subdirectory original-file converted-file))
(setf to-load converted-file)))
(multiple-value-bind (content length)
(storage::read id subdirectory to-load)
(rails-to-caveman.storage::read id subdirectory to-load)
`(,status-code:+ok+ (:content-type ,content-type
:content-length ,length) ,content))))

BIN
storage/1/account/IygicHJvZmlsZS5wbmciIE5JTCAiaW1hZ2UvcG5nIik=

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Loading…
Cancel
Save