template path fix (#48)
This commit is contained in:
parent
a21ff37225
commit
4025f03826
4 changed files with 9 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ package vault
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/services"
|
"github.com/KristianJBorgwarth/dendrite.daemon/core/services"
|
||||||
|
|
@ -45,6 +46,10 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmd.Config.VaultPath == "" {
|
||||||
|
return nil, errors.New("vault_path is empty — check your dendrite.nvim config")
|
||||||
|
}
|
||||||
|
|
||||||
store := store.NewVaultStore(
|
store := store.NewVaultStore(
|
||||||
cmd.Config.VaultName,
|
cmd.Config.VaultName,
|
||||||
cmd.Config.VaultPath,
|
cmd.Config.VaultPath,
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ func GetVaultStore() *VaultStore {
|
||||||
|
|
||||||
func (vs *VaultStore) GetTemplatePath(templateName string) string {
|
func (vs *VaultStore) GetTemplatePath(templateName string) string {
|
||||||
templateName = vs.fileTypeCheck(templateName)
|
templateName = vs.fileTypeCheck(templateName)
|
||||||
return path.Join(vs.Config.TemplateDirectory(), templateName)
|
path := path.Join(vs.Config.VaultPath(), vs.Config.TemplateDirectory(), templateName)
|
||||||
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vs *VaultStore) fileTypeCheck(templateName string) string {
|
func (vs *VaultStore) fileTypeCheck(templateName string) string {
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ func TestCreateNoteHandler_WithTemplate_CreatesNoteFileWithTagsAndReturnsPath(t
|
||||||
handler := newCreateNoteHandler()
|
handler := newCreateNoteHandler()
|
||||||
|
|
||||||
vaultPath := Fixture.VaultStore.Config.VaultPath()
|
vaultPath := Fixture.VaultStore.Config.VaultPath()
|
||||||
templateDir := Fixture.VaultStore.Config.TemplateDirectory()
|
templateDir := filepath.Join(Fixture.VaultStore.Config.VaultPath(), Fixture.VaultStore.Config.TemplateDirectory())
|
||||||
require.NoError(t, os.MkdirAll(templateDir, 0o755))
|
require.NoError(t, os.MkdirAll(templateDir, 0o755))
|
||||||
|
|
||||||
templatePath := filepath.Join(templateDir, "template.md")
|
templatePath := filepath.Join(templateDir, "template.md")
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -46,7 +45,7 @@ func NewDBFixture() *DBFixture {
|
||||||
DB: dbContext.DB,
|
DB: dbContext.DB,
|
||||||
DBPath: dbPath,
|
DBPath: dbPath,
|
||||||
TestContext: context.Background(),
|
TestContext: context.Background(),
|
||||||
VaultStore: store.NewVaultStore("testVault", vaultPath, path.Join(vaultPath, "templates"), []string{}, false, "", "", ""),
|
VaultStore: store.NewVaultStore("testVault", vaultPath, "templates", []string{}, false, "", "", ""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue