🐛 Add method to retrieve image data in plugins

This commit is contained in:
alonso.torres 2025-11-12 12:01:57 +01:00
parent 4a887840c6
commit 4cdf1eed0c
2 changed files with 40 additions and 8 deletions

View File

@ -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;

View 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))))))))