mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 15:11:39 +02:00
Merge remote-tracking branch 'origin/staging' into develop
This commit is contained in:
commit
ee1b9e861e
3 changed files with 42 additions and 11 deletions
|
@ -14,6 +14,7 @@
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.http.client :as http]
|
[app.http.client :as http]
|
||||||
|
[app.loggers.audit :as-alias audit]
|
||||||
[app.media :as media]
|
[app.media :as media]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
[app.rpc.climit :as climit]
|
[app.rpc.climit :as climit]
|
||||||
|
@ -68,8 +69,15 @@
|
||||||
(files/check-edition-permissions! pool profile-id file-id)
|
(files/check-edition-permissions! pool profile-id file-id)
|
||||||
(media/validate-media-type! content)
|
(media/validate-media-type! content)
|
||||||
(validate-content-size! content)
|
(validate-content-size! content)
|
||||||
|
(->> (create-file-media-object cfg params)
|
||||||
(create-file-media-object cfg params)))
|
(p/fmap (fn [object]
|
||||||
|
(with-meta object
|
||||||
|
{::audit/replace-props
|
||||||
|
{:name (:name params)
|
||||||
|
:file-id file-id
|
||||||
|
:is-local (:is-local params)
|
||||||
|
:size (:size content)
|
||||||
|
:mtype (:mtype content)}}))))))
|
||||||
|
|
||||||
(defn- big-enough-for-thumbnail?
|
(defn- big-enough-for-thumbnail?
|
||||||
"Checks if the provided image info is big enough for
|
"Checks if the provided image info is big enough for
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
[app.util.keyboard :as kbd]
|
[app.util.keyboard :as kbd]
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[app.util.timers :as timers]
|
[app.util.timers :as timers]
|
||||||
|
[app.util.webapi :as wapi]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
@ -434,7 +435,9 @@
|
||||||
(:id component)
|
(:id component)
|
||||||
(gpt/point final-x final-y))))
|
(gpt/point final-x final-y))))
|
||||||
|
|
||||||
;; Will trigger when the user drags an image from a browser to the viewport (firefox and chrome do it a bit different depending on the origin)
|
;; Will trigger when the user drags an image from a browser
|
||||||
|
;; to the viewport (firefox and chrome do it a bit different
|
||||||
|
;; depending on the origin)
|
||||||
(dnd/has-type? event "Files")
|
(dnd/has-type? event "Files")
|
||||||
(let [files (dnd/get-files event)
|
(let [files (dnd/get-files event)
|
||||||
params {:file-id (:id file)
|
params {:file-id (:id file)
|
||||||
|
@ -442,16 +445,19 @@
|
||||||
:blobs (seq files)}]
|
:blobs (seq files)}]
|
||||||
(st/emit! (dwm/upload-media-workspace params)))
|
(st/emit! (dwm/upload-media-workspace params)))
|
||||||
|
|
||||||
;; Will trigger when the user drags an image from a browser to the viewport (firefox and chrome do it a bit different depending on the origin)
|
;; Will trigger when the user drags an image (usually rendered as datauri) from a
|
||||||
|
;; browser to the viewport (mainly on firefox, all depending on the origin of the
|
||||||
|
;; drag event).
|
||||||
(dnd/has-type? event "text/uri-list")
|
(dnd/has-type? event "text/uri-list")
|
||||||
(let [data (dnd/get-data event "text/uri-list")
|
(let [data (dnd/get-data event "text/uri-list")
|
||||||
lines (str/lines data)
|
lines (str/lines data)
|
||||||
uris (filter #(and (not (str/blank? %))
|
uris (->> lines (filter #(str/starts-with? % "http")))
|
||||||
(not (str/starts-with? % "#")))
|
data (->> lines (filter #(str/starts-with? % "data:image/")))
|
||||||
lines)
|
|
||||||
params {:file-id (:id file)
|
params {:file-id (:id file)
|
||||||
:position viewport-coord
|
:position viewport-coord}
|
||||||
:uris uris}]
|
params (if (seq uris)
|
||||||
|
(assoc params :uris uris)
|
||||||
|
(assoc params :blobs (map wapi/data-uri->blob data)))]
|
||||||
(st/emit! (dwm/upload-media-workspace params)))
|
(st/emit! (dwm/upload-media-workspace params)))
|
||||||
|
|
||||||
;; Will trigger when the user drags an SVG asset from the assets panel
|
;; Will trigger when the user drags an SVG asset from the assets panel
|
||||||
|
|
|
@ -60,6 +60,23 @@
|
||||||
(assert (blob? b) "invalid arguments")
|
(assert (blob? b) "invalid arguments")
|
||||||
(js/URL.createObjectURL b))
|
(js/URL.createObjectURL b))
|
||||||
|
|
||||||
|
(defn data-uri?
|
||||||
|
[s]
|
||||||
|
(str/starts-with? s "data:"))
|
||||||
|
|
||||||
|
(defn data-uri->blob
|
||||||
|
[data-uri]
|
||||||
|
(let [[mtype b64-data] (str/split data-uri ";base64,")
|
||||||
|
mtype (subs mtype (inc (str/index-of mtype ":")))
|
||||||
|
decoded (.atob js/window b64-data)
|
||||||
|
size (.-length ^js decoded)
|
||||||
|
content (js/Uint8Array. size)]
|
||||||
|
|
||||||
|
(doseq [i (range 0 size)]
|
||||||
|
(aset content i (.charCodeAt ^js decoded i)))
|
||||||
|
|
||||||
|
(create-blob content mtype)))
|
||||||
|
|
||||||
(defn write-to-clipboard
|
(defn write-to-clipboard
|
||||||
[data]
|
[data]
|
||||||
(assert (string? data) "`data` should be string")
|
(assert (string? data) "`data` should be string")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue