aility to delete podcast

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

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

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

@ -108,6 +108,17 @@ func DownloadPodcastItem(c *gin.Context) {
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) {
var addPodcastData AddPodcastData

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

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

Loading…
Cancel
Save