mirror of
https://github.com/teacat/chaturbate-dvr.git
synced 2025-10-29 16:59:59 +00:00
Fixed #44
This commit is contained in:
parent
4350359f90
commit
12a27d11d5
@ -1,7 +1,9 @@
|
||||
package chaturbate
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -161,3 +163,45 @@ func (m *Manager) StopListenUpdate(id string) error {
|
||||
close(v)
|
||||
return nil
|
||||
}
|
||||
|
||||
// SaveChannels
|
||||
func (m *Manager) SaveChannels() error {
|
||||
configs := make([]*Config, 0)
|
||||
for _, v := range m.Channels {
|
||||
configs = append(configs, &Config{
|
||||
Username: v.Username,
|
||||
Framerate: v.Framerate,
|
||||
Resolution: v.Resolution,
|
||||
ResolutionFallback: v.ResolutionFallback,
|
||||
FilenamePattern: v.filenamePattern,
|
||||
SplitDuration: v.SplitDuration,
|
||||
SplitFilesize: v.SplitFilesize,
|
||||
})
|
||||
}
|
||||
b, err := json.MarshalIndent(configs, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile("chaturbate_channels.json", b, 0777)
|
||||
}
|
||||
|
||||
// LoadChannels
|
||||
func (m *Manager) LoadChannels() error {
|
||||
b, err := os.ReadFile("chaturbate_channels.json")
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
var configs []*Config
|
||||
if err := json.Unmarshal(b, &configs); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range configs {
|
||||
if err := m.CreateChannel(v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -60,5 +60,9 @@ func (h *CreateChannelHandler) Handle(c *gin.Context) {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if err := h.chaturbate.SaveChannels(); err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, &CreateChannelResponse{})
|
||||
}
|
||||
|
||||
@ -46,5 +46,9 @@ func (h *DeleteChannelHandler) Handle(c *gin.Context) {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
if err := h.chaturbate.SaveChannels(); err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, &DeleteChannelResponse{})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user