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

@ -6,6 +6,9 @@ import (
"github.com/sirupsen/logrus"
"gorm.io/gorm"
"nf-repo/internal/interfaces"
"nf-repo/internal/opt"
"os"
"path"
)
type tx struct {
@ -13,7 +16,13 @@ type tx struct {
}
func (t *tx) TX(ctx context.Context) *gorm.DB {
return t.db.Session(&gorm.Session{}).WithContext(ctx)
db := t.db.Session(&gorm.Session{}).WithContext(ctx)
if opt.Debug {
db = db.Debug()
}
return db
}
func newTX(db *gorm.DB) interfaces.Database {
@ -39,6 +48,10 @@ func Must(database interfaces.Database, err error) interfaces.Database {
}
func NewSqliteTX(filepath string) (interfaces.Database, error) {
if err := os.MkdirAll(path.Dir(filepath), 0755); err != nil {
return nil, err
}
db, err := gorm.Open(sqlite.Open(filepath), &gorm.Config{})
return newTX(db), err
}