diff --git a/frontend/src/app/plugins/format.cljs b/frontend/src/app/plugins/format.cljs index 0ea3832406..2b892a65e1 100644 --- a/frontend/src/app/plugins/format.cljs +++ b/frontend/src/app/plugins/format.cljs @@ -8,6 +8,7 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] + [app.plugins.image-data :refer [create-image-data]] [app.util.object :as obj])) (def shape-proxy nil) @@ -106,15 +107,9 @@ ;; keepAspectRatio?: boolean; ;; }; (defn format-image - [{:keys [name width height mtype id keep-aspect-ratio] :as image}] + [image] (when (some? image) - (obj/without-empty - #js {:name name - :width width - :height height - :mtype mtype - :id (format-id id) - :keepAspectRatio keep-aspect-ratio}))) + (create-image-data image))) ;; export interface Color { ;; id?: string; diff --git a/frontend/src/app/plugins/image_data.cljs b/frontend/src/app/plugins/image_data.cljs new file mode 100644 index 0000000000..f3bfb84080 --- /dev/null +++ b/frontend/src/app/plugins/image_data.cljs @@ -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))))))))