background checking of deleted files

pull/24/head
Akhil Gupta 4 years ago
parent 9be83f7fb5
commit 8419897870

@ -69,6 +69,11 @@ func GetAllPodcastItemsToBeDownloaded() (*[]PodcastItem, error) {
result := DB.Debug().Preload(clause.Associations).Where("download_date=?", time.Time{}).Find(&podcastItems) result := DB.Debug().Preload(clause.Associations).Where("download_date=?", time.Time{}).Find(&podcastItems)
return &podcastItems, result.Error return &podcastItems, result.Error
} }
func GetAllPodcastItemsAlreadyDownloaded() (*[]PodcastItem, error) {
var podcastItems []PodcastItem
result := DB.Debug().Preload(clause.Associations).Where("download_date!=?", time.Time{}).Find(&podcastItems)
return &podcastItems, result.Error
}
func GetPodcastItemByPodcastIdAndGUID(podcastId string, guid string, podcastItem *PodcastItem) error { func GetPodcastItemByPodcastIdAndGUID(podcastId string, guid string, podcastItem *PodcastItem) error {

@ -110,6 +110,7 @@ func intiCron() {
} }
//gocron.Every(uint64(checkFrequency)).Minutes().Do(service.DownloadMissingEpisodes) //gocron.Every(uint64(checkFrequency)).Minutes().Do(service.DownloadMissingEpisodes)
gocron.Every(uint64(checkFrequency)).Minutes().Do(service.RefreshEpisodes) gocron.Every(uint64(checkFrequency)).Minutes().Do(service.RefreshEpisodes)
gocron.Every(uint64(checkFrequency)).Minutes().Do(service.CheckMissingFiles)
<-gocron.Start() <-gocron.Start()
} }

@ -58,6 +58,11 @@ func DeleteFile(filePath string) error {
} }
return nil return nil
} }
func FileExists(filePath string) bool {
_, err := os.Stat(filePath)
return err == nil
}
func httpClient() *http.Client { func httpClient() *http.Client {
client := http.Client{ client := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error { CheckRedirect: func(r *http.Request, via []*http.Request) error {

@ -128,6 +128,21 @@ func DownloadMissingEpisodes() error {
} }
return nil return nil
} }
func CheckMissingFiles() error {
data, err := db.GetAllPodcastItemsAlreadyDownloaded()
//fmt.Println("Processing episodes: ", strconv.Itoa(len(*data)))
if err != nil {
return err
}
for _, item := range *data {
fileExists := FileExists(item.DownloadPath)
if !fileExists {
SetPodcastItemAsNotDownloaded(item.ID)
}
}
return nil
}
func DeleteEpisodeFile(podcastItemId string) error { func DeleteEpisodeFile(podcastItemId string) error {
var podcastItem db.PodcastItem var podcastItem db.PodcastItem

Loading…
Cancel
Save