regular backups

pull/24/head
Akhil Gupta 4 years ago
parent 2265f46229
commit b39e879325

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PodGrab</title>
{{template "commoncss"}}
<style>
.button-delete{
background-color: indianred;
color:wheat;
}
img{
display: none;
}
@media (max-width: 750px) {
.label-body{
display: inline!important;
}
}
/* Larger than tablet */
@media (min-width: 750px) {
img{
display: block
}
}
</style>
</head>
<body>
<div class="container">
{{template "navbar" .}}
<br>
<div class="row" id="app">
<div class="columns twelve">
<table class="u-full-width">
<thead>
<th>Date</th>
<th>Path</th>
</thead>
<tbody>
{{ range .backups}}
<tr>
<td>{{ formatDate .date }}</td>
<td><a href="{{ .path }}" download="">{{.name}}</a></td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
{{template "scripts"}}
<script>
</script>
</body>
</html>

@ -32,10 +32,17 @@
{{template "navbar" .}}
<br>
<div class="row">
<div class="columns twelve">
<a href="/backups" class="button">Backups</a>
</div>
</div>
<hr>
<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">
<h3>Settings</h3>
<label for="downloadOnAdd">
<input type="checkbox" name="downloadOnAdd" v-model="downloadOnAdd">
<span class="label-body">Download episodes whenever new podcast is added</span>

@ -4,7 +4,10 @@ import (
"fmt"
"math"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/akhilrex/podgrab/db"
"github.com/akhilrex/podgrab/service"
@ -64,6 +67,37 @@ func SettingsPage(c *gin.Context) {
"title": "Update your preferences",
})
}
func BackupsPage(c *gin.Context) {
files, err := service.GetAllBackupFiles()
var allFiles []interface{}
for _, file := range files {
arr := strings.Split(file, string(os.PathSeparator))
name := arr[len(arr)-1]
subsplit := strings.Split(name, "_")
dateStr := subsplit[2]
date, err := time.Parse("2006.01.02", dateStr)
if err == nil {
toAdd := map[string]interface{}{
"date": date,
"name": name,
"path": strings.ReplaceAll(file, string(os.PathSeparator), "/"),
}
allFiles = append(allFiles, toAdd)
}
}
if err == nil {
c.HTML(http.StatusOK, "backups.html", gin.H{
"backups": allFiles,
"title": "Backups",
})
} else {
c.JSON(http.StatusBadRequest, err)
}
}
func AllEpisodesPage(c *gin.Context) {
var pagination Pagination

@ -86,6 +86,7 @@ func main() {
r.GET("/episodes", controllers.AllEpisodesPage)
r.GET("/settings", controllers.SettingsPage)
r.POST("/settings", controllers.UpdateSetting)
r.GET("/backups", controllers.BackupsPage)
go assetEnv()
go intiCron()

@ -68,7 +68,7 @@ func FileExists(filePath string) bool {
}
func deleteOldBackup() {
func GetAllBackupFiles() ([]string, error) {
var files []string
folder := createIfFoldeDoesntExist("backups")
err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
@ -77,6 +77,12 @@ func deleteOldBackup() {
}
return nil
})
sort.Sort(sort.Reverse(sort.StringSlice(files)))
return files, err
}
func deleteOldBackup() {
files, err := GetAllBackupFiles()
if err != nil {
return
}
@ -84,8 +90,6 @@ func deleteOldBackup() {
return
}
sort.Sort(sort.Reverse(sort.StringSlice(files)))
toDelete := files[5:]
for _, file := range toDelete {
fmt.Println(file)

Loading…
Cancel
Save