feat: proxy download image

This commit is contained in:
loveuer
2024-04-15 18:02:54 +08:00
parent c5d0b8e45b
commit 410a4c0d8d
57 changed files with 10913 additions and 316 deletions

View File

@ -7,6 +7,7 @@ import (
"nf-repo/internal/interfaces"
"nf-repo/internal/model"
"nf-repo/internal/opt"
"nf-repo/internal/verify"
"os"
"path"
"sync"
@ -48,12 +49,13 @@ func (l *localHandler) Stat(ctx context.Context, repo string, hash model.Hash) (
var (
err error
info os.FileInfo
sp = l.path(hash)
)
l.Lock()
defer l.Unlock()
if info, err = os.Stat(l.path(hash)); err != nil {
if info, err = os.Stat(sp); err != nil {
if errors.Is(err, os.ErrNotExist) {
return 0, opt.ErrNotFound
}
@ -68,11 +70,17 @@ func (l *localHandler) Put(ctx context.Context, repo string, hash model.Hash, rc
var (
err error
f *os.File
nrc io.ReadCloser
)
l.Lock()
defer l.Unlock()
if nrc, err = verify.ReadCloser(rc, verify.SizeUnknown, hash); err != nil {
return err
}
defer nrc.Close()
if f, err = os.OpenFile(l.path(hash), os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644); err != nil {
return err
}