feat(dep/fileindex): enable fileindex in file managing

This commit is contained in:
hexxa 2022-07-21 22:25:38 +08:00 committed by Hexxa
parent 28b7113d27
commit dff79ed87f
7 changed files with 111 additions and 44 deletions

View file

@ -41,13 +41,14 @@ type Secrets struct {
}
type ServerCfg struct {
Debug bool `json:"debug" yaml:"debug"`
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port" cfg:"env"`
ReadTimeout int `json:"readTimeout" yaml:"readTimeout"`
WriteTimeout int `json:"writeTimeout" yaml:"writeTimeout"`
MaxHeaderBytes int `json:"maxHeaderBytes" yaml:"maxHeaderBytes"`
PublicPath string `json:"publicPath" yaml:"publicPath"`
Debug bool `json:"debug" yaml:"debug"`
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port" cfg:"env"`
ReadTimeout int `json:"readTimeout" yaml:"readTimeout"`
WriteTimeout int `json:"writeTimeout" yaml:"writeTimeout"`
MaxHeaderBytes int `json:"maxHeaderBytes" yaml:"maxHeaderBytes"`
PublicPath string `json:"publicPath" yaml:"publicPath"`
SearchResultLimit int `json:"searchResultLimit" yaml:"searchResultLimit"`
}
type WorkerPoolCfg struct {
@ -105,13 +106,14 @@ func DefaultConfigStruct() *Config {
TokenSecret: "", // it will auto generated if it is left as empty
},
Server: &ServerCfg{
Debug: false,
Host: "0.0.0.0",
Port: 8686,
ReadTimeout: 2000,
WriteTimeout: 1000 * 3600 * 24, // 1 day
MaxHeaderBytes: 512,
PublicPath: "static/public",
Debug: false,
Host: "0.0.0.0",
Port: 8686,
ReadTimeout: 2000,
WriteTimeout: 1000 * 3600 * 24, // 1 day
MaxHeaderBytes: 512,
PublicPath: "static/public",
SearchResultLimit: 16,
},
Workers: &WorkerPoolCfg{
QueueSize: 1024,

View file

@ -126,13 +126,14 @@ func TestLoadCfg(t *testing.T) {
TokenSecret: "1",
},
Server: &ServerCfg{
Debug: true,
Host: "1",
Port: 1,
ReadTimeout: 1,
WriteTimeout: 1,
MaxHeaderBytes: 1,
PublicPath: "1",
Debug: true,
Host: "1",
Port: 1,
ReadTimeout: 1,
WriteTimeout: 1,
MaxHeaderBytes: 1,
PublicPath: "1",
SearchResultLimit: 16,
},
Workers: &WorkerPoolCfg{
QueueSize: 1,
@ -192,13 +193,14 @@ func TestLoadCfg(t *testing.T) {
TokenSecret: "4",
},
Server: &ServerCfg{
Debug: false,
Host: "4",
Port: 4,
ReadTimeout: 4,
WriteTimeout: 4,
MaxHeaderBytes: 4,
PublicPath: "4",
Debug: false,
Host: "4",
Port: 4,
ReadTimeout: 4,
WriteTimeout: 4,
MaxHeaderBytes: 4,
PublicPath: "4",
SearchResultLimit: 16,
},
Workers: &WorkerPoolCfg{
QueueSize: 4,
@ -260,13 +262,14 @@ func TestLoadCfg(t *testing.T) {
TokenSecret: "4",
},
Server: &ServerCfg{
Debug: false,
Host: "4",
Port: 4,
ReadTimeout: 4,
WriteTimeout: 4,
MaxHeaderBytes: 4,
PublicPath: "4",
Debug: false,
Host: "4",
Port: 4,
ReadTimeout: 4,
WriteTimeout: 4,
MaxHeaderBytes: 4,
PublicPath: "4",
SearchResultLimit: 16,
},
Workers: &WorkerPoolCfg{
QueueSize: 4,
@ -328,13 +331,14 @@ func TestLoadCfg(t *testing.T) {
TokenSecret: "4",
},
Server: &ServerCfg{
Debug: false,
Host: "4",
Port: 4,
ReadTimeout: 4,
WriteTimeout: 4,
MaxHeaderBytes: 4,
PublicPath: "4",
Debug: false,
Host: "4",
Port: 4,
ReadTimeout: 4,
WriteTimeout: 4,
MaxHeaderBytes: 4,
PublicPath: "4",
SearchResultLimit: 16,
},
Workers: &WorkerPoolCfg{
QueueSize: 4,

View file

@ -38,6 +38,7 @@ import (
"github.com/ihexxa/quickshare/src/iolimiter"
"github.com/ihexxa/quickshare/src/kvstore"
"github.com/ihexxa/quickshare/src/kvstore/boltdbpvd"
"github.com/ihexxa/quickshare/src/search/fileindex"
"github.com/ihexxa/quickshare/src/worker/localworker"
qsstatic "github.com/ihexxa/quickshare/static"
)
@ -140,6 +141,9 @@ func initDeps(cfg gocfg.ICfg) *depidx.Deps {
filesystem := local.NewLocalFS(rootPath, 0660, opensLimit, openTTL, readerTTL, ider)
jwtEncDec := jwt.NewJWTEncDec(secret)
searchResultLimit := cfg.GrabInt("Server.SearchResultLimit")
fileIndex := fileindex.NewFileTreeIndex(filesystem, "/", searchResultLimit)
dbPath := cfg.GrabString("Db.DbPath")
dbDir := filepath.Dir(dbPath)
if err := filesystem.MkdirAll(dbDir); err != nil {
@ -196,6 +200,7 @@ func initDeps(cfg gocfg.ICfg) *depidx.Deps {
deps.SetID(ider)
deps.SetLog(logger)
deps.SetLimiter(limiter)
deps.SetIFileIndex(fileIndex)
queueSize := cfg.GrabInt("Workers.QueueSize")
sleepCyc := cfg.GrabInt("Workers.SleepCyc")

Binary file not shown.