parent
2c33c6cdcc
commit
5f3ed0e363
@ -0,0 +1,50 @@
|
||||
(ns wanijo.instance.files
|
||||
(:require [clojure.java.io :as io]
|
||||
[wanijo.infra.sysconfig :refer [env]]
|
||||
[wanijo.infra.neo4j :refer [uuid]])
|
||||
(:import [java.io File]))
|
||||
|
||||
(def files-home (str (env "WANIJO_HOME") "/files"))
|
||||
|
||||
(comment
|
||||
(def files-home "/tmp/wanijo"))
|
||||
|
||||
(defn persist-files! [instance]
|
||||
(doall
|
||||
(for [file (->> (:properties instance)
|
||||
(filter #(= "file" (-> % :attribute :type)))
|
||||
(map (fn [prop] {:file (:value prop)
|
||||
:uuid (:uuid prop)})))
|
||||
:let [uploaded-file (:file file)
|
||||
size (:size uploaded-file)
|
||||
uuid (if (empty? (:uuid file)) (uuid) (:uuid file))
|
||||
path (str files-home "/" uuid)]
|
||||
:when (> size 0)]
|
||||
(do
|
||||
(.mkdirs (io/file files-home))
|
||||
(io/copy (io/file (:tempfile uploaded-file)) (io/file path))
|
||||
{:path path
|
||||
:uuid uuid
|
||||
:filename (:filename uploaded-file)
|
||||
:content-type (:content-type uploaded-file)}))))
|
||||
|
||||
(comment
|
||||
(let [instance {:name "Frank",
|
||||
:properties
|
||||
'({:attribute
|
||||
{:name "Dateidings",
|
||||
:created_at "20210929T154103.152Z",
|
||||
:type "file",
|
||||
:uuid "00847b4c-9961-47cd-a64f-18eaea0e362f",
|
||||
:required 0},
|
||||
:value
|
||||
{:filename "2020.pdf",
|
||||
:content-type "application/pdf",
|
||||
:tempfile nil,
|
||||
:size 127785},
|
||||
:uuid "f7d56f9c-e74a-4b12-95c1-f33961672072"}),
|
||||
:uuid "def4dacb-979f-4a0d-b1d6-535ac2a3f94b"}]
|
||||
(->> (:properties instance)
|
||||
(filter #(= "file" 1 #_(-> % :attribute :type))) #_(map (fn [prop] {:file (:value prop)
|
||||
:uuid (:uuid prop)}))))
|
||||
)
|
Loading…
Reference in new issue