fix(sitestore): clean up sitestore for refactoring
This commit is contained in:
parent
9ff28ecce4
commit
b4dc30f824
14 changed files with 117 additions and 128 deletions
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/db"
|
||||
"github.com/ihexxa/quickshare/src/db/sitestore"
|
||||
"github.com/ihexxa/quickshare/src/db/userstore"
|
||||
)
|
||||
|
@ -120,10 +121,10 @@ func DefaultConfigStruct() *Config {
|
|||
WorkerCount: 2,
|
||||
},
|
||||
Site: &sitestore.SiteConfig{
|
||||
ClientCfg: &sitestore.ClientConfig{
|
||||
ClientCfg: &db.ClientConfig{
|
||||
SiteName: "Quickshare",
|
||||
SiteDesc: "quick and simple file sharing",
|
||||
Bg: &sitestore.BgConfig{
|
||||
Bg: &db.BgConfig{
|
||||
Url: "/static/img/textured_paper.png",
|
||||
Repeat: "repeat",
|
||||
Position: "fixed",
|
||||
|
|
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -41,6 +42,9 @@ func LoadCfg(args *Args) (*gocfg.Cfg, error) {
|
|||
_, err := os.Stat(dbPath)
|
||||
if err == nil {
|
||||
cfg, err = mergeDbConfig(cfg, dbPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
|
@ -64,8 +68,12 @@ func mergeDbConfig(cfg *gocfg.Cfg, dbPath string) (*gocfg.Cfg, error) {
|
|||
|
||||
clientCfg, err := siteStore.GetCfg()
|
||||
if err != nil {
|
||||
if errors.Is(err, sitestore.ErrNotFound) {
|
||||
return cfg, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clientCfgBytes, err := json.Marshal(clientCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
"github.com/ihexxa/gocfg"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/db"
|
||||
"github.com/ihexxa/quickshare/src/db/sitestore"
|
||||
"github.com/ihexxa/quickshare/src/db/userstore"
|
||||
)
|
||||
|
@ -111,10 +112,10 @@ func TestLoadCfg(t *testing.T) {
|
|||
WorkerCount: 1,
|
||||
},
|
||||
Site: &sitestore.SiteConfig{
|
||||
ClientCfg: &sitestore.ClientConfig{
|
||||
ClientCfg: &db.ClientConfig{
|
||||
SiteName: "1",
|
||||
SiteDesc: "1",
|
||||
Bg: &sitestore.BgConfig{
|
||||
Bg: &db.BgConfig{
|
||||
Url: "1",
|
||||
Repeat: "1",
|
||||
Position: "1",
|
||||
|
@ -177,10 +178,10 @@ func TestLoadCfg(t *testing.T) {
|
|||
WorkerCount: 4,
|
||||
},
|
||||
Site: &sitestore.SiteConfig{
|
||||
ClientCfg: &sitestore.ClientConfig{
|
||||
ClientCfg: &db.ClientConfig{
|
||||
SiteName: "4",
|
||||
SiteDesc: "4",
|
||||
Bg: &sitestore.BgConfig{
|
||||
Bg: &db.BgConfig{
|
||||
Url: "4",
|
||||
Repeat: "4",
|
||||
Position: "4",
|
||||
|
@ -243,10 +244,10 @@ func TestLoadCfg(t *testing.T) {
|
|||
WorkerCount: 4,
|
||||
},
|
||||
Site: &sitestore.SiteConfig{
|
||||
ClientCfg: &sitestore.ClientConfig{
|
||||
ClientCfg: &db.ClientConfig{
|
||||
SiteName: "4",
|
||||
SiteDesc: "4",
|
||||
Bg: &sitestore.BgConfig{
|
||||
Bg: &db.BgConfig{
|
||||
Url: "4",
|
||||
Repeat: "4",
|
||||
Position: "4",
|
||||
|
@ -309,15 +310,15 @@ func TestLoadCfg(t *testing.T) {
|
|||
WorkerCount: 4,
|
||||
},
|
||||
Site: &sitestore.SiteConfig{
|
||||
ClientCfg: &sitestore.ClientConfig{
|
||||
SiteName: "Quickshare",
|
||||
SiteDesc: "Quickshare",
|
||||
Bg: &sitestore.BgConfig{
|
||||
Url: "test.png",
|
||||
Repeat: "no-repeat",
|
||||
Position: "top",
|
||||
Align: "scroll",
|
||||
BgColor: "", // the schema of the config from db is old
|
||||
ClientCfg: &db.ClientConfig{
|
||||
SiteName: "4",
|
||||
SiteDesc: "4",
|
||||
Bg: &db.BgConfig{
|
||||
Url: "4",
|
||||
Repeat: "4",
|
||||
Position: "4",
|
||||
Align: "4",
|
||||
BgColor: "4",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/cryptoutil/jwt"
|
||||
"github.com/ihexxa/quickshare/src/db"
|
||||
"github.com/ihexxa/quickshare/src/db/boltstore"
|
||||
"github.com/ihexxa/quickshare/src/db/fileinfostore"
|
||||
"github.com/ihexxa/quickshare/src/db/sitestore"
|
||||
|
@ -162,10 +163,10 @@ func initDeps(cfg gocfg.ICfg) *depidx.Deps {
|
|||
}
|
||||
|
||||
err = siteStore.Init(&sitestore.SiteConfig{
|
||||
ClientCfg: &sitestore.ClientConfig{
|
||||
ClientCfg: &db.ClientConfig{
|
||||
SiteName: cfg.StringOr("Site.ClientCfg.SiteName", "Quickshare"),
|
||||
SiteDesc: cfg.StringOr("Site.ClientCfg.SiteDesc", "quick and simple file sharing"),
|
||||
Bg: &sitestore.BgConfig{
|
||||
Bg: &db.BgConfig{
|
||||
Url: cfg.StringOr("Site.ClientCfg.Bg.Url", "/static/img/textured_paper.png"),
|
||||
Repeat: cfg.StringOr("Site.ClientCfg.Bg.Repeat", "repeat"),
|
||||
Position: cfg.StringOr("Site.ClientCfg.Bg.Position", "fixed"),
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/client"
|
||||
"github.com/ihexxa/quickshare/src/db/sitestore"
|
||||
"github.com/ihexxa/quickshare/src/db"
|
||||
q "github.com/ihexxa/quickshare/src/handlers"
|
||||
"github.com/ihexxa/quickshare/src/handlers/settings"
|
||||
)
|
||||
|
@ -74,11 +74,11 @@ func TestSettingsHandlers(t *testing.T) {
|
|||
|
||||
t.Run("get/set client config", func(t *testing.T) {
|
||||
settingsCl := client.NewSettingsClient(addr)
|
||||
cfgs := []*sitestore.ClientConfig{
|
||||
&sitestore.ClientConfig{
|
||||
cfgs := []*db.ClientConfig{
|
||||
&db.ClientConfig{
|
||||
SiteName: "quickshare",
|
||||
SiteDesc: "quickshare",
|
||||
Bg: &sitestore.BgConfig{
|
||||
Bg: &db.BgConfig{
|
||||
Url: "url",
|
||||
Repeat: "repeat",
|
||||
Position: "center",
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/ihexxa/quickshare/src/client"
|
||||
"github.com/ihexxa/quickshare/src/db"
|
||||
"github.com/ihexxa/quickshare/src/db/sitestore"
|
||||
"github.com/ihexxa/quickshare/src/db/userstore"
|
||||
q "github.com/ihexxa/quickshare/src/handlers"
|
||||
su "github.com/ihexxa/quickshare/src/handlers/singleuserhdr"
|
||||
|
@ -448,7 +447,7 @@ func TestUsersHandlers(t *testing.T) {
|
|||
|
||||
prefers := []*db.Preferences{
|
||||
&db.Preferences{
|
||||
Bg: &sitestore.BgConfig{
|
||||
Bg: &db.BgConfig{
|
||||
Url: "/bgurl",
|
||||
Repeat: "no-repeat",
|
||||
Position: "center",
|
||||
|
@ -461,7 +460,7 @@ func TestUsersHandlers(t *testing.T) {
|
|||
Email: "email1",
|
||||
},
|
||||
&db.Preferences{
|
||||
Bg: &sitestore.BgConfig{
|
||||
Bg: &db.BgConfig{
|
||||
Url: "/bgurl2",
|
||||
Repeat: "no-repeat2",
|
||||
Position: "center2",
|
||||
|
|
BIN
src/server/testdata/test_quickshare.db
vendored
BIN
src/server/testdata/test_quickshare.db
vendored
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue