diff --git a/go.mod b/go.mod index d401a07..8676020 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,26 @@ module github.com/oolong-sh/oolong -go 1.22.7 +go 1.23.2 require github.com/yuin/gopher-lua v1.1.1 require ( - github.com/aaaton/golem/v4 v4.0.0 + github.com/aaaton/golem/v4 v4.0.1 github.com/aaaton/golem/v4/dicts/en v1.0.1 ) -require github.com/BurntSushi/toml v1.4.0 +require ( + github.com/BurntSushi/toml v1.4.0 + github.com/oolong-sh/sync v0.0.0-20241128232107-4aff73e779a0 +) + +require ( + github.com/kr/fs v0.1.0 // indirect + github.com/pkg/sftp v1.13.7 // indirect + golang.org/x/crypto v0.29.0 // indirect +) require ( github.com/fsnotify/fsnotify v1.8.0 - golang.org/x/sys v0.13.0 // indirect + golang.org/x/sys v0.27.0 // indirect ) diff --git a/go.sum b/go.sum index 7dc255a..052a8dd 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,75 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/aaaton/golem/v4 v4.0.0 h1:YHieBS+5Fqir298nJ7fk3EvMcKM/+T5gpMRt4TIAiZ8= github.com/aaaton/golem/v4 v4.0.0/go.mod h1:OfK/S5v9Exsx1yO21WorREuIVV+Y5K2hygP0A9oJCCI= +github.com/aaaton/golem/v4 v4.0.1 h1:jvnnTmzdfZC8cUGIo6obIcnmB3stTaf5Uw64OMx3C84= +github.com/aaaton/golem/v4 v4.0.1/go.mod h1:OfK/S5v9Exsx1yO21WorREuIVV+Y5K2hygP0A9oJCCI= github.com/aaaton/golem/v4/dicts/en v1.0.1 h1:/BsOsh8JTgTkuevwM9axPnAi9CD4rK7TWHNdW/6V3Uo= github.com/aaaton/golem/v4/dicts/en v1.0.1/go.mod h1:1YKRrQNng+KbS+peA7sj3TIa8eqR6T2UqdJ+Tc9xeoA= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/oolong-sh/sync v0.0.0-20241128232107-4aff73e779a0 h1:xQq7hGer2MRvHjLK4L+bLPFyCnwyFiiy/1F5Ap2LS30= +github.com/oolong-sh/sync v0.0.0-20241128232107-4aff73e779a0/go.mod h1:R+SR70YgYzJHvs81TcrFk6q2zcSFI9DoTo7d3yBPWHM= +github.com/pkg/sftp v1.13.7 h1:uv+I3nNJvlKZIQGSr8JVQLNHFU9YhhNpvC14Y6KgmSM= +github.com/pkg/sftp v1.13.7/go.mod h1:KMKI0t3T6hfA+lTR/ssZdunHo+uwq7ghoN09/FSu3DY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= +golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= +golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/api/api_utils.go b/internal/api/api_utils.go index 513219f..3eadf94 100644 --- a/internal/api/api_utils.go +++ b/internal/api/api_utils.go @@ -16,27 +16,25 @@ func checkOrigin(w http.ResponseWriter, r *http.Request) error { origin := r.Header.Get("Origin") // check if the origin is whitelisted - if !slices.Contains(allowedOrigins, origin) { - http.Error(w, "Request origin not in allow list", http.StatusForbidden) - return fmt.Errorf("Requesting client not in allow list. Origin: %s\n", origin) + if origin != "" { + if !slices.Contains(allowedOrigins, origin) { + http.Error(w, "Request origin not in allow list", http.StatusForbidden) + return fmt.Errorf("Requesting client not in allow list. Origin: %s\n", origin) + } + w.Header().Set("Access-Control-Allow-Origin", origin) } - w.Header().Set("Access-Control-Allow-Origin", origin) - return nil } // exists returns whether the given file or directory exists func exists(path string) (bool, error) { _, err := os.Stat(path) - if err == nil { return true, nil } - if os.IsNotExist(err) { return false, nil } - return false, err } diff --git a/internal/api/endpoints.go b/internal/api/endpoints.go index c1cde42..aedd3e1 100644 --- a/internal/api/endpoints.go +++ b/internal/api/endpoints.go @@ -9,6 +9,8 @@ import ( func SpawnServer() { mux := http.NewServeMux() + // TODO: add some sort of JWT system for better security + // graph endpoints mux.HandleFunc("GET /graph", handleGetGraph) @@ -19,10 +21,6 @@ func SpawnServer() { mux.HandleFunc("PUT /note", handleUpdateNote) mux.HandleFunc("DELETE /note", handleDeleteNote) - // keyword endpoints? - - // plugin endpoints? (probably not these outside of official ones) - // start server log.Println("Starting server on :11975...") if err := http.ListenAndServe(":11975", mux); err != nil { diff --git a/internal/api/graph_handlers.go b/internal/api/graph_handlers.go index f49eaa1..3d6cf2f 100644 --- a/internal/api/graph_handlers.go +++ b/internal/api/graph_handlers.go @@ -19,6 +19,7 @@ func handleGetGraph(w http.ResponseWriter, r *http.Request) { if err := checkOrigin(w, r); err != nil { log.Println(err) http.Error(w, fmt.Sprintln(err), 500) + return } // get snapshot of current state @@ -29,7 +30,6 @@ func handleGetGraph(w http.ResponseWriter, r *http.Request) { notes := notes.DocumentsToNotes(s.Documents) // serialize graph data - // TODO: pass in thresholds (with request? or with config?) data, err := graph.SerializeGraph(kw, notes) if err != nil { http.Error(w, "Error serializing graph data", 500) diff --git a/internal/api/note_handlers.go b/internal/api/note_handlers.go index 8ac8c52..ed275c0 100644 --- a/internal/api/note_handlers.go +++ b/internal/api/note_handlers.go @@ -24,6 +24,7 @@ func handleGetNotes(w http.ResponseWriter, r *http.Request) { if err := checkOrigin(w, r); err != nil { log.Println(err) http.Error(w, fmt.Sprintln(err), 500) + return } s := state.State() @@ -44,6 +45,7 @@ func handleGetNote(w http.ResponseWriter, r *http.Request) { if err := checkOrigin(w, r); err != nil { log.Println(err) http.Error(w, fmt.Sprintln(err), 500) + return } path := r.URL.Query().Get("path") @@ -77,6 +79,7 @@ func handleCreateNote(w http.ResponseWriter, r *http.Request) { if err := checkOrigin(w, r); err != nil { log.Println(err) http.Error(w, fmt.Sprintln(err), 500) + return } // parse request body @@ -121,6 +124,7 @@ func handleUpdateNote(w http.ResponseWriter, r *http.Request) { if err := checkOrigin(w, r); err != nil { log.Println(err) http.Error(w, fmt.Sprintln(err), 500) + return } // parse request body @@ -146,6 +150,7 @@ func handleDeleteNote(w http.ResponseWriter, r *http.Request) { if err := checkOrigin(w, r); err != nil { log.Println(err) http.Error(w, fmt.Sprintln(err), 500) + return } path := r.URL.Query().Get("path") diff --git a/internal/config/config.go b/internal/config/config.go index 227bc6a..84bc371 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,14 +2,15 @@ package config import ( "os" - "os/user" - "path/filepath" "github.com/BurntSushi/toml" + "github.com/oolong-sh/sync" ) var cfg OolongConfig +type OolongSyncConfig sync.SyncConfig + type OolongConfig struct { NotesDirPaths []string `toml:"note_directories"` NGramRange []int `toml:"ngram_range"` @@ -19,6 +20,7 @@ type OolongConfig struct { PluginsConfig OolongPluginConfig `toml:"plugins"` GraphConfig OolongGraphConfig `toml:"graph"` + SyncConfig OolongSyncConfig `toml:"sync"` } type OolongPluginConfig struct { @@ -40,12 +42,12 @@ func PluginPaths() []string { return cfg.PluginsConfig.PluginPaths func IgnoredDirectories() []string { return cfg.IgnoreDirectories } func StopWords() []string { return cfg.StopWords } func WeightThresholds() OolongGraphConfig { return cfg.GraphConfig } +func SyncConfig() OolongSyncConfig { return cfg.SyncConfig } // TODO: file watcher for config file, reload on change -func Setup(configPath string) error { - var err error - configPath, err = expand(configPath) +func Setup() error { + configPath, err := findConfigPath() if err != nil { panic(err) } @@ -72,15 +74,3 @@ func Setup(configPath string) error { return nil } - -func expand(path string) (string, error) { - if len(path) == 0 || path[0] != '~' { - return path, nil - } - - usr, err := user.Current() - if err != nil { - return "", err - } - return filepath.Join(usr.HomeDir, path[1:]), nil -} diff --git a/internal/config/config_utils.go b/internal/config/config_utils.go new file mode 100644 index 0000000..e854935 --- /dev/null +++ b/internal/config/config_utils.go @@ -0,0 +1,65 @@ +package config + +import ( + "fmt" + "os" + "os/user" + "path/filepath" +) + +func findConfigPath() (string, error) { + var err error + + // read config file location from env var, fall back to ~/.config/oolong.toml + configPath := os.Getenv("OOLONG_CONFIG_PATH") + if configPath == "" { + configPath, err = checkDefaultLocations() + if err != nil { + return "", err + } + } + fmt.Println(configPath) + + configPath, err = expand(configPath) + if err != nil { + return "", err + } + + return configPath, nil +} + +func checkDefaultLocations() (string, error) { + configPaths := []string{ + "~/.config/oolong.toml", + "~/.config/oolong/oolong.toml", + "~/oolong.toml", + "~/.oolong.toml", + "/etc/oolong/oolong.toml", + "./oolong.toml", + } + + for _, p := range configPaths { + configPath, err := expand(p) + if err != nil { + continue + } + + if _, err := os.Stat(configPath); err == nil { + return configPath, nil + } + } + + return "", fmt.Errorf("No fallback config file found.") +} + +func expand(path string) (string, error) { + if len(path) == 0 || path[0] != '~' { + return path, nil + } + + usr, err := user.Current() + if err != nil { + return "", err + } + return filepath.Join(usr.HomeDir, path[1:]), nil +} diff --git a/internal/daemon/sync.go b/internal/daemon/sync.go new file mode 100644 index 0000000..e31258c --- /dev/null +++ b/internal/daemon/sync.go @@ -0,0 +1,31 @@ +package daemon + +import ( + "log" + + "github.com/oolong-sh/oolong/internal/config" + "github.com/oolong-sh/sync" +) + +func Sync(files ...string) error { + syncConfig := config.SyncConfig() + + // stop if synchronization is not enabled (no config/bad config) + if syncConfig.Host == "" { + log.Println("Synchronization not enabled.") + return nil + } + + s, err := sync.NewClient(sync.SyncConfig(syncConfig)) + if err != nil { + return err + } + + if err := s.Update(files...); err != nil { + return err + } + + log.Println("Done syncing.") + + return nil +} diff --git a/internal/daemon/watcher.go b/internal/daemon/watcher.go index 56888f1..8154eff 100644 --- a/internal/daemon/watcher.go +++ b/internal/daemon/watcher.go @@ -24,10 +24,17 @@ func runNotesDirsWatcher(dirs ...string) error { dirIgnores := config.IgnoredDirectories() + files := []string{} for _, dir := range dirs { + if _, err := os.Stat(dir); err != nil { + log.Printf("Error creating watcher on directory '%s': %v\n", dir, err) + continue + } + // TODO: add oolong ignore system to blacklist certain subdirs/files if err = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { if !d.IsDir() { + files = append(files, path) return nil } @@ -50,6 +57,13 @@ func runNotesDirsWatcher(dirs ...string) error { } } + // run initial server synchronization + go func(files []string) { + if err := Sync(files...); err != nil { + log.Printf("Failed to synchronize files %s: %v\n", files, err) + } + }(files) + // watcher handler for { select { @@ -66,6 +80,12 @@ func runNotesDirsWatcher(dirs ...string) error { // write event is sent on write start, wait 500ms for write to finish time.Sleep(500) + go func(file string) { + if err := Sync(file); err != nil { + log.Printf("Failed to synchronize file %s: %v\n", file, err) + } + }(event.Name) + // re-read document documents.ReadDocuments(event.Name) @@ -77,10 +97,13 @@ func runNotesDirsWatcher(dirs ...string) error { // - need to be careful with remove event as editors use it when writing files // - state removal needs to also remove ngrams // - should only trigger update on file deletions + // TODO: sync handling case event.Has(fsnotify.Create): log.Println("Created file/directory", event.Name) + // TODO: sync handling? + if info, err := os.Stat(event.Name); err == nil { if info.IsDir() { watcher.Add(event.Name) diff --git a/internal/documents/corpus.go b/internal/documents/corpus.go index 2f95447..5b9da8f 100644 --- a/internal/documents/corpus.go +++ b/internal/documents/corpus.go @@ -4,6 +4,7 @@ import ( "errors" "io/fs" "log" + "os" "path/filepath" "slices" "sync" @@ -41,6 +42,11 @@ func ReadNotesDirs() error { docs := []*Document{} for _, dir := range config.NotesDirPaths() { + if _, err := os.Stat(dir); err != nil { + log.Printf("Error reading directory '%s': %v\n", dir, err) + continue + } + // extract all note file paths from notes directory paths := []string{} // TODO: add oolong ignore system to blacklist certain subdirs/files diff --git a/internal/linking/lexer/lexer_test.go b/internal/linking/lexer/lexer_test.go index ca685ba..3daf85e 100644 --- a/internal/linking/lexer/lexer_test.go +++ b/internal/linking/lexer/lexer_test.go @@ -3,6 +3,7 @@ package lexer_test import ( "fmt" "io" + "os" "slices" "strings" "testing" @@ -14,7 +15,10 @@ import ( var cfg config.OolongConfig func init() { - if err := config.Setup("../../../examples/oolong.toml"); err != nil { + if err := os.Setenv("OOLONG_CONFIG_PATH", "../../../examples/oolong.toml"); err != nil { + panic(err) + } + if err := config.Setup(); err != nil { panic(err) } } diff --git a/internal/state/state.go b/internal/state/state.go index e7be7e5..52ea8c1 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -104,10 +104,9 @@ func (s *StateManager) updateState(docs []*documents.Document) { // if err := os.WriteFile("./meaningful-ngrams.csv", b, 0666); err != nil { // panic(err) // } - // // TODO: add threshold filtering params to these functions (use config) // kw := keywords.NGramsToKeywordsMap(s.state.NGrams) // notes := notes.DocumentsToNotes(s.state.Documents) - // dat, err := graph.SerializeGraph(kw, notes, 0.1, 80) + // dat, err := graph.SerializeGraph(kw, notes) // if err != nil { // panic(err) // } diff --git a/main.go b/main.go index 46deac0..f04dbc2 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ var daemonFlag = flag.Bool("no-daemon", false, "Run Oolong in no-daemon mode (no func main() { // read in config - if err := config.Setup("~/.config/oolong.toml"); err != nil { + if err := config.Setup(); err != nil { panic(err) }