From 3ffdf5a3ec79db607e041a53733e1a3f26a9bdb5 Mon Sep 17 00:00:00 2001 From: Akhil Gupta Date: Fri, 13 Aug 2021 16:58:31 +0530 Subject: [PATCH] add base url to setting --- Readme.md | 2 +- client/settings.html | 10 ++++++++-- controllers/pages.go | 19 ++++++++++--------- controllers/podcast.go | 23 ++++++++++++++++------- db/podcast.go | 1 + service/podcastService.go | 5 ++++- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Readme.md b/Readme.md index 84661ca..f579087 100644 --- a/Readme.md +++ b/Readme.md @@ -14,7 +14,7 @@ -->

Podgrab

-

Current Version -2021.08.02

+

Current Version -2021.08.13

A self-hosted podcast manager to download episodes as soon as they become live diff --git a/client/settings.html b/client/settings.html index 1cc86a2..b4fc3ec 100644 --- a/client/settings.html +++ b/client/settings.html @@ -97,6 +97,10 @@ Don't re-download files deleted from disk. + @@ -128,7 +132,7 @@ - + @@ -173,7 +177,8 @@ var app = new Vue({ darkMode:self.darkMode, downloadEpisodeImages:self.downloadEpisodeImages, generateNFOFile:self.generateNFOFile, - dontDownloadDeletedFromDisk:self.dontDownloadDeletedFromDisk + dontDownloadDeletedFromDisk:self.dontDownloadDeletedFromDisk, + baseUrl:self.baseUrl, }) .then(function(response){ Vue.toasted.show('Settings saved successfully.' ,{ @@ -217,6 +222,7 @@ var app = new Vue({ downloadEpisodeImages:{{.setting.DownloadEpisodeImages }}, generateNFOFile:{{ .setting.GenerateNFOFile }}, dontDownloadDeletedFromDisk:{{ .setting.DontDownloadDeletedFromDisk }}, + baseUrl: {{ .setting.BaseUrl }}, }, }) diff --git a/controllers/pages.go b/controllers/pages.go index 4bffa41..7f2660d 100644 --- a/controllers/pages.go +++ b/controllers/pages.go @@ -21,15 +21,16 @@ type SearchGPodderData struct { SearchSource string `binding:"required" form:"searchSource" json:"searchSource" query:"searchSource"` } type SettingModel struct { - DownloadOnAdd bool `form:"downloadOnAdd" json:"downloadOnAdd" query:"downloadOnAdd"` - InitialDownloadCount int `form:"initialDownloadCount" json:"initialDownloadCount" query:"initialDownloadCount"` - AutoDownload bool `form:"autoDownload" json:"autoDownload" query:"autoDownload"` - AppendDateToFileName bool `form:"appendDateToFileName" json:"appendDateToFileName" query:"appendDateToFileName"` - AppendEpisodeNumberToFileName bool `form:"appendEpisodeNumberToFileName" json:"appendEpisodeNumberToFileName" query:"appendEpisodeNumberToFileName"` - DarkMode bool `form:"darkMode" json:"darkMode" query:"darkMode"` - DownloadEpisodeImages bool `form:"downloadEpisodeImages" json:"downloadEpisodeImages" query:"downloadEpisodeImages"` - GenerateNFOFile bool `form:"generateNFOFile" json:"generateNFOFile" query:"generateNFOFile"` - DontDownloadDeletedFromDisk bool `form:"dontDownloadDeletedFromDisk" json:"dontDownloadDeletedFromDisk" query:"dontDownloadDeletedFromDisk"` + DownloadOnAdd bool `form:"downloadOnAdd" json:"downloadOnAdd" query:"downloadOnAdd"` + InitialDownloadCount int `form:"initialDownloadCount" json:"initialDownloadCount" query:"initialDownloadCount"` + AutoDownload bool `form:"autoDownload" json:"autoDownload" query:"autoDownload"` + AppendDateToFileName bool `form:"appendDateToFileName" json:"appendDateToFileName" query:"appendDateToFileName"` + AppendEpisodeNumberToFileName bool `form:"appendEpisodeNumberToFileName" json:"appendEpisodeNumberToFileName" query:"appendEpisodeNumberToFileName"` + DarkMode bool `form:"darkMode" json:"darkMode" query:"darkMode"` + DownloadEpisodeImages bool `form:"downloadEpisodeImages" json:"downloadEpisodeImages" query:"downloadEpisodeImages"` + GenerateNFOFile bool `form:"generateNFOFile" json:"generateNFOFile" query:"generateNFOFile"` + DontDownloadDeletedFromDisk bool `form:"dontDownloadDeletedFromDisk" json:"dontDownloadDeletedFromDisk" query:"dontDownloadDeletedFromDisk"` + BaseUrl string `form:"baseUrl" json:"baseUrl" query:"baseUrl"` } var searchOptions = map[string]string{ diff --git a/controllers/podcast.go b/controllers/podcast.go index 5fe36d1..5fb7282 100644 --- a/controllers/podcast.go +++ b/controllers/podcast.go @@ -430,9 +430,18 @@ func GetTagById(c *gin.Context) { } } +func getBaseUrl(c *gin.Context) string { + setting := c.MustGet("setting").(*db.Setting) + if setting.BaseUrl == "" { + url := location.Get(c) + return fmt.Sprintf("%s://%s", url.Scheme, url.Host) + } + return setting.BaseUrl +} + func createRss(items []db.PodcastItem, title, description string, c *gin.Context) model.RssPodcastData { var rssItems []model.RssItem - url := location.Get(c) + url := getBaseUrl(c) for _, item := range items { rssItem := model.RssItem{ Title: item.Title, @@ -440,11 +449,11 @@ func createRss(items []db.PodcastItem, title, description string, c *gin.Context Summary: item.Summary, Image: model.RssItemImage{ Text: item.Title, - Href: fmt.Sprintf("%s://%s/podcastitems/%s/image", url.Scheme, url.Host, item.ID), + Href: fmt.Sprintf("%s/podcastitems/%s/image", url, item.ID), }, EpisodeType: item.EpisodeType, Enclosure: model.RssItemEnclosure{ - URL: fmt.Sprintf("%s://%s/podcastitems/%s/file", url.Scheme, url.Host, item.ID), + URL: fmt.Sprintf("%s/podcastitems/%s/file", url, item.ID), Length: fmt.Sprint(item.FileSize), Type: "audio/mpeg", }, @@ -453,7 +462,7 @@ func createRss(items []db.PodcastItem, title, description string, c *gin.Context IsPermaLink: "false", Text: item.ID, }, - Link: fmt.Sprintf("%s://%s/allTags", url.Scheme, url.Host), + Link: fmt.Sprintf("%s/allTags", url), Text: item.Title, Duration: fmt.Sprint(item.Duration), } @@ -472,8 +481,8 @@ func createRss(items []db.PodcastItem, title, description string, c *gin.Context Description: description, Summary: description, Author: "Podgrab Aggregation", - Link: fmt.Sprintf("%s://%s/allTags", url.Scheme, url.Host), - Image: model.RssItemImage{Text: title, Href: fmt.Sprintf("%s://%s/webassets/blank.png", url.Scheme, url.Host)}, + Link: fmt.Sprintf("%s/allTags", url), + Image: model.RssItemImage{Text: title, Href: fmt.Sprintf("%s/webassets/blank.png", url)}, }, } } @@ -578,7 +587,7 @@ func UpdateSetting(c *gin.Context) { err = service.UpdateSettings(model.DownloadOnAdd, model.InitialDownloadCount, model.AutoDownload, model.AppendDateToFileName, model.AppendEpisodeNumberToFileName, - model.DarkMode, model.DownloadEpisodeImages, model.GenerateNFOFile, model.DontDownloadDeletedFromDisk) + model.DarkMode, model.DownloadEpisodeImages, model.GenerateNFOFile, model.DontDownloadDeletedFromDisk, model.BaseUrl) if err == nil { c.JSON(200, gin.H{"message": "Success"}) diff --git a/db/podcast.go b/db/podcast.go index aae79a5..0962dd1 100644 --- a/db/podcast.go +++ b/db/podcast.go @@ -86,6 +86,7 @@ type Setting struct { DownloadEpisodeImages bool `gorm:"default:false"` GenerateNFOFile bool `gorm:"default:false"` DontDownloadDeletedFromDisk bool `gorm:"default:false"` + BaseUrl string } type Migration struct { Base diff --git a/service/podcastService.go b/service/podcastService.go index 9259499..c14b099 100644 --- a/service/podcastService.go +++ b/service/podcastService.go @@ -745,7 +745,9 @@ func GetSearchFromPodcastIndex(pod *podcastindex.Podcast) *model.CommonSearchRes return p } -func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool, appendDateToFileName bool, appendEpisodeNumberToFileName bool, darkMode bool, downloadEpisodeImages bool, generateNFOFile bool, dontDownloadDeletedFromDisk bool) error { +func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload bool, + appendDateToFileName bool, appendEpisodeNumberToFileName bool, darkMode bool, downloadEpisodeImages bool, + generateNFOFile bool, dontDownloadDeletedFromDisk bool, baseUrl string) error { setting := db.GetOrCreateSetting() setting.AutoDownload = autoDownload @@ -757,6 +759,7 @@ func UpdateSettings(downloadOnAdd bool, initialDownloadCount int, autoDownload b setting.DownloadEpisodeImages = downloadEpisodeImages setting.GenerateNFOFile = generateNFOFile setting.DontDownloadDeletedFromDisk = dontDownloadDeletedFromDisk + setting.BaseUrl = baseUrl return db.UpdateSettings(setting) }
Current Version 2021.08.02 2021.08.13
Website