aility to delete podcast

pull/24/head
Akhil Gupta 4 years ago
parent 94f893465c
commit 78e6806e2c

@ -70,6 +70,8 @@ hr{
<p>{{ .Summary }}</p> <p>{{ .Summary }}</p>
{{if .DownloadPath}} {{if .DownloadPath}}
<a class="button button-primary" href="{{ .DownloadPath }}" download>Download</a> <a class="button button-primary" href="{{ .DownloadPath }}" download>Download</a>
<a class="button button" onclick="deleteFile('{{.ID}}')" download>Delete</a>
{{else}} {{else}}
{{if not $setting.AutoDownload}} {{if not $setting.AutoDownload}}
<a class="button button-primary" onclick="downloadToDisk('{{.ID}}')" download>Download to Disk</a> <a class="button button-primary" onclick="downloadToDisk('{{.ID}}')" download>Download to Disk</a>
@ -125,6 +127,33 @@ function downloadToDisk(id){
}) })
return false; 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;
}
</script> </script>
</body> </body>
</html> </html>

@ -14,11 +14,17 @@
img{ img{
display: none; display: none;
} }
@media (max-width: 750px) {
.label-body{
display: inline!important;
}
}
/* Larger than tablet */ /* Larger than tablet */
@media (min-width: 750px) { @media (min-width: 750px) {
img{ img{
display: block display: block
} }
} }
</style> </style>
</head> </head>
@ -30,12 +36,17 @@
{{template "navbar"}} {{template "navbar"}}
<br> <br>
<div class="row" id="app"> <div class="row" id="app">
<div class="columns twelve">
<form action="/saveSettings" method="post" @submit="saveSettings"> <form action="/saveSettings" method="post" @submit="saveSettings">
<div class="row">
<label for="downloadOnAdd"> <label for="downloadOnAdd">
<input type="checkbox" name="downloadOnAdd" v-model="downloadOnAdd"> <input type="checkbox" name="downloadOnAdd" v-model="downloadOnAdd">
<span class="label-body">Download episodes whenever new podcast is added</span> <span class="label-body">Download episodes whenever new podcast is added</span>
</label> </label>
</div>
<div v-if="downloadOnAdd"> <div v-if="downloadOnAdd">
<br>
<label for="initialDownloadCount" > <label for="initialDownloadCount" >
<span class="label-body">How many episodes to be downloaded when a new podcast is added</span> <span class="label-body">How many episodes to be downloaded when a new podcast is added</span>
@ -43,13 +54,15 @@
</label> </label>
<input type="number" name="initialDownloadCount" v-model.number="initialDownloadCount" min="0"> <input type="number" name="initialDownloadCount" v-model.number="initialDownloadCount" min="0">
</div> </div>
<br>
<label for="autoDownload"> <label for="autoDownload">
<input type="checkbox" name="autoDownload" v-model="autoDownload"> <input type="checkbox" name="autoDownload" v-model="autoDownload">
<span class="label-body">Automatically download new episodes to the disk</span> <span class="label-body">Automatically download new episodes to the disk</span>
</label> </label>
<br>
<input type="submit" value="Save" class="button button-primary"> <input type="submit" value="Save" class="button button-primary">
</form> </form>
</div>
</div> </div>
{{template "scripts"}} {{template "scripts"}}

@ -108,6 +108,17 @@ func DownloadPodcastItem(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) 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) { func AddPodcast(c *gin.Context) {
var addPodcastData AddPodcastData var addPodcastData AddPodcastData

@ -77,6 +77,7 @@ func main() {
r.GET("/podcastitems", controllers.GetAllPodcastItems) r.GET("/podcastitems", controllers.GetAllPodcastItems)
r.GET("/podcastitems/:id", controllers.GetPodcastItemById) r.GET("/podcastitems/:id", controllers.GetPodcastItemById)
r.GET("/podcastitems/:id/download", controllers.DownloadPodcastItem) r.GET("/podcastitems/:id/download", controllers.DownloadPodcastItem)
r.GET("/podcastitems/:id/delete", controllers.DeletePodcastItem)
r.GET("/add", controllers.AddPage) r.GET("/add", controllers.AddPage)
r.GET("/search", controllers.Search) r.GET("/search", controllers.Search)

@ -102,6 +102,17 @@ func SetPodcastItemAsDownloaded(id string, location string) error {
return db.UpdatePodcastItem(&podcastItem) 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 { func DownloadMissingEpisodes() error {
data, err := db.GetAllPodcastItemsToBeDownloaded() data, err := db.GetAllPodcastItemsToBeDownloaded()
@ -117,6 +128,22 @@ func DownloadMissingEpisodes() error {
} }
return nil 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 { func DownloadSingleEpisode(podcastItemId string) error {
var podcastItem db.PodcastItem var podcastItem db.PodcastItem
err := db.GetPodcastItemById(podcastItemId, &podcastItem) err := db.GetPodcastItemById(podcastItemId, &podcastItem)

Loading…
Cancel
Save