mirror of https://github.com/Xhofe/alist
fix: link cache not deleted after overwriting file (close #4852)
parent
e2ca06dcca
commit
0c1acd72ca
|
@ -25,6 +25,7 @@ type Link struct {
|
||||||
Status int // status maybe 200 or 206, etc
|
Status int // status maybe 200 or 206, etc
|
||||||
FilePath *string // local file, return the filepath
|
FilePath *string // local file, return the filepath
|
||||||
Expiration *time.Duration // url expiration time
|
Expiration *time.Duration // url expiration time
|
||||||
|
IPCacheKey bool // add ip to cache key
|
||||||
//Handle func(w http.ResponseWriter, r *http.Request) error `json:"-"` // custom handler
|
//Handle func(w http.ResponseWriter, r *http.Request) error `json:"-"` // custom handler
|
||||||
Writer WriterFunc `json:"-"` // custom writer
|
Writer WriterFunc `json:"-"` // custom writer
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,7 +243,7 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
|
||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
return nil, nil, errors.WithStack(errs.NotFile)
|
return nil, nil, errors.WithStack(errs.NotFile)
|
||||||
}
|
}
|
||||||
key := Key(storage, path) + ":" + args.IP
|
key := Key(storage, path)
|
||||||
if link, ok := linkCache.Get(key); ok {
|
if link, ok := linkCache.Get(key); ok {
|
||||||
return link, file, nil
|
return link, file, nil
|
||||||
}
|
}
|
||||||
|
@ -253,6 +253,9 @@ func Link(ctx context.Context, storage driver.Driver, path string, args model.Li
|
||||||
return nil, errors.Wrapf(err, "failed get link")
|
return nil, errors.Wrapf(err, "failed get link")
|
||||||
}
|
}
|
||||||
if link.Expiration != nil {
|
if link.Expiration != nil {
|
||||||
|
if link.IPCacheKey {
|
||||||
|
key = key + ":" + args.IP
|
||||||
|
}
|
||||||
linkCache.Set(key, link, cache.WithEx[*model.Link](*link.Expiration))
|
linkCache.Set(key, link, cache.WithEx[*model.Link](*link.Expiration))
|
||||||
}
|
}
|
||||||
return link, nil
|
return link, nil
|
||||||
|
@ -563,6 +566,9 @@ func Put(ctx context.Context, storage driver.Driver, dstDirPath string, file *mo
|
||||||
err := Remove(ctx, storage, tempPath)
|
err := Remove(ctx, storage, tempPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else {
|
||||||
|
key := Key(storage, stdpath.Join(dstDirPath, file.GetName()))
|
||||||
|
linkCache.Del(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue