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