fix(liquidsoap): switch append_history to let json.parse with typed record

old json.parse(default=...) silently failed on every track change so
recent-played always showed only one entry. modern let-form parses
the existing history file correctly.
This commit is contained in:
devilreef 2026-04-30 11:22:50 +06:00
parent abca97b4ac
commit 52c6750a51
Signed by: devilreef
SSH key fingerprint: SHA256:UZisRr4iuXx+IhkbZnR655L2RWAT6o2rgbGv5F/6m3Y

View file

@ -36,25 +36,32 @@ def append_history(station, m) =
filename = m["filename"] filename = m["filename"]
if filename != "" then if filename != "" then
history_path = "/now-playing/#{station}.history.json" history_path = "/now-playing/#{station}.history.json"
existing = entry = {
if file.exists(history_path) then title = m["title"],
file.contents(history_path) artist = m["artist"],
else album = m["album"],
"[]" filename = filename,
end started_at = string(int_of_float(time()))
}
arr = arr =
try if file.exists(history_path) then
json.parse(default=([] : [json]), existing) existing = file.contents(history_path)
catch _ do try
([] : [json]) let json.parse (parsed : [{
title: string,
artist: string,
album: string,
filename: string,
started_at: string
}]) = existing
parsed
catch _ do
[]
end
else
[]
end end
entry = json() new_arr = list.add(entry, list.prefix(49, arr))
entry.add("title", m["title"])
entry.add("artist", m["artist"])
entry.add("album", m["album"])
entry.add("filename", filename)
entry.add("started_at", string(int_of_float(time())))
new_arr = list.add(entry, list.prefix(50, arr))
out_str = json.stringify(new_arr) out_str = json.stringify(new_arr)
file.write(data=out_str, atomic=true, temp_dir="/now-playing", history_path) file.write(data=out_str, atomic=true, temp_dir="/now-playing", history_path)
end end