From 78e6806e2cde8d1317f84a7287a517fb1af4bacf Mon Sep 17 00:00:00 2001 From: Akhil Gupta Date: Fri, 30 Oct 2020 11:34:03 +0530 Subject: [PATCH] aility to delete podcast --- client/episodes.html | 29 +++++++++++++++++++++++++++++ client/settings.html | 15 ++++++++++++++- controllers/podcast.go | 11 +++++++++++ main.go | 1 + service/podcastService.go | 27 +++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) diff --git a/client/episodes.html b/client/episodes.html index 46a4349..45464a4 100644 --- a/client/episodes.html +++ b/client/episodes.html @@ -70,6 +70,8 @@ hr{

{{ .Summary }}

{{if .DownloadPath}} Download + Delete + {{else}} {{if not $setting.AutoDownload}} Download to Disk @@ -125,6 +127,33 @@ function downloadToDisk(id){ }) return false; } + function deleteFile(id){ + + axios.get("/podcastitems/"+id+"/delete") + .then(function(response){ + Vue.toasted.show('Podcast file deleted.' ,{ + theme: "bubble", + position: "top-right", + duration : 5000 + }); + var row = document.getElementById('podcast-'+id); + row.remove(); + }) + .catch(function(error){ + if(error.response){ + + Vue.toasted.show(error.response.data?.message, { + theme: "bubble", + position: "top-right", + duration : 5000 + }) + } + + }). + then(function(){ + }) + return false; + } \ No newline at end of file diff --git a/client/settings.html b/client/settings.html index e451184..ad1e6b6 100644 --- a/client/settings.html +++ b/client/settings.html @@ -14,11 +14,17 @@ img{ display: none; } + @media (max-width: 750px) { + .label-body{ + display: inline!important; + } + } /* Larger than tablet */ @media (min-width: 750px) { img{ display: block } + } @@ -30,12 +36,17 @@ {{template "navbar"}}
+
+
+
+
+
+
+
- +
{{template "scripts"}} diff --git a/controllers/podcast.go b/controllers/podcast.go index 7f9af5a..d066ec0 100644 --- a/controllers/podcast.go +++ b/controllers/podcast.go @@ -108,6 +108,17 @@ func DownloadPodcastItem(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) } } +func DeletePodcastItem(c *gin.Context) { + var searchByIdQuery SearchByIdQuery + + if c.ShouldBindUri(&searchByIdQuery) == nil { + + go service.DeleteEpisodeFile(searchByIdQuery.Id) + c.JSON(200, gin.H{}) + } else { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) + } +} func AddPodcast(c *gin.Context) { var addPodcastData AddPodcastData diff --git a/main.go b/main.go index 3048c10..c802c14 100644 --- a/main.go +++ b/main.go @@ -77,6 +77,7 @@ func main() { r.GET("/podcastitems", controllers.GetAllPodcastItems) r.GET("/podcastitems/:id", controllers.GetPodcastItemById) r.GET("/podcastitems/:id/download", controllers.DownloadPodcastItem) + r.GET("/podcastitems/:id/delete", controllers.DeletePodcastItem) r.GET("/add", controllers.AddPage) r.GET("/search", controllers.Search) diff --git a/service/podcastService.go b/service/podcastService.go index db1bb09..8cc3061 100644 --- a/service/podcastService.go +++ b/service/podcastService.go @@ -102,6 +102,17 @@ func SetPodcastItemAsDownloaded(id string, location string) error { return db.UpdatePodcastItem(&podcastItem) } +func SetPodcastItemAsNotDownloaded(id string) error { + var podcastItem db.PodcastItem + err := db.GetPodcastItemById(id, &podcastItem) + if err != nil { + return err + } + podcastItem.DownloadDate = time.Time{} + podcastItem.DownloadPath = "" + + return db.UpdatePodcastItem(&podcastItem) +} func DownloadMissingEpisodes() error { data, err := db.GetAllPodcastItemsToBeDownloaded() @@ -117,6 +128,22 @@ func DownloadMissingEpisodes() error { } return nil } + +func DeleteEpisodeFile(podcastItemId string) error { + var podcastItem db.PodcastItem + err := db.GetPodcastItemById(podcastItemId, &podcastItem) + + //fmt.Println("Processing episodes: ", strconv.Itoa(len(*data))) + if err != nil { + return err + } + + err = DeleteFile(podcastItem.DownloadPath) + if err != nil { + return err + } + return SetPodcastItemAsNotDownloaded(podcastItem.ID) +} func DownloadSingleEpisode(podcastItemId string) error { var podcastItem db.PodcastItem err := db.GetPodcastItemById(podcastItemId, &podcastItem)