0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 18:18:24 -05:00

Merge remote-tracking branch 'origin/staging' into develop

This commit is contained in:
Alejandro Alonso 2023-04-13 09:17:06 +02:00
commit ee1b9e861e
3 changed files with 42 additions and 11 deletions

View file

@ -14,6 +14,7 @@
[app.config :as cf]
[app.db :as db]
[app.http.client :as http]
[app.loggers.audit :as-alias audit]
[app.media :as media]
[app.rpc :as-alias rpc]
[app.rpc.climit :as climit]
@ -68,8 +69,15 @@
(files/check-edition-permissions! pool profile-id file-id)
(media/validate-media-type! 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?
"Checks if the provided image info is big enough for

View file

@ -26,6 +26,7 @@
[app.util.keyboard :as kbd]
[app.util.object :as obj]
[app.util.timers :as timers]
[app.util.webapi :as wapi]
[beicon.core :as rx]
[cuerdas.core :as str]
[rumext.v2 :as mf]))
@ -434,7 +435,9 @@
(:id component)
(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")
(let [files (dnd/get-files event)
params {:file-id (:id file)
@ -442,16 +445,19 @@
:blobs (seq files)}]
(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")
(let [data (dnd/get-data event "text/uri-list")
lines (str/lines data)
uris (filter #(and (not (str/blank? %))
(not (str/starts-with? % "#")))
lines)
(let [data (dnd/get-data event "text/uri-list")
lines (str/lines data)
uris (->> lines (filter #(str/starts-with? % "http")))
data (->> lines (filter #(str/starts-with? % "data:image/")))
params {:file-id (:id file)
:position viewport-coord
:uris uris}]
:position viewport-coord}
params (if (seq uris)
(assoc params :uris uris)
(assoc params :blobs (map wapi/data-uri->blob data)))]
(st/emit! (dwm/upload-media-workspace params)))
;; Will trigger when the user drags an SVG asset from the assets panel

View file

@ -60,6 +60,23 @@
(assert (blob? b) "invalid arguments")
(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
[data]
(assert (string? data) "`data` should be string")