0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-03 11:25:27 -05:00
penpot/backend/src/uxbox/media.clj

37 lines
1.1 KiB
Clojure
Raw Normal View History

;; 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/.
;;
2020-02-03 22:29:59 +01:00
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2017-2020 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.media
"A media storage impl for uxbox."
2020-02-03 22:29:59 +01:00
(:require
[mount.core :refer [defstate]]
[clojure.java.io :as io]
[cuerdas.core :as str]
[datoteka.core :as fs]
[uxbox.util.storage :as ust]
[uxbox.config :refer [config]]))
;; --- State
2017-01-22 15:50:00 +01:00
(defstate assets-storage
2020-02-03 22:29:59 +01:00
:start (ust/create {:base-path (:assets-directory config)
:base-uri (:assets-uri config)}))
(defstate media-storage
2020-02-03 22:29:59 +01:00
:start (ust/create {:base-path (:media-directory config)
:base-uri (:media-uri config)
:xf (comp ust/random-path
ust/slugify-filename)}))
;; --- Public Api
(defn resolve-asset
[path]
2020-02-03 22:29:59 +01:00
(str (ust/public-uri assets-storage path)))