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
|
package chaturbate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -161,3 +163,45 @@ func (m *Manager) StopListenUpdate(id string) error {
|
|||||||
close(v)
|
close(v)
|
||||||
return nil
|
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)
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err := h.chaturbate.SaveChannels(); err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
c.JSON(http.StatusOK, &CreateChannelResponse{})
|
c.JSON(http.StatusOK, &CreateChannelResponse{})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -46,5 +46,9 @@ func (h *DeleteChannelHandler) Handle(c *gin.Context) {
|
|||||||
c.AbortWithError(http.StatusInternalServerError, err)
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if err := h.chaturbate.SaveChannels(); err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
c.JSON(http.StatusOK, &DeleteChannelResponse{})
|
c.JSON(http.StatusOK, &DeleteChannelResponse{})
|
||||||
}
|
}
|
||||||
|
|||||||
3
main.go
3
main.go
@ -132,6 +132,9 @@ func startWeb(c *cli.Context) error {
|
|||||||
|
|
||||||
//r.Use(cors.Default())
|
//r.Use(cors.Default())
|
||||||
m := chaturbate.NewManager(c)
|
m := chaturbate.NewManager(c)
|
||||||
|
if err := m.LoadChannels(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
fe, err := fs.Sub(FS, "handler/view")
|
fe, err := fs.Sub(FS, "handler/view")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user