2016-11-20 20:04:52 +01:00
|
|
|
;; 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>
|
2016-11-20 20:04:52 +01:00
|
|
|
|
|
|
|
(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]]))
|
2019-07-05 13:27:01 +02:00
|
|
|
|
2016-11-20 20:04:52 +01:00
|
|
|
;; --- 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)}))
|
2016-11-20 20:04:52 +01:00
|
|
|
|
|
|
|
(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)}))
|
2016-11-20 20:04:52 +01:00
|
|
|
|
|
|
|
;; --- Public Api
|
|
|
|
|
|
|
|
(defn resolve-asset
|
|
|
|
[path]
|
2020-02-03 22:29:59 +01:00
|
|
|
(str (ust/public-uri assets-storage path)))
|