Skip to content

Commit

Permalink
Add file domain utility function to decode obj with schema
Browse files Browse the repository at this point in the history
[Re #1543]

* Useful if we want to convert a file to a domain when pulled from the DB using join
and JSON aggregations.
  • Loading branch information
lucassousaf committed Aug 9, 2023
1 parent ff54fe5 commit ad27ae4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backend/src/gpml/domain/file.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[gpml.domain.miscellaneous :as dom.misc]
[gpml.domain.types :as dom.types]
[gpml.util :as util]
[malli.core :as m])
[malli.core :as m]
[malli.transform :as mt])
(:import [java.io File]))

(def ^:const object-key-pattern
Expand Down Expand Up @@ -55,6 +56,10 @@
(str/replace #"FILE-KEY" (name file-key))
(str/replace #"FILE-ID" (str file-id))))

(defn decode-file
[file]
(m/decode file-schema file mt/string-transformer))

(defn base64->file
[payload entity-key file-key visibility]
(let [[_ ^String content-type ^String content] (re-find #"^data:(\S+);base64,(.*)$" payload)
Expand Down

0 comments on commit ad27ae4

Please sign in to comment.