diff --git a/Readme.md b/Readme.md index ae449fc..1ec086e 100644 --- a/Readme.md +++ b/Readme.md @@ -14,7 +14,7 @@ -->

Podgrab

-

Current Version - 2021.07.28

+

Current Version - 2021.07.30

A self-hosted podcast manager to download episodes as soon as they become live diff --git a/client/index.html b/client/index.html index b6e63c1..bede206 100644 --- a/client/index.html +++ b/client/index.html @@ -115,6 +115,10 @@ .list .u-full-width{ width: 80%; } + + .paused{ + opacity: 50%; + } @@ -172,11 +176,12 @@ /> -

+
@@ -250,6 +255,22 @@ > + +
@@ -469,6 +490,27 @@ } this.socket.send(getWebsocketMessage("Enqueue",`{"podcastId":"${id}"}`)) }, + togglePause(item,isPaused){ + var self=this; + var url= isPaused?`/podcasts/${item.ID}/pause`:`/podcasts/${item.ID}/unpause`; + axios + .get(url) + .then(function (response) { + item.IsPaused=isPaused; + + }) + .catch(function (error) { + if (error.response && error.response.data && error.response.data.message) { + Vue.toasted.show(error.response.data.message, { + theme: "bubble", + type: "error", + position: "top-right", + duration: 5000, + }); + } + }) + + }, filterPodcasts(){ if(this.filterTag===""){ this.podcasts=this.allPodcasts; diff --git a/client/settings.html b/client/settings.html index 03b384e..37ff746 100644 --- a/client/settings.html +++ b/client/settings.html @@ -128,7 +128,7 @@ - + diff --git a/controllers/podcast.go b/controllers/podcast.go index 471a15d..5fe36d1 100644 --- a/controllers/podcast.go +++ b/controllers/podcast.go @@ -95,6 +95,35 @@ func GetPodcastById(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) } } + +func PausePodcastById(c *gin.Context) { + var searchByIdQuery SearchByIdQuery + if c.ShouldBindUri(&searchByIdQuery) == nil { + + err := service.TogglePodcastPause(searchByIdQuery.Id, true) + if err != nil { + c.JSON(http.StatusBadRequest, err) + return + } + c.JSON(200, gin.H{}) + } else { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) + } +} +func UnpausePodcastById(c *gin.Context) { + var searchByIdQuery SearchByIdQuery + if c.ShouldBindUri(&searchByIdQuery) == nil { + err := service.TogglePodcastPause(searchByIdQuery.Id, false) + if err != nil { + c.JSON(http.StatusBadRequest, err) + return + } + c.JSON(200, gin.H{}) + } else { + c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) + } +} + func DeletePodcastById(c *gin.Context) { var searchByIdQuery SearchByIdQuery diff --git a/db/dbfunctions.go b/db/dbfunctions.go index 82b44e2..7d001ea 100644 --- a/db/dbfunctions.go +++ b/db/dbfunctions.go @@ -272,6 +272,12 @@ func ForceSetLastEpisodeDate(podcastId string) { DB.Exec("update podcasts set last_episode = (select max(pi.pub_date) from podcast_items pi where pi.podcast_id = @id) where id = @id", sql.Named("id", podcastId)) } +func TogglePodcastPauseStatus(podcastId string, isPaused bool) error { + + tx := DB.Debug().Exec("update podcasts set is_paused = @isPaused where id = @id", sql.Named("id", podcastId), sql.Named("isPaused", isPaused)) + return tx.Error +} + func GetPodcastItemsByPodcastIdAndGUIDs(podcastId string, guids []string) (*[]PodcastItem, error) { var podcastItems []PodcastItem result := DB.Preload(clause.Associations).Where(&PodcastItem{PodcastID: podcastId}).Where("guid IN ?", guids).Find(&podcastItems) @@ -297,6 +303,11 @@ func CreatePodcastItem(podcastItem *PodcastItem) error { tx := DB.Omit("Podcast").Create(&podcastItem) return tx.Error } + +func UpdatePodcast(podcast *Podcast) error { + tx := DB.Save(&podcast) + return tx.Error +} func UpdatePodcastItem(podcastItem *PodcastItem) error { tx := DB.Omit("Podcast").Save(&podcastItem) return tx.Error diff --git a/db/podcast.go b/db/podcast.go index fa9abdb..aae79a5 100644 --- a/db/podcast.go +++ b/db/podcast.go @@ -30,6 +30,8 @@ type Podcast struct { DownloadedEpisodesSize int64 `gorm:"-"` DownloadingEpisodesSize int64 `gorm:"-"` AllEpisodesSize int64 `gorm:"-"` + + IsPaused bool `gorm:"default:false"` } //PodcastItem is diff --git a/main.go b/main.go index e107104..0fcdbe0 100644 --- a/main.go +++ b/main.go @@ -157,6 +157,8 @@ func main() { router.GET("/podcasts/:id/download", controllers.DownloadAllEpisodesByPodcastId) router.DELETE("/podcasts/:id/items", controllers.DeletePodcastEpisodesById) router.DELETE("/podcasts/:id/podcast", controllers.DeleteOnlyPodcastById) + router.GET("/podcasts/:id/pause", controllers.PausePodcastById) + router.GET("/podcasts/:id/unpause", controllers.UnpausePodcastById) router.GET("/podcastitems", controllers.GetAllPodcastItems) router.GET("/podcastitems/:id", controllers.GetPodcastItemById) diff --git a/service/podcastService.go b/service/podcastService.go index 0ff9ce2..9259499 100644 --- a/service/podcastService.go +++ b/service/podcastService.go @@ -312,6 +312,10 @@ func AddPodcastItems(podcast *db.Podcast, newPodcast bool) error { downloadStatus = db.Deleted } + if podcast.IsPaused { + downloadStatus = db.Deleted + } + summary := strip.StripTags(obj.Summary) if summary == "" { summary = strip.StripTags(obj.Description) @@ -779,3 +783,13 @@ func AddTag(label, description string) (db.Tag, error) { return *tag, &model.TagAlreadyExistsError{Label: label} } + +func TogglePodcastPause(id string, isPaused bool) error { + var podcast db.Podcast + err := db.GetPodcastById(id, &podcast) + if err != nil { + return err + } + + return db.TogglePodcastPauseStatus(id, isPaused) +}
Current Version 2021.07.28 2021.07.30
Website