feat: automatically resync completed downloads to webdav
This commit is contained in:
@@ -37,6 +37,7 @@ func main() {
|
||||
a.storage = NewWebDAVStorage(a.cfg)
|
||||
}
|
||||
a.startWorkers()
|
||||
a.startWebDAVResync()
|
||||
|
||||
r := gin.Default()
|
||||
r.StaticFile("/", "/app/index.html")
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
|
||||
// resyncPendingUploads repairs tasks that finished locally while WebDAV was
|
||||
// unavailable or the user's WebDAV permission was not yet configured.
|
||||
func (a *App) resyncPendingUploads() {
|
||||
var tasks []Task
|
||||
if err := a.db.Where("status = ? AND local_path <> ? AND (remote_path = ? OR remote_path IS NULL)", "done", "", "").Order("id asc").Limit(100).Find(&tasks).Error; err != nil {
|
||||
return
|
||||
}
|
||||
for i := range tasks {
|
||||
t := tasks[i]
|
||||
if _, _, ok := a.storageForTask(&t); !ok {
|
||||
continue
|
||||
}
|
||||
a.upload(&t)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
// startWebDAVResync runs a small periodic repair loop. It is intentionally
|
||||
// conservative: only completed local tasks without a remote path are retried.
|
||||
func (a *App) startWebDAVResync() {
|
||||
go func() {
|
||||
a.resyncPendingUploads()
|
||||
ticker := time.NewTicker(5 * time.Minute)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
a.resyncPendingUploads()
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user