Skip to content

Commit

Permalink
fix(signage): errors when no playlists scheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Aug 19, 2024
1 parent 5be711d commit 1657a1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ shards:

placeos-models:
git: https://github.com/placeos/models.git
version: 9.57.2
version: 9.57.4

placeos-resource:
git: https://github.com/place-labs/resource.git
Expand Down
16 changes: 13 additions & 3 deletions src/placeos-rest-api/controllers/signage.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ module PlaceOS::Api
system.playlist_mappings = playlist_map

# get the playlist configuration (default timeouts etc) and media lists (latest revisions)
playlist_details = ::PlaceOS::Model::Playlist.where(id: playlist_ids).to_a
playlist_items = ::PlaceOS::Model::Playlist::Revision.revisions(playlist_ids)
if playlist_ids.empty?
playlist_details = [] of ::PlaceOS::Model::Playlist
playlist_items = [] of ::PlaceOS::Model::Playlist::Revision
else
playlist_details = ::PlaceOS::Model::Playlist.where(id: playlist_ids).to_a
playlist_items = ::PlaceOS::Model::Playlist::Revision.revisions(playlist_ids)
end

playlist_config = Hash(String, Tuple(::PlaceOS::Model::Playlist, Array(String))).new(playlist_details.size) { raise "no default" }
playlist_details.each do |playlist|
Expand All @@ -44,7 +49,12 @@ module PlaceOS::Api

# grab all the media details that should be cached / used in the media lists
media_ids = playlist_config.values.flat_map(&.[](1)).uniq!
system.playlist_media = ::PlaceOS::Model::Playlist::Item.where(id: media_ids).to_a

if media_ids.empty?
system.playlist_media = [] of ::PlaceOS::Model::Playlist::Item
else
system.playlist_media = ::PlaceOS::Model::Playlist::Item.where(id: media_ids).to_a
end

# ensure response caching is configured correctly
response.headers["Cache-Control"] = "no-cache"
Expand Down

0 comments on commit 1657a1a

Please sign in to comment.