diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b85cbd93d7ae2f344bbbe946057df7a6245609b..4473662d2ff1495469a8a41021df1163e94c2319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] -*Nothing yet*. +### Added + +* Added support for a `forKinds: ["all"]` option on datastores. ## [1.0.1] - February 27, 2020 diff --git a/common/media_kinds.go b/common/media_kinds.go index 4ea68567cc3b44407bef1d0f16b80903418acb9c..5421b05193bcd67790879ddcc5891e387048b8de 100644 --- a/common/media_kinds.go +++ b/common/media_kinds.go @@ -4,5 +4,19 @@ const KindLocalMedia = "local_media" const KindRemoteMedia = "remote_media" const KindThumbnails = "thumbnails" const KindArchives = "archives" +const KindAll = "all" var AllKinds = []string{KindLocalMedia, KindRemoteMedia, KindThumbnails} + +func IsKind(have string, want string) bool { + return have == want || have == KindAll +} + +func HasKind(have []string, want string) bool { + for _, k := range have { + if IsKind(k, want) { + return true + } + } + return false +} diff --git a/storage/datastore/datastore.go b/storage/datastore/datastore.go index 76ebc304a71dc4fd3fda82020c7de49e7d21a1de..6274c3e79e0d92f7e2e2f1df974912c9dcb22b25 100644 --- a/storage/datastore/datastore.go +++ b/storage/datastore/datastore.go @@ -105,13 +105,7 @@ func PickDatastore(forKind string, ctx rcontext.RequestContext) (*DatastoreRef, dsConf.MediaKinds = common.AllKinds } - allowed := false - for _, k := range dsConf.MediaKinds { - if k == forKind { - allowed = true - break - } - } + allowed := common.HasKind(dsConf.MediaKinds, forKind) if !allowed { continue }