feat(vault_store): simplified store and config
This commit is contained in:
parent
a8346e82f1
commit
1aa7c167a7
4 changed files with 11 additions and 40 deletions
|
|
@ -5,15 +5,12 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
||||||
|
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type initializeCommand struct {
|
type initializeCommand struct {
|
||||||
VaultPath string `json:"vaultPath"`
|
VaultPath string `json:"vaultPath"`
|
||||||
TemplateDirectory string `json:"templateDirectory"`
|
TemplateDirectory string `json:"templateDirectory"`
|
||||||
ScratchDirectory string `json:"scratchDirectory"`
|
|
||||||
ScratchTemplate string `json:"scratchTemplate"`
|
|
||||||
DailyDirectory string `json:"dailyDirectory"`
|
|
||||||
DailyTemplate string `json:"dailyTemplate"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type InitializeHandler struct{}
|
type InitializeHandler struct{}
|
||||||
|
|
@ -29,9 +26,9 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
store := store.NewVaultStore(cmd.VaultPath, cmd.TemplateDirectory)
|
||||||
|
|
||||||
|
err := persistence.InitializeDBContext(store.Config.VaultPath())
|
||||||
err := persistence.InitializeDBContext(cmd.VaultPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
dendrite
BIN
dendrite
Binary file not shown.
|
|
@ -5,46 +5,16 @@ import "path"
|
||||||
type VaultConfiguration struct {
|
type VaultConfiguration struct {
|
||||||
path string
|
path string
|
||||||
templateDirectory string
|
templateDirectory string
|
||||||
scratches struct {
|
|
||||||
directory string
|
|
||||||
templateName string
|
|
||||||
}
|
|
||||||
dailyNotes struct {
|
|
||||||
directory string
|
|
||||||
templateName string
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVaultConfiguration(vaultPath, templateDirectory, scratchDirectory, scratchTemplate, dailyDirectory, dailyTemplate string) *VaultConfiguration {
|
func NewVaultConfiguration(vaultPath, templateDirectory string) *VaultConfiguration {
|
||||||
return &VaultConfiguration{path: vaultPath, templateDirectory: templateDirectory, scratches: struct {
|
return &VaultConfiguration{path: vaultPath, templateDirectory: templateDirectory}
|
||||||
directory string
|
|
||||||
templateName string
|
|
||||||
}{
|
|
||||||
directory: scratchDirectory,
|
|
||||||
templateName: scratchTemplate,
|
|
||||||
}, dailyNotes: struct {
|
|
||||||
directory string
|
|
||||||
templateName string
|
|
||||||
}{
|
|
||||||
directory: dailyDirectory,
|
|
||||||
templateName: dailyTemplate,
|
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc *VaultConfiguration) VaultPath() string {
|
func (vc *VaultConfiguration) VaultPath() string {
|
||||||
return vc.path
|
return vc.path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vc *VaultConfiguration) ScratchTemplatePath() string {
|
|
||||||
fileName := vc.fileTypeCheck(vc.scratches.templateName)
|
|
||||||
return path.Join(vc.templateDirectory, fileName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (vc *VaultConfiguration) DailyTemplatePath() string {
|
|
||||||
fileName := vc.fileTypeCheck(vc.dailyNotes.templateName)
|
|
||||||
return path.Join(vc.templateDirectory, fileName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (vc *VaultConfiguration) fileTypeCheck(templateName string) string {
|
func (vc *VaultConfiguration) fileTypeCheck(templateName string) string {
|
||||||
fileType := path.Ext(templateName)
|
fileType := path.Ext(templateName)
|
||||||
if fileType != ".md" {
|
if fileType != ".md" {
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ type VaultStore struct {
|
||||||
|
|
||||||
var vaultStore *VaultStore
|
var vaultStore *VaultStore
|
||||||
|
|
||||||
func NewVaultStore(vaultPath string) *VaultStore {
|
func NewVaultStore(vault, templateDir string) *VaultStore {
|
||||||
if vaultStore != nil {
|
if vaultStore != nil {
|
||||||
return vaultStore
|
return vaultStore
|
||||||
}
|
}
|
||||||
vaultStore = &VaultStore{}
|
vaultStore = &VaultStore{Config: persistenceconfig.NewVaultConfiguration(vault, templateDir)}
|
||||||
return vaultStore
|
return vaultStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,3 +22,7 @@ func GetVaultStore() *VaultStore {
|
||||||
}
|
}
|
||||||
return vaultStore
|
return vaultStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vs *VaultStore) SetConfig(config persistenceconfig.VaultConfiguration) {
|
||||||
|
vs.Config = &config
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue