mirror of https://github.com/Xhofe/alist
chore: rename store to db
parent
c5295f4d72
commit
b474eefd87
|
@ -3,7 +3,7 @@ package bootstrap
|
|||
import (
|
||||
"github.com/alist-org/alist/v3/cmd/args"
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
|
@ -30,10 +30,10 @@ func InitDB() {
|
|||
Logger: newLogger,
|
||||
}
|
||||
if args.Dev {
|
||||
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), gormConfig)
|
||||
dB, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), gormConfig)
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
store.Init(db)
|
||||
db.Init(dB)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
conf2 "github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/operations"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
"github.com/alist-org/alist/v3/pkg/task"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
|
@ -26,7 +25,7 @@ func init() {
|
|||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
store.Init(db)
|
||||
db.Init(db)
|
||||
}
|
||||
|
||||
func TestConnect(t *testing.T) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package store
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
|
@ -1,4 +1,4 @@
|
|||
package store
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/go-cache"
|
|
@ -1,4 +1,4 @@
|
|||
package store
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
|
@ -1,4 +1,4 @@
|
|||
package store
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
|
@ -1,4 +1,4 @@
|
|||
package store
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/Xhofe/go-cache"
|
|
@ -1,4 +1,4 @@
|
|||
package store
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -7,9 +7,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/driver"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
"github.com/alist-org/alist/v3/pkg/generic_sync"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -33,7 +33,7 @@ func GetAccountByVirtualPath(virtualPath string) (driver.Driver, error) {
|
|||
func CreateAccount(ctx context.Context, account model.Account) error {
|
||||
account.Modified = time.Now()
|
||||
account.VirtualPath = utils.StandardizePath(account.VirtualPath)
|
||||
err := store.CreateAccount(&account)
|
||||
err := db.CreateAccount(&account)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed create account in database")
|
||||
}
|
||||
|
@ -56,13 +56,13 @@ func CreateAccount(ctx context.Context, account model.Account) error {
|
|||
// get old account first
|
||||
// drop the account then reinitialize
|
||||
func UpdateAccount(ctx context.Context, account model.Account) error {
|
||||
oldAccount, err := store.GetAccountById(account.ID)
|
||||
oldAccount, err := db.GetAccountById(account.ID)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get old account")
|
||||
}
|
||||
account.Modified = time.Now()
|
||||
account.VirtualPath = utils.StandardizePath(account.VirtualPath)
|
||||
err = store.UpdateAccount(&account)
|
||||
err = db.UpdateAccount(&account)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed update account in database")
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ func saveDriverAccount(driver driver.Driver) error {
|
|||
return errors.Wrap(err, "error while marshal addition")
|
||||
}
|
||||
account.Addition = string(bytes)
|
||||
err = store.UpdateAccount(&account)
|
||||
err = db.UpdateAccount(&account)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed update account in database")
|
||||
}
|
||||
|
|
|
@ -2,22 +2,22 @@ package operations_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"testing"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/operations"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
|
||||
dB, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
store.Init(db)
|
||||
db.Init(dB)
|
||||
}
|
||||
|
||||
func TestCreateAccount(t *testing.T) {
|
||||
|
|
|
@ -2,8 +2,8 @@ package controllers
|
|||
|
||||
import (
|
||||
"github.com/Xhofe/go-cache"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/server/common"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
)
|
||||
|
@ -34,7 +34,7 @@ func Login(c *gin.Context) {
|
|||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
}
|
||||
user, err := store.GetUserByName(req.Username)
|
||||
user, err := db.GetUserByName(req.Username)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 400)
|
||||
return
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/server/common"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@ -14,7 +14,7 @@ func AuthAdmin(c *gin.Context) {
|
|||
c.Abort()
|
||||
return
|
||||
}
|
||||
user, err := store.GetUserByName(userClaims.Username)
|
||||
user, err := db.GetUserByName(userClaims.Username)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 401)
|
||||
c.Abort()
|
||||
|
|
Loading…
Reference in New Issue