mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 06:06:13 +02:00
Fix unexpected exception on uploading new image.
And additionally add spec for image entity on image collections related ns.
This commit is contained in:
parent
345a788cdd
commit
1172c56dfa
3 changed files with 52 additions and 14 deletions
|
@ -5,15 +5,45 @@
|
|||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.main.data.images
|
||||
(:require [cuerdas.core :as str]
|
||||
(:require [cljs.spec :as s]
|
||||
[cuerdas.core :as str]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.main.store :as st]
|
||||
[uxbox.main.repo :as rp]
|
||||
[uxbox.util.data :refer (jscoll->vec)]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.util.time :as ts]
|
||||
[uxbox.util.spec :as us]
|
||||
[uxbox.util.router :as r]
|
||||
[uxbox.util.files :as files]
|
||||
[uxbox.main.store :as st]
|
||||
[uxbox.main.repo :as rp]))
|
||||
[uxbox.util.files :as files]))
|
||||
|
||||
;; --- Specs
|
||||
|
||||
(s/def ::name string?)
|
||||
(s/def ::width number?)
|
||||
(s/def ::height number?)
|
||||
(s/def ::modified-at ts/instant?)
|
||||
(s/def ::created-at ts/instant?)
|
||||
(s/def ::mimetype string?)
|
||||
(s/def ::thumbnail us/url-str?)
|
||||
(s/def ::id uuid?)
|
||||
(s/def ::url us/url-str?)
|
||||
(s/def ::collection (s/nilable uuid?))
|
||||
(s/def ::user uuid?)
|
||||
|
||||
(s/def ::image-entity
|
||||
(s/keys :req-un [::id
|
||||
::name
|
||||
::width
|
||||
::height
|
||||
::created-at
|
||||
::modified-at
|
||||
::mimetype
|
||||
::thumbnail
|
||||
::url
|
||||
::collection
|
||||
::user]))
|
||||
|
||||
;; --- Initialize
|
||||
|
||||
|
@ -184,6 +214,7 @@
|
|||
|
||||
(defn image-created
|
||||
[item]
|
||||
{:pre [(us/valid? ::image-entity item)]}
|
||||
(ImageCreated. item))
|
||||
|
||||
;; --- Create Image
|
||||
|
@ -196,13 +227,13 @@
|
|||
(assoc-in state [:dashboard :images :uploading] true))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state s]
|
||||
(watch [_ state stream]
|
||||
(letfn [(image-size [file]
|
||||
(->> (files/get-image-size file)
|
||||
(rx/map (partial vector file))))
|
||||
(allowed-file? [file]
|
||||
(contains? allowed-file-types (.-type file)))
|
||||
(finalize-upload []
|
||||
(finalize-upload [state]
|
||||
(assoc-in state [:dashboard :images :uploading] false))
|
||||
(prepare [[file [width height]]]
|
||||
{:collection id
|
||||
|
@ -211,7 +242,7 @@
|
|||
:file file
|
||||
:width width
|
||||
:height height})]
|
||||
(->> (rx/from-coll (jscoll->vec files))
|
||||
(->> (rx/from-coll files)
|
||||
(rx/filter allowed-file?)
|
||||
(rx/mapcat image-size)
|
||||
(rx/map prepare)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
(ns uxbox.main.ui.dashboard.images
|
||||
(:require [cuerdas.core :as str]
|
||||
[lentes.core :as l]
|
||||
[uxbox.util.i18n :as t :refer (tr)]
|
||||
[uxbox.util.i18n :as t :refer [tr]]
|
||||
[uxbox.main.store :as st]
|
||||
[potok.core :as ptk]
|
||||
[uxbox.main.data.lightbox :as udl]
|
||||
|
@ -17,9 +17,9 @@
|
|||
[uxbox.util.mixins :as mx :include-macros true]
|
||||
[uxbox.main.ui.lightbox :as lbx]
|
||||
[uxbox.main.ui.keyboard :as kbd]
|
||||
[uxbox.main.ui.dashboard.header :refer (header)]
|
||||
[uxbox.main.ui.dashboard.header :refer [header]]
|
||||
[uxbox.util.time :as dt]
|
||||
[uxbox.util.data :as data :refer (read-string)]
|
||||
[uxbox.util.data :refer [read-string jscoll->vec]]
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
||||
;; --- Helpers & Constants
|
||||
|
@ -223,7 +223,8 @@
|
|||
(letfn [(forward-click [event]
|
||||
(dom/click (mx/ref-node own "file-input")))
|
||||
(on-file-selected [event]
|
||||
(let [files (dom/get-event-files event)]
|
||||
(let [files (dom/get-event-files event)
|
||||
files (jscoll->vec files)]
|
||||
(st/emit! (di/create-images coll-id files))))]
|
||||
(let [uploading? (mx/react uploading?-ref)]
|
||||
[:div.grid-item.add-project {:on-click forward-click}
|
||||
|
@ -371,8 +372,8 @@
|
|||
(let [editable? (or (= type :own) (nil? id))
|
||||
ordering (:order state :name)
|
||||
filtering (:filter state "")
|
||||
images (mx/react images-ref)
|
||||
images (->> (vals images)
|
||||
images-map (mx/react images-ref)
|
||||
images (->> (vals images-map)
|
||||
(filter #(= id (:collection %)))
|
||||
(filter-images-by filtering)
|
||||
(sort-images-by ordering))]
|
||||
|
|
|
@ -31,6 +31,12 @@
|
|||
[v]
|
||||
(instance? js/File v))
|
||||
|
||||
;; TODO: properly implement
|
||||
|
||||
(defn url-str?
|
||||
[v]
|
||||
(string? v))
|
||||
|
||||
;; --- Default Specs
|
||||
|
||||
(s/def ::uuid uuid?)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue