summaryrefslogtreecommitdiff
path: root/pages/api/notes
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-10-11 21:27:17 +0200
committerGitHub <[email protected]>2021-10-11 21:27:17 +0200
commit58b7030d45370072dee25214748670d6413343a9 (patch)
tree9632df7273415f4b197413c45ad11563af32d53a /pages/api/notes
parent89be3b67b2d10d35d72b5c54e1e166beeeef3095 (diff)
parent6e3dcf585c35620c6804f3c208e6882c29dfc17e (diff)
Merge pull request #101 from org-roam/sidebar
feat: Add file preview functionality
Diffstat (limited to 'pages/api/notes')
-rw-r--r--pages/api/notes/[[...slug]].ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/pages/api/notes/[[...slug]].ts b/pages/api/notes/[[...slug]].ts
new file mode 100644
index 0000000..b0df82a
--- /dev/null
+++ b/pages/api/notes/[[...slug]].ts
@@ -0,0 +1,17 @@
+import fs from 'fs'
+
+export default async function handler(req: any, res: any) {
+ const { slug } = req.query
+ const stuff = slug.join('')
+ console.log(stuff)
+ const uri = decodeURIComponent(slug)
+ const prefix = uri.includes('\\') ? '' : '/'
+ const path = `${uri}`
+ try {
+ const text = fs.readFileSync(`${path}`, { encoding: 'utf-8' })
+ res.end(`${text}`)
+ } catch (e) {
+ res.end(`Oopsie Whoopsie! We did a fucky wucky!`)
+ console.log(e)
+ }
+}