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"
|
||||
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
|
||||
)
|
||||
|
||||
type initializeCommand struct {
|
||||
VaultPath string `json:"vaultPath"`
|
||||
TemplateDirectory string `json:"templateDirectory"`
|
||||
ScratchDirectory string `json:"scratchDirectory"`
|
||||
ScratchTemplate string `json:"scratchTemplate"`
|
||||
DailyDirectory string `json:"dailyDirectory"`
|
||||
DailyTemplate string `json:"dailyTemplate"`
|
||||
}
|
||||
|
||||
type InitializeHandler struct{}
|
||||
|
|
@ -29,9 +26,9 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
|
|||
return nil, err
|
||||
}
|
||||
|
||||
store := store.NewVaultStore(cmd.VaultPath, cmd.TemplateDirectory)
|
||||
|
||||
|
||||
err := persistence.InitializeDBContext(cmd.VaultPath)
|
||||
err := persistence.InitializeDBContext(store.Config.VaultPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
BIN
dendrite
BIN
dendrite
Binary file not shown.
|
|
@ -5,46 +5,16 @@ import "path"
|
|||
type VaultConfiguration struct {
|
||||
path 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 {
|
||||
return &VaultConfiguration{path: vaultPath, templateDirectory: templateDirectory, scratches: struct {
|
||||
directory string
|
||||
templateName string
|
||||
}{
|
||||
directory: scratchDirectory,
|
||||
templateName: scratchTemplate,
|
||||
}, dailyNotes: struct {
|
||||
directory string
|
||||
templateName string
|
||||
}{
|
||||
directory: dailyDirectory,
|
||||
templateName: dailyTemplate,
|
||||
}}
|
||||
func NewVaultConfiguration(vaultPath, templateDirectory string) *VaultConfiguration {
|
||||
return &VaultConfiguration{path: vaultPath, templateDirectory: templateDirectory}
|
||||
}
|
||||
|
||||
func (vc *VaultConfiguration) VaultPath() string {
|
||||
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 {
|
||||
fileType := path.Ext(templateName)
|
||||
if fileType != ".md" {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ type VaultStore struct {
|
|||
|
||||
var vaultStore *VaultStore
|
||||
|
||||
func NewVaultStore(vaultPath string) *VaultStore {
|
||||
func NewVaultStore(vault, templateDir string) *VaultStore {
|
||||
if vaultStore != nil {
|
||||
return vaultStore
|
||||
}
|
||||
vaultStore = &VaultStore{}
|
||||
vaultStore = &VaultStore{Config: persistenceconfig.NewVaultConfiguration(vault, templateDir)}
|
||||
return vaultStore
|
||||
}
|
||||
|
||||
|
|
@ -22,3 +22,7 @@ func GetVaultStore() *VaultStore {
|
|||
}
|
||||
return vaultStore
|
||||
}
|
||||
|
||||
func (vs *VaultStore) SetConfig(config persistenceconfig.VaultConfiguration) {
|
||||
vs.Config = &config
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue