auto-file-store constructor for auto-detecting store type based on config keys

clj-a2png
Marcin Kulik 7 years ago
parent a3feeb6454
commit 155bd3d36a

@ -1,12 +1,9 @@
{:components
{:file-store #var asciinema.component.local-file-store/local-file-store
:exp-set #var asciinema.component.mem-expiring-set/mem-expiring-set}
{:exp-set #var asciinema.component.mem-expiring-set/mem-expiring-set}
:config
{:http
{:port 4000}
:db
{:uri "jdbc:postgresql://localhost:15432/asciinema_development?user=vagrant"}
:file-store
{:path "uploads/"}
:png-gen
{:bin-path "a2png/a2png.sh"}}}

@ -2,7 +2,7 @@
{:http #var asciinema.component.yada-listener/yada-listener
:db #var asciinema.component.db/hikaricp
:ragtime #var duct.component.ragtime/ragtime
:file-store #var asciinema.component.s3-file-store/s3-file-store
:file-store #var asciinema.component.auto-file-store/auto-file-store
:exp-set #var asciinema.component.redis-client/redis-client
:png-gen #var asciinema.component.a2png/a2png
:executor #var asciinema.component.fixed-thread-executor/fixed-thread-executor}
@ -20,10 +20,10 @@
:ragtime
{:resource-path "asciinema/migrations"}
:file-store
{:cred {:access-key s3-access-key
:secret-key s3-secret-key}
:bucket s3-bucket
:path-prefix "uploads/"}
{:path "uploads/"
:s3-bucket s3-bucket
:s3-cred {:access-key s3-access-key
:secret-key s3-secret-key}}
:exp-set
{:uri redis-url}
:png-gen

@ -0,0 +1,8 @@
(ns asciinema.component.auto-file-store
(:require [asciinema.component.local-file-store :refer [local-file-store]]
[asciinema.component.s3-file-store :refer [s3-file-store]]))
(defn auto-file-store [config]
(if (:s3-bucket config)
(s3-file-store config)
(local-file-store config)))

@ -60,5 +60,5 @@
(assoc :status 302)
(update :headers assoc "location" url)))))
(defn s3-file-store [{:keys [cred bucket path-prefix]}]
(->S3FileStore cred bucket path-prefix))
(defn s3-file-store [{:keys [s3-cred s3-bucket path]}]
(->S3FileStore s3-cred s3-bucket path))

Loading…
Cancel
Save