From e99d452f8d43f3358cd273699b42011eee1e2394 Mon Sep 17 00:00:00 2001 From: Sergey Petrov Date: Thu, 10 Apr 2025 10:13:48 +0500 Subject: [PATCH] Add all handlers from first doc. --- reader/internal/handlers/handlers.go | 45 ++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/reader/internal/handlers/handlers.go b/reader/internal/handlers/handlers.go index f64b25e..df9fa25 100644 --- a/reader/internal/handlers/handlers.go +++ b/reader/internal/handlers/handlers.go @@ -58,6 +58,22 @@ type ConfigVodsResponse struct { Provider string `json:"provider"` // Human-readable name of the content provider. Applicable to MPEG-TS. } +type SingleVodsResponse struct { + Name string `json:"name"` + Prefix string `json:"prefix"` + Url string `json:"url"` + Folder string `json:"folder"` + Bytes int64 `json:"bytes"` + MediaInfo MediaSingleVodsResponse `json:"media_info"` +} + +type MediaSingleVodsResponse struct { + Tracks map[string]string `json:"tracks"` + Duration int `json:"duration"` + Provider string `json:"provider"` + Title string `json:"title"` +} + // Inactive5Minutes checks if a folder has files that was not created or modified for last 5 minutes. func Inactive5Minutes(entries []os.DirEntry) (bool, error) { threshold := time.Now().Add(-5 * time.Minute) @@ -364,18 +380,21 @@ func SingleVodsHandler(w http.ResponseWriter, r *http.Request) { } } -type SingleVodsResponse struct { - Name string `json:"name"` - Prefix string `json:"prefix"` - Url string `json:"url"` - Folder string `json:"folder"` - Bytes int64 `json:"bytes"` - MediaInfo MediaSingleVodsResponse `json:"media_info"` -} +// DelSingleVodsHandler deletes a VOD file by its name. +// +// This method deletes a VOD file by its name. +func DelSingleVodsHandler(w http.ResponseWriter, r *http.Request) { + // Read camera id, res, filename. + id := r.PathValue("id") + res := r.PathValue("res") + file := r.PathValue("file") -type MediaSingleVodsResponse struct { - Tracks map[string]string `json:"tracks"` - Duration int `json:"duration"` - Provider string `json:"provider"` - Title string `json:"title"` + if err := os.Remove(fmt.Sprintf("%s/%s/%s/%s", config.DirData, id, res, file)); err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + logger.Log.Error("file does not exist", zap.Error(err)) + return + } + + w.WriteHeader(http.StatusNoContent) + w.Write([]byte("Deleted")) }