Skip to content

Commit

Permalink
Update object path to include date, start time, end time
Browse files Browse the repository at this point in the history
  • Loading branch information
skanderm committed Sep 10, 2024
1 parent f01aba6 commit d7836be
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion server/lib/orcasite/radio/audio_image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,27 @@ defmodule Orcasite.Radio.AudioImage do
fn _change, record, _context ->
feed = record |> Ash.load!(:feed) |> Map.get(:feed)

date_string = record.start_time |> DateTime.to_date() |> to_string()

# Convert to string like: ""2024-09-10_17-41-53Z"
start_time_string =
record.start_time
|> DateTime.truncate(:second)
|> to_string()
|> String.replace(":", "-")
|> String.replace(" ", "_")

end_time_string =
record.end_time
|> DateTime.truncate(:second)
|> to_string()
|> String.replace(":", "-")
|> String.replace(" ", "_")

record
|> Ash.Changeset.for_update(:update, %{
object_path: "/#{feed.node_name}/spectrograms/#{record.id}.png"
object_path:
"/#{feed.node_name}/spectrograms/#{date_string}/#{start_time_string}__#{end_time_string}__#{record.id}.png"
})
|> Ash.update(authorize?: false)
end,
Expand Down

0 comments on commit d7836be

Please sign in to comment.