fixed livestreams monitor peristence
This commit is contained in:
@@ -3,6 +3,7 @@ package livestream
|
|||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@@ -84,7 +85,12 @@ func (m *Monitor) Persist() error {
|
|||||||
|
|
||||||
slog.Debug("persisting livestream monitor state")
|
slog.Debug("persisting livestream monitor state")
|
||||||
|
|
||||||
return gob.NewEncoder(fd).Encode(m.streams)
|
var toPersist []string
|
||||||
|
for url := range maps.Keys(m.streams) {
|
||||||
|
toPersist = append(toPersist, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
return gob.NewEncoder(fd).Encode(toPersist)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore a saved state and resume the monitored livestreams
|
// Restore a saved state and resume the monitored livestreams
|
||||||
@@ -96,14 +102,14 @@ func (m *Monitor) Restore() error {
|
|||||||
|
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
||||||
restored := make(map[string]*LiveStream)
|
var toRestore []string
|
||||||
|
|
||||||
if err := gob.NewDecoder(fd).Decode(&restored); err != nil {
|
if err := gob.NewDecoder(fd).Decode(&toRestore); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for k := range restored {
|
for _, url := range toRestore {
|
||||||
m.Add(k)
|
m.Add(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Debug("restored livestream monitor state")
|
slog.Debug("restored livestream monitor state")
|
||||||
|
|||||||
Reference in New Issue
Block a user