From b6b6fdf1151e803d9301c02a9a6e306ae6a3f921 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 5 Jul 2019 09:41:02 +0200 Subject: [PATCH] fix(backend): fix image uploading --- backend/deps.edn | 5 ++++- backend/src/uxbox/api/images.clj | 8 ++------ backend/src/uxbox/http/middleware.clj | 1 + backend/src/uxbox/images.clj | 2 +- backend/src/uxbox/media.clj | 6 ++++-- backend/src/uxbox/util/transit.clj | 12 ++++++++++-- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/backend/deps.edn b/backend/deps.edn index 7c72ac773..54ecead9a 100644 --- a/backend/deps.edn +++ b/backend/deps.edn @@ -3,7 +3,10 @@ funcool/suricatta {:mvn/version "1.3.1"} funcool/promesa {:mvn/version "2.0.1"} funcool/cuerdas {:mvn/version "2.2.0"} - funcool/datoteka {:mvn/version "1.0.0"} + + funcool/datoteka {:git/url "https://github.com/funcool/datoteka.git" + :sha "b75f08fd59013577dd5e743d0b013dede6c6dc66"} + funcool/struct {:mvn/version "1.4.0"} ring/ring {:mvn/version "1.7.1"} diff --git a/backend/src/uxbox/api/images.clj b/backend/src/uxbox/api/images.clj index 048102bb3..ccde3cb5e 100644 --- a/backend/src/uxbox/api/images.clj +++ b/backend/src/uxbox/api/images.clj @@ -85,12 +85,8 @@ (rsp/ok)) (rsp/not-found ""))))))) -;; (s/def ::create-image -;; (s/keys :req-un [::file ::width ::height ::mimetype] -;; :opt-un [::us/id ::collection])) - (defn create-image - {:parameters {:multipart {:upload [st/required] + {:parameters {:multipart {:file [st/required] :id [st/uuid-str] :width [st/required st/integer-str] :height [st/required st/integer-str] @@ -98,7 +94,7 @@ :collection [st/uuid-str]}}} [{:keys [user parameters] :as ctx}] (let [params (get parameters :multipart) - upload (get params :upload) + upload (get params :file) filename (fs/name (:filename upload)) tempfile (:tempfile upload) storage media/images-storage] diff --git a/backend/src/uxbox/http/middleware.clj b/backend/src/uxbox/http/middleware.clj index 41731eb86..5bd2692ca 100644 --- a/backend/src/uxbox/http/middleware.clj +++ b/backend/src/uxbox/http/middleware.clj @@ -83,6 +83,7 @@ (ex/raise :type :validation :code (:key spec) :context errors + :prop key :value (get req key) :message "Invalid data") (assoc-in req [:parameters (:key spec)] result)))) diff --git a/backend/src/uxbox/images.clj b/backend/src/uxbox/images.clj index 0d6035a4b..3f1b2bf23 100644 --- a/backend/src/uxbox/images.clj +++ b/backend/src/uxbox/images.clj @@ -60,7 +60,7 @@ (or (string? input) (fs/path input))]} (let [parent (fs/parent input) - [filename ext] (fs/split-ext input) + [filename ext] (fs/split-ext (fs/name input)) suffix (->> [width height quality format] (interpose ".") diff --git a/backend/src/uxbox/media.clj b/backend/src/uxbox/media.clj index 0d1ebc156..a3b9e904d 100644 --- a/backend/src/uxbox/media.clj +++ b/backend/src/uxbox/media.clj @@ -18,11 +18,13 @@ (defstate assets-storage :start (localfs {:basedir (:assets-directory config) - :baseuri (:assets-uri config)})) + :baseuri (:assets-uri config) + :transform-filename str/uslug})) (defstate media-storage :start (localfs {:basedir (:media-directory config) - :baseuri (:media-uri config)})) + :baseuri (:media-uri config) + :transform-filename str/uslug})) (defstate images-storage :start (-> media-storage diff --git a/backend/src/uxbox/util/transit.clj b/backend/src/uxbox/util/transit.clj index 9f0159aa8..649b99dd4 100644 --- a/backend/src/uxbox/util/transit.clj +++ b/backend/src/uxbox/util/transit.clj @@ -8,12 +8,20 @@ (:require [cognitect.transit :as t] [uxbox.util.time :as dt]) (:import java.io.ByteArrayInputStream - java.io.ByteArrayOutputStream)) + java.io.ByteArrayOutputStream + java.io.File)) ;; --- Handlers +(def ^:private file-write-handler + (t/write-handler + (constantly "file") + (fn [v] (str v)))) + (def +read-handlers+ dt/+read-handlers+) -(def +write-handlers+ dt/+write-handlers+) +(def +write-handlers+ + (assoc dt/+write-handlers+ + File file-write-handler)) ;; --- Low-Level Api