mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-11-05 14:07:01 +00:00
fix
This commit is contained in:
parent
94cb43508c
commit
af49f9a8f6
2 changed files with 8 additions and 7 deletions
|
@ -65,7 +65,7 @@ type BranchTimestamp struct {
|
|||
}
|
||||
|
||||
type writeCacheReader struct {
|
||||
r io.Reader
|
||||
rc io.ReadCloser
|
||||
buff *bytes.Buffer
|
||||
f *FileResponse
|
||||
cacheKey string
|
||||
|
@ -74,7 +74,7 @@ type writeCacheReader struct {
|
|||
}
|
||||
|
||||
func (t *writeCacheReader) Read(p []byte) (n int, err error) {
|
||||
n, err = t.r.Read(p)
|
||||
n, err = t.rc.Read(p)
|
||||
if err != nil {
|
||||
t.hasErr = true
|
||||
} else if n > 0 {
|
||||
|
@ -85,16 +85,17 @@ func (t *writeCacheReader) Read(p []byte) (n int, err error) {
|
|||
|
||||
func (t *writeCacheReader) Close() error {
|
||||
if !t.hasErr {
|
||||
t.f.Body = t.buff.Bytes()
|
||||
t.cache.Set(t.cacheKey, *t.f, fileCacheTimeout)
|
||||
fc := *t.f
|
||||
fc.Body = t.buff.Bytes()
|
||||
_ = t.cache.Set(t.cacheKey, fc, fileCacheTimeout)
|
||||
}
|
||||
return t.Close()
|
||||
return t.rc.Close()
|
||||
}
|
||||
|
||||
func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey, cacheKey string) io.ReadCloser {
|
||||
buf := []byte{}
|
||||
return &writeCacheReader{
|
||||
r: r,
|
||||
rc: r,
|
||||
buff: bytes.NewBuffer(buf),
|
||||
f: &f,
|
||||
cacheKey: cacheKey,
|
||||
|
|
|
@ -97,7 +97,7 @@ func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource str
|
|||
log := log.With().Str("cache_key", cacheKey).Logger()
|
||||
|
||||
// handle if cache entry exist
|
||||
if cache, ok := client.responseCache.Get(cacheKey); ok == true {
|
||||
if cache, ok := client.responseCache.Get(cacheKey); ok {
|
||||
cache := cache.(FileResponse)
|
||||
// TODO: check against some timestamp missmatch?!?
|
||||
if cache.Exists {
|
||||
|
|
Loading…
Reference in a new issue