feat: proxy download image
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user