add base url to setting

pull/142/head
Akhil Gupta 3 years ago
parent c9cfd46551
commit 3ffdf5a3ec

@ -14,7 +14,7 @@
</a> -->
<h1 align="center" style="margin-bottom:0px">Podgrab</h1>
<p align="center">Current Version -2021.08.02</p>
<p align="center">Current Version -2021.08.13</p>
<p align="center">
A self-hosted podcast manager to download episodes as soon as they become live

@ -97,6 +97,10 @@
<input type="checkbox" name="dontDownloadDeletedFromDisk" v-model="dontDownloadDeletedFromDisk">
<span class="label-body">Don't re-download files deleted from disk.</span>
</label>
<label for="baseUrl">
<span class="label-body">Base URL (if accessing Podgrab using a URL. Without trailing /. Leave empty if not using or unsure.)</span>
<input type="url" class="u-full-width" name="baseUrl" v-model="baseUrl">
</label>
<input type="submit" value="Save" class="button">
@ -128,7 +132,7 @@
<table>
<tr>
<td>Current Version</td>
<td> 2021.08.02</td>
<td> 2021.08.13</td>
</tr>
<tr>
<td>Website</td>
@ -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 }},
},
})

@ -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{

@ -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"})

@ -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

@ -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)
}

Loading…
Cancel
Save