mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 23:18:48 -05:00
fix(backend): fix image uploading
This commit is contained in:
parent
8a7f981f6e
commit
b6b6fdf115
6 changed files with 22 additions and 12 deletions
|
@ -3,7 +3,10 @@
|
||||||
funcool/suricatta {:mvn/version "1.3.1"}
|
funcool/suricatta {:mvn/version "1.3.1"}
|
||||||
funcool/promesa {:mvn/version "2.0.1"}
|
funcool/promesa {:mvn/version "2.0.1"}
|
||||||
funcool/cuerdas {:mvn/version "2.2.0"}
|
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"}
|
funcool/struct {:mvn/version "1.4.0"}
|
||||||
|
|
||||||
ring/ring {:mvn/version "1.7.1"}
|
ring/ring {:mvn/version "1.7.1"}
|
||||||
|
|
|
@ -85,12 +85,8 @@
|
||||||
(rsp/ok))
|
(rsp/ok))
|
||||||
(rsp/not-found "")))))))
|
(rsp/not-found "")))))))
|
||||||
|
|
||||||
;; (s/def ::create-image
|
|
||||||
;; (s/keys :req-un [::file ::width ::height ::mimetype]
|
|
||||||
;; :opt-un [::us/id ::collection]))
|
|
||||||
|
|
||||||
(defn create-image
|
(defn create-image
|
||||||
{:parameters {:multipart {:upload [st/required]
|
{:parameters {:multipart {:file [st/required]
|
||||||
:id [st/uuid-str]
|
:id [st/uuid-str]
|
||||||
:width [st/required st/integer-str]
|
:width [st/required st/integer-str]
|
||||||
:height [st/required st/integer-str]
|
:height [st/required st/integer-str]
|
||||||
|
@ -98,7 +94,7 @@
|
||||||
:collection [st/uuid-str]}}}
|
:collection [st/uuid-str]}}}
|
||||||
[{:keys [user parameters] :as ctx}]
|
[{:keys [user parameters] :as ctx}]
|
||||||
(let [params (get parameters :multipart)
|
(let [params (get parameters :multipart)
|
||||||
upload (get params :upload)
|
upload (get params :file)
|
||||||
filename (fs/name (:filename upload))
|
filename (fs/name (:filename upload))
|
||||||
tempfile (:tempfile upload)
|
tempfile (:tempfile upload)
|
||||||
storage media/images-storage]
|
storage media/images-storage]
|
||||||
|
|
|
@ -83,6 +83,7 @@
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code (:key spec)
|
:code (:key spec)
|
||||||
:context errors
|
:context errors
|
||||||
|
:prop key
|
||||||
:value (get req key)
|
:value (get req key)
|
||||||
:message "Invalid data")
|
:message "Invalid data")
|
||||||
(assoc-in req [:parameters (:key spec)] result))))
|
(assoc-in req [:parameters (:key spec)] result))))
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
(or (string? input)
|
(or (string? input)
|
||||||
(fs/path input))]}
|
(fs/path input))]}
|
||||||
(let [parent (fs/parent 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]
|
suffix (->> [width height quality format]
|
||||||
(interpose ".")
|
(interpose ".")
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
|
|
||||||
(defstate assets-storage
|
(defstate assets-storage
|
||||||
:start (localfs {:basedir (:assets-directory config)
|
:start (localfs {:basedir (:assets-directory config)
|
||||||
:baseuri (:assets-uri config)}))
|
:baseuri (:assets-uri config)
|
||||||
|
:transform-filename str/uslug}))
|
||||||
|
|
||||||
(defstate media-storage
|
(defstate media-storage
|
||||||
:start (localfs {:basedir (:media-directory config)
|
:start (localfs {:basedir (:media-directory config)
|
||||||
:baseuri (:media-uri config)}))
|
:baseuri (:media-uri config)
|
||||||
|
:transform-filename str/uslug}))
|
||||||
|
|
||||||
(defstate images-storage
|
(defstate images-storage
|
||||||
:start (-> media-storage
|
:start (-> media-storage
|
||||||
|
|
|
@ -8,12 +8,20 @@
|
||||||
(:require [cognitect.transit :as t]
|
(:require [cognitect.transit :as t]
|
||||||
[uxbox.util.time :as dt])
|
[uxbox.util.time :as dt])
|
||||||
(:import java.io.ByteArrayInputStream
|
(:import java.io.ByteArrayInputStream
|
||||||
java.io.ByteArrayOutputStream))
|
java.io.ByteArrayOutputStream
|
||||||
|
java.io.File))
|
||||||
|
|
||||||
;; --- Handlers
|
;; --- Handlers
|
||||||
|
|
||||||
|
(def ^:private file-write-handler
|
||||||
|
(t/write-handler
|
||||||
|
(constantly "file")
|
||||||
|
(fn [v] (str v))))
|
||||||
|
|
||||||
(def +read-handlers+ dt/+read-handlers+)
|
(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
|
;; --- Low-Level Api
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue