Skip to content

Commit

Permalink
It would help if I could actually delete the stored stream...
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Feb 18, 2024
1 parent 8b6c7cc commit 3df9233
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions server/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,38 @@ func (store *Store) AddStored(stored *storage.Stored) (*storage.Stored, error) {
return stored, nil
}

func (store *Store) DeleteStored(unique string) error {
streamer, err := store.backend.Read()
if err != nil {
return err
}

s := streamer.Stored
found := false
var index int
var v *storage.Stored
for index, v = range s {
if v.Stream == unique {
found = true
break
}
}

if found {
copy(s[index:], s[index+1:]) // Shift a[i+1:] left one index
s[len(s)-1] = nil // Erase last element (write zero value)
streamer.Stored = s[:len(s)-1] // Truncate slice
} else {
return fmt.Errorf("stream not found for DeleteStored")
}

if err = store.backend.Write(streamer); err != nil {
return err
}

return nil
}

func (store *Store) Get() (*storage.Streamer, error) {
return store.backend.Read()
}
2 changes: 1 addition & 1 deletion server/views/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (v *Views) DeleteFunc(c echo.Context) error {
return c.JSON(http.StatusOK, response)
}

err = v.store.DeleteStream(unique)
err = v.store.DeleteStored(unique)
if err != nil {
log.Printf("failed to delete stored: %+v, unique: %s", err, unique)
response.Error = fmt.Sprintf("failed to delete stored: %+v, unique: %s", err, unique)
Expand Down

0 comments on commit 3df9233

Please sign in to comment.