mirror of https://github.com/Xhofe/alist
feat(task): attach creator to `user` of the context (#7729)
parent
aa1082a56c
commit
6745dcc139
|
@ -1,17 +1,21 @@
|
||||||
package task
|
package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/xhofe/tache"
|
"github.com/xhofe/tache"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskExtension struct {
|
type TaskExtension struct {
|
||||||
tache.Base
|
tache.Base
|
||||||
Creator *model.User
|
ctx context.Context
|
||||||
startTime *time.Time
|
ctxInitMutex sync.Mutex
|
||||||
endTime *time.Time
|
Creator *model.User
|
||||||
totalBytes int64
|
startTime *time.Time
|
||||||
|
endTime *time.Time
|
||||||
|
totalBytes int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TaskExtension) SetCreator(creator *model.User) {
|
func (t *TaskExtension) SetCreator(creator *model.User) {
|
||||||
|
@ -51,6 +55,17 @@ func (t *TaskExtension) GetTotalBytes() int64 {
|
||||||
return t.totalBytes
|
return t.totalBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TaskExtension) Ctx() context.Context {
|
||||||
|
if t.ctx == nil {
|
||||||
|
t.ctxInitMutex.Lock()
|
||||||
|
if t.ctx == nil {
|
||||||
|
t.ctx = context.WithValue(t.Base.Ctx(), "user", t.Creator)
|
||||||
|
}
|
||||||
|
t.ctxInitMutex.Unlock()
|
||||||
|
}
|
||||||
|
return t.ctx
|
||||||
|
}
|
||||||
|
|
||||||
type TaskExtensionInfo interface {
|
type TaskExtensionInfo interface {
|
||||||
tache.TaskWithInfo
|
tache.TaskWithInfo
|
||||||
GetCreator() *model.User
|
GetCreator() *model.User
|
||||||
|
|
Loading…
Reference in New Issue