mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-07-18 17:38:07 +08:00

* Enable blank issue * chore(README.md): update docs (temporally) * Update FUNDING.yml * chore: purge README.md * chore: change module name to OpenListTeam/OpenList * fix: fix link errors * chore: remove v3 in module name * fix: resolve some conficts * fix: resolve conficts * docs: update with latest file --------- Co-authored-by: ShenLin <773933146@qq.com> Co-authored-by: Hantong Chen <cxwdyx620@gmail.com> Co-authored-by: joshua <i@joshua.su> Co-authored-by: Hantong Chen <70561268+cxw620@users.noreply.github.com>
32 lines
869 B
Go
32 lines
869 B
Go
package base
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/OpenListTeam/OpenList/internal/driver"
|
|
"github.com/Xhofe/go-cache"
|
|
)
|
|
|
|
// storage upload progress, for upload recovery
|
|
var UploadStateCache = cache.NewMemCache(cache.WithShards[any](32))
|
|
|
|
// Save upload progress for 20 minutes
|
|
func SaveUploadProgress(driver driver.Driver, state any, keys ...string) bool {
|
|
return UploadStateCache.Set(
|
|
fmt.Sprint(driver.Config().Name, "-upload-", strings.Join(keys, "-")),
|
|
state,
|
|
cache.WithEx[any](time.Minute*20))
|
|
}
|
|
|
|
// An upload progress can only be made by one process alone,
|
|
// so here you need to get it and then delete it.
|
|
func GetUploadProgress[T any](driver driver.Driver, keys ...string) (state T, ok bool) {
|
|
v, ok := UploadStateCache.GetDel(fmt.Sprint(driver.Config().Name, "-upload-", strings.Join(keys, "-")))
|
|
if ok {
|
|
state, ok = v.(T)
|
|
}
|
|
return
|
|
}
|