Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/drivers/base/upload.go
1987 views
1
package base
2
3
import (
4
"fmt"
5
"strings"
6
"time"
7
8
"github.com/Xhofe/go-cache"
9
"github.com/alist-org/alist/v3/internal/driver"
10
)
11
12
// storage upload progress, for upload recovery
13
var UploadStateCache = cache.NewMemCache(cache.WithShards[any](32))
14
15
// Save upload progress for 20 minutes
16
func SaveUploadProgress(driver driver.Driver, state any, keys ...string) bool {
17
return UploadStateCache.Set(
18
fmt.Sprint(driver.Config().Name, "-upload-", strings.Join(keys, "-")),
19
state,
20
cache.WithEx[any](time.Minute*20))
21
}
22
23
// An upload progress can only be made by one process alone,
24
// so here you need to get it and then delete it.
25
func GetUploadProgress[T any](driver driver.Driver, keys ...string) (state T, ok bool) {
26
v, ok := UploadStateCache.GetDel(fmt.Sprint(driver.Config().Name, "-upload-", strings.Join(keys, "-")))
27
if ok {
28
state, ok = v.(T)
29
}
30
return
31
}
32
33