diff --git a/README.md b/README.md new file mode 100644 index 0000000..e38574e --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +```bash +// hot-reload +go install github.com/air-verse/air@latest +air + +// REPL +gore +``` diff --git a/api/api b/api/api deleted file mode 100755 index ee32005..0000000 Binary files a/api/api and /dev/null differ diff --git a/api/main.go b/api/main.go index bc950c8..abcacab 100644 --- a/api/main.go +++ b/api/main.go @@ -1,23 +1,28 @@ package main import ( - // "os" - // "fmt" + "fmt" + "io/fs" + "log" + "os" + "path" + "net/http" + "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" ) func main() { router := gin.Default() - // port = os.Getenv("API_PORT") || 8912 - router.SetTrustedProxies([]string{"127.0.0.1"}) // TODO: fix - router.Use(cors.Default()) // All origins allowed by default + router.SetTrustedProxies([]string{"127.0.0.1"}) // TODO: fix All origins allowed by default + router.Use(cors.Default()) + list := listFiles("/Users/madundead/Syncthing/Obsidian/Personal") - router.GET("/api/v1/ping", func(c *gin.Context) { + router.GET("/api/v1/files", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ - "message": "pong", - "status": "ok", + "data": list, + "status": "ok", }) }) @@ -25,3 +30,28 @@ func main() { panic(err) } } + +func listFiles(dir string) []string { + root := os.DirFS(dir) + + mdFiles, err := fs.Glob(root, "**/*.md") + + if err != nil { + log.Fatal(err) + } + + var files []string + for _, v := range mdFiles { + files = append(files, path.Join(dir, v)) + } + return files +} + +func readFile(string filePath) []string { + content, err := os.ReadFile(filePath) + if err != nil { + fmt.Println("Error reading file:", err) + return + } + return content +} diff --git a/frontend/src/APITester.tsx b/frontend/src/APITester.tsx deleted file mode 100644 index 3f09c04..0000000 --- a/frontend/src/APITester.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { useRef, type FormEvent } from "react"; - -export function APITester() { - const responseInputRef = useRef(null); - - const testEndpoint = async (e: FormEvent) => { - e.preventDefault(); - - try { - const form = e.currentTarget; - const formData = new FormData(form); - const endpoint = formData.get("endpoint") as string; - const url = new URL(endpoint, "http://localhost:8912"); - const method = formData.get("method") as string; - const res = await fetch(url, { method }); - - const data = await res.json(); - responseInputRef.current!.value = JSON.stringify(data, null, 2); - } catch (error) { - responseInputRef.current!.value = String(error); - } - }; - - return ( -
-
- - - -
-