mirror of
https://github.com/penpot/penpot.git
synced 2025-07-14 16:37:18 +02:00
✨ Add the notion of temporal files on the storage.
This commit is contained in:
parent
5d0ad1ada2
commit
d68286821b
8 changed files with 176 additions and 95 deletions
|
@ -34,7 +34,7 @@
|
|||
[_ cfg]
|
||||
(assoc cfg :type :db))
|
||||
|
||||
(s/def ::type #{:db})
|
||||
(s/def ::type ::us/keyword)
|
||||
(s/def ::backend
|
||||
(s/keys :req-un [::type ::db/pool]))
|
||||
|
||||
|
|
|
@ -29,22 +29,25 @@
|
|||
;; --- BACKEND INIT
|
||||
|
||||
(s/def ::directory ::us/string)
|
||||
(s/def ::uri ::us/string)
|
||||
|
||||
(defmethod ig/pre-init-spec ::backend [_]
|
||||
(s/keys :opt-un [::directory ::uri]))
|
||||
(s/keys :opt-un [::directory]))
|
||||
|
||||
(defmethod ig/init-key ::backend
|
||||
[_ cfg]
|
||||
[key cfg]
|
||||
;; Return a valid backend data structure only if all optional
|
||||
;; parameters are provided.
|
||||
(when (and (string? (:directory cfg))
|
||||
(string? (:uri cfg)))
|
||||
(assoc cfg :type :fs)))
|
||||
(when (string? (:directory cfg))
|
||||
(let [dir (fs/normalize (:directory cfg))]
|
||||
(assoc cfg
|
||||
:type :fs
|
||||
:directory (str dir)
|
||||
:uri (u/uri (str "file://" dir))))))
|
||||
|
||||
(s/def ::type #{:fs})
|
||||
(s/def ::type ::us/keyword)
|
||||
(s/def ::uri #(instance? lambdaisland.uri.URI %))
|
||||
(s/def ::backend
|
||||
(s/keys :req-un [::directory ::uri ::type]))
|
||||
(s/keys :req-un [::type ::directory ::uri]))
|
||||
|
||||
;; --- API IMPL
|
||||
|
||||
|
@ -82,13 +85,12 @@
|
|||
(io/input-stream full)))
|
||||
|
||||
(defmethod impl/get-object-url :fs
|
||||
[backend {:keys [id] :as object} _]
|
||||
(let [uri (u/uri (:uri backend))]
|
||||
(update uri :path
|
||||
(fn [existing]
|
||||
(if (str/ends-with? existing "/")
|
||||
(str existing (impl/id->path id))
|
||||
(str existing "/" (impl/id->path id)))))))
|
||||
[{:keys [uri] :as backend} {:keys [id] :as object} _]
|
||||
(update uri :path
|
||||
(fn [existing]
|
||||
(if (str/ends-with? existing "/")
|
||||
(str existing (impl/id->path id))
|
||||
(str existing "/" (impl/id->path id))))))
|
||||
|
||||
(defmethod impl/del-objects-in-bulk :fs
|
||||
[backend ids]
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
:presigner presigner
|
||||
:type :s3))))
|
||||
|
||||
(s/def ::type #{:s3})
|
||||
(s/def ::type ::us/keyword)
|
||||
(s/def ::client #(instance? S3Client %))
|
||||
(s/def ::presigner #(instance? S3Presigner %))
|
||||
(s/def ::backend
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue