0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 07:50:43 -05:00

fix(backend): fix image uploading

This commit is contained in:
Andrey Antukh 2019-07-05 09:41:02 +02:00
parent 8a7f981f6e
commit b6b6fdf115
6 changed files with 22 additions and 12 deletions

View file

@ -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"}

View file

@ -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]

View file

@ -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))))

View file

@ -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 ".")

View file

@ -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

View file

@ -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