Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh buttons #156

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ <h5 v-if="layout=='grid'">${podcast.Title} </h5>
>
<i style="color: red;" class="fas fa-dot-circle"></i>
</button>
<button
class="button"
title="Click to refresh this podcast."
@click="refreshPodcast(podcast)"
>
<i class="fas fa-sync"></i>
</button>
<button
class="button"
title="Click to see details."
Expand Down Expand Up @@ -667,6 +674,7 @@ <h5>Tags: ${podcast.Title}</h5>
return dt.toDateString()
},
downloadAllEpisodes(id) { downloadAllEpisodes(id);},
refreshPodcast(podcast) { refreshPodcast(podcast.ID, podcast.Title); },
deletePodcast(id){ deletePodcast(id,()=>{

const index= this.podcasts.findIndex(x=>x.ID===id);
Expand Down
9 changes: 8 additions & 1 deletion client/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,14 @@
</a>
<h1 id="pageTitle">{{ .title }}</h1>
{{if .podcastId }}
<button
<button
class="button"
title="Refresh this podcast"
onclick="refreshPodcast({{ .podcastId }}, {{ .title }})"
>
<i class="fas fa-sync"></i>
</button>
<button
class="button"
title="Download all episode files"
onclick="downloadAllEpisodes({{ .podcastId }})"
Expand Down
28 changes: 28 additions & 0 deletions client/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,34 @@
.then(function () {});
return false;
}
function refreshPodcast(id, title) {
axios
.get("/podcasts/" + id + "/refresh")
.then(function (response) {
Vue.toasted.show(
"\"" + title + "\" has been enqueued to refresh.",
{
theme: "bubble",
type: "info",
position: "top-right",
duration: 5000,
}
);
})
.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,
});
}
})
.then(function () {});
return false;
}
function deletePodcast(id,onSuccess) {
if (typeof id !== 'string'){
id= id.getAttribute('data-id')
Expand Down
40 changes: 39 additions & 1 deletion client/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@
<a href="/opml" class="button">Export OPML</a>
</div>
<div class="columns two">
<a title="Import this rss feed in your favorite podcast player" target="_blank" href="/rss" class="button">Rss Feed</a>
<a title="Import this RSS feed in your favorite podcast player" target="_blank" href="/rss" class="button">RSS Feed</a>
</div>
<div class="columns two">
<button
class="button"
title="Refresh all RSS feeds."
onclick="refreshEpisodes()"
>
Refresh All Feeds
</button>
</div>
</div>
<hr>
Expand Down Expand Up @@ -157,6 +166,35 @@ <h3>More Info</h3>

{{template "scripts"}}
<script>
function refreshEpisodes() {
axios
.get("/refreshAll")
.then(function (response) {
Vue.toasted.show(
"All feeds have been enqueued to refresh.",
{
theme: "bubble",
type: "info",
position: "top-right",
duration: 5000,
}
);
})
.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,
});
}
})
.then(function () {});
return false;
}
</script>
<script>
var app = new Vue({
delimiters: ['${', '}'],
el: '#app',
Expand Down
16 changes: 16 additions & 0 deletions controllers/podcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ func DownloadAllEpisodesByPodcastId(c *gin.Context) {
}
}

func RefreshEpisodes(c *gin.Context) {
go service.RefreshEpisodes()
c.JSON(200, gin.H{})
}

func RefreshEpisodesByPodcastId(c *gin.Context) {
var searchByIdQuery SearchByIdQuery

if c.ShouldBindUri(&searchByIdQuery) == nil {
go service.RefreshPodcastByPodcastId(searchByIdQuery.Id)
c.JSON(200, gin.H{})
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}

func GetAllPodcastItems(c *gin.Context) {
var filter model.EpisodesFilter
err := c.ShouldBindQuery(&filter)
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func main() {
router.DELETE("/podcasts/:id", controllers.DeletePodcastById)
router.GET("/podcasts/:id/items", controllers.GetPodcastItemsByPodcastId)
router.GET("/podcasts/:id/download", controllers.DownloadAllEpisodesByPodcastId)
router.GET("/podcasts/:id/refresh", controllers.RefreshEpisodesByPodcastId)
router.DELETE("/podcasts/:id/items", controllers.DeletePodcastEpisodesById)
router.DELETE("/podcasts/:id/podcast", controllers.DeleteOnlyPodcastById)
router.GET("/podcasts/:id/pause", controllers.PausePodcastById)
Expand All @@ -180,6 +181,7 @@ func main() {
router.POST("/podcasts/:id/tags/:tagId", controllers.AddTagToPodcast)
router.DELETE("/podcasts/:id/tags/:tagId", controllers.RemoveTagFromPodcast)

router.GET("/refreshAll", controllers.RefreshEpisodes)
router.GET("/add", controllers.AddPage)
router.GET("/search", controllers.Search)
router.GET("/", controllers.HomePage)
Expand Down
30 changes: 24 additions & 6 deletions service/podcastService.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,7 @@ func RefreshEpisodes() error {
return err
}
for _, item := range data {
isNewPodcast := item.LastEpisode == nil
if isNewPodcast {
fmt.Println(item.Title)
db.ForceSetLastEpisodeDate(item.ID)
}
AddPodcastItems(&item, isNewPodcast)
RefreshPodcast(&item)
}
// setting := db.GetOrCreateSetting()

Expand All @@ -628,6 +623,29 @@ func RefreshEpisodes() error {
return nil
}

func RefreshPodcastByPodcastId(podcastId string) error {
var podcast db.Podcast
err := db.GetPodcastById(podcastId, &podcast)
if err != nil {
return err
}

RefreshPodcast(&podcast)

go DownloadMissingEpisodes()

return nil
}

func RefreshPodcast(podcast *db.Podcast) {
isNewPodcast := podcast.LastEpisode == nil
if isNewPodcast {
fmt.Println(podcast.Title)
db.ForceSetLastEpisodeDate(podcast.ID)
}
AddPodcastItems(podcast, isNewPodcast)
}

func DeletePodcastEpisodes(id string) error {
var podcast db.Podcast

Expand Down