mirror of
https://github.com/penpot/penpot.git
synced 2026-08-28 23:59:00 +00:00
🐛 Add method to retrieve image data in plugins
This commit is contained in:
parent
4a887840c6
commit
4cdf1eed0c
@ -8,6 +8,7 @@
|
|||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
|
[app.plugins.image-data :refer [create-image-data]]
|
||||||
[app.util.object :as obj]))
|
[app.util.object :as obj]))
|
||||||
|
|
||||||
(def shape-proxy nil)
|
(def shape-proxy nil)
|
||||||
@ -106,15 +107,9 @@
|
|||||||
;; keepAspectRatio?: boolean;
|
;; keepAspectRatio?: boolean;
|
||||||
;; };
|
;; };
|
||||||
(defn format-image
|
(defn format-image
|
||||||
[{:keys [name width height mtype id keep-aspect-ratio] :as image}]
|
[image]
|
||||||
(when (some? image)
|
(when (some? image)
|
||||||
(obj/without-empty
|
(create-image-data image)))
|
||||||
#js {:name name
|
|
||||||
:width width
|
|
||||||
:height height
|
|
||||||
:mtype mtype
|
|
||||||
:id (format-id id)
|
|
||||||
:keepAspectRatio keep-aspect-ratio})))
|
|
||||||
|
|
||||||
;; export interface Color {
|
;; export interface Color {
|
||||||
;; id?: string;
|
;; id?: string;
|
||||||
|
|||||||
37
frontend/src/app/plugins/image_data.cljs
Normal file
37
frontend/src/app/plugins/image_data.cljs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.plugins.image-data
|
||||||
|
(:require
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
|
[app.config :as cf]
|
||||||
|
[app.util.http :as http]
|
||||||
|
[app.util.object :as obj]
|
||||||
|
[beicon.v2.core :as rx]))
|
||||||
|
|
||||||
|
(defn create-image-data
|
||||||
|
[{:keys [name width height mtype id keep-aspect-ratio] :as entry}]
|
||||||
|
(obj/reify {:name "ImageData"}
|
||||||
|
:name {:get (constantly name)}
|
||||||
|
:width {:get (constantly width)}
|
||||||
|
:height {:get (constantly height)}
|
||||||
|
:mtype {:get (constantly mtype)}
|
||||||
|
:id {:get #(when id (dm/str id))}
|
||||||
|
:keepAspectRatio {:get (constantly keep-aspect-ratio)}
|
||||||
|
|
||||||
|
:data
|
||||||
|
(fn []
|
||||||
|
(let [url (cf/resolve-file-media entry)]
|
||||||
|
(js/Promise.
|
||||||
|
(fn [resolve reject]
|
||||||
|
(->> (http/send!
|
||||||
|
{:method :get
|
||||||
|
:uri url
|
||||||
|
:response-type :blob})
|
||||||
|
(rx/map :body)
|
||||||
|
(rx/mapcat #(.arrayBuffer %))
|
||||||
|
(rx/map #(js/Uint8Array. %))
|
||||||
|
(rx/subs! resolve reject))))))))
|
||||||
Loading…
x
Reference in New Issue
Block a user