diff --git a/backend/config/const.go b/backend/config/const.go index 5ca72e5..abcf243 100644 --- a/backend/config/const.go +++ b/backend/config/const.go @@ -1,8 +1,12 @@ package config -const LocalNotePath = "data/notes/" -const AppDataPath = "data/vortexnotes/" -const AppDbPath = AppDataPath + "app.db" -const IndexPath = AppDataPath + "notes.bleve" +import "os" + +var basePath, _ = os.Getwd() +var LocalNotePath = basePath + "/data/notes/" +var AppDataPath = basePath + "/data/vortexnotes/" +var AppDbPath = AppDataPath + "app.db" +var IndexPath = AppDataPath + "notes.bleve" + const ApiHost = "0.0.0.0" const ApiPort = "7701" diff --git a/backend/indexer/indexer.go b/backend/indexer/indexer.go index a80599b..c40bea5 100644 --- a/backend/indexer/indexer.go +++ b/backend/indexer/indexer.go @@ -65,6 +65,7 @@ func ListNotes() []string { } func NoteExist(path string) bool { + logger.Logger.Println("NoteExist", path) fileInfo, err := os.Stat(path) if err != nil { return false diff --git a/backend/storages/local-storage.go b/backend/storages/local-storage.go index 4467c50..cff632c 100644 --- a/backend/storages/local-storage.go +++ b/backend/storages/local-storage.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "strings" + "vortexnotes/backend/config" "vortexnotes/backend/logger" ) @@ -60,6 +61,11 @@ func ListTextFiles(dirPath string) (error, []string) { return nil, textFiles } +func Init() { + _ = CreateDirectoryIfNotExists(config.LocalNotePath) + _ = CreateDirectoryIfNotExists(config.AppDataPath) +} + func CreateDirectoryIfNotExists(dirPath string) error { _, err := os.Stat(dirPath) if os.IsNotExist(err) { diff --git a/main.go b/main.go index 1730c68..0b6cb5f 100644 --- a/main.go +++ b/main.go @@ -4,9 +4,11 @@ import ( "vortexnotes/backend/api" "vortexnotes/backend/database" "vortexnotes/backend/indexer" + "vortexnotes/backend/storages" ) func main() { + storages.Init() database.Init() indexer.Start() api.Start()