tangled
alpha
login
or
join now
finxol.io
/
bookmarker
0
fork
atom
A very simple bookmarking webapp
bookmarker.finxol.deno.net/
0
fork
atom
overview
issues
pulls
pipelines
refactor: remove boilerplate
finxol.io
1 month ago
26f92754
993ac1a5
verified
This commit was signed with the committer's
known signature
.
finxol.io
SSH Key Fingerprint:
SHA256:olFE3asYdoBMScuJOt60UxXdJ0RFdGv5kVKrdOtIcPI=
1/1
deploy.yaml
success
12s
+5
-51
1 changed file
expand all
collapse all
unified
split
server
routes
bookmarks.ts
+5
-51
server/routes/bookmarks.ts
reviewed
···
5
5
import { encodeHex } from "@std/encoding/hex"
6
6
import { parse } from "node-html-parser"
7
7
import type { Variables } from "../utils/globals.ts"
8
8
-
import { getUserSub } from "../utils/auth.ts"
9
8
import { tryCatch } from "../utils/utils.ts"
10
9
import { ofetch } from "ofetch"
11
10
import { type } from "arktype"
···
64
63
65
64
const app = new Hono<Variables>()
66
65
.get("/all", async (c) => {
67
67
-
const subject = getUserSub(c)
68
68
-
69
69
-
if (!subject) {
70
70
-
return c.json(
71
71
-
{
72
72
-
message: "User subject missing in context",
73
73
-
},
74
74
-
500,
75
75
-
)
76
76
-
}
66
66
+
const subject = c.get("user")
77
67
78
68
const it = kv.list<Bookmark>({ prefix: ["bookmarks", subject.id] })
79
69
···
95
85
)
96
86
})
97
87
.post("/add", async (c) => {
98
98
-
const subject = getUserSub(c)
99
99
-
100
100
-
if (!subject) {
101
101
-
return c.json(
102
102
-
{
103
103
-
message: "User subject missing in context",
104
104
-
},
105
105
-
500,
106
106
-
)
107
107
-
}
88
88
+
const subject = c.get("user")
108
89
109
90
const urlParam = c.req.query("url")
110
91
const urlBody = (await c.req.parseBody()).url
···
149
130
return c.json({ id })
150
131
})
151
132
.post("/import", async (c) => {
152
152
-
const subject = getUserSub(c)
153
153
-
154
154
-
if (!subject) {
155
155
-
return c.json(
156
156
-
{
157
157
-
message: "User subject missing in context",
158
158
-
},
159
159
-
500,
160
160
-
)
161
161
-
}
133
133
+
const subject = c.get("user")
162
134
163
135
const body = await c.req.json()
164
136
const bookmarks = BookmarkSchema.array()(body.bookmarks)
···
206
178
return c.json(results)
207
179
})
208
180
.delete("/all", async (c) => {
209
209
-
const subject = getUserSub(c)
210
210
-
211
211
-
if (!subject) {
212
212
-
return c.json(
213
213
-
{
214
214
-
message: "User subject missing in context",
215
215
-
},
216
216
-
500,
217
217
-
)
218
218
-
}
181
181
+
const subject = c.get("user")
219
182
220
183
const it = kv.list({ prefix: ["bookmarks", subject.id] })
221
184
···
225
188
return c.text("Bookmarks deleted!")
226
189
})
227
190
.delete("/:id", async (c) => {
228
228
-
const subject = getUserSub(c)
229
229
-
230
230
-
if (!subject) {
231
231
-
return c.json(
232
232
-
{
233
233
-
message: "User subject missing in context",
234
234
-
},
235
235
-
500,
236
236
-
)
237
237
-
}
191
191
+
const subject = c.get("user")
238
192
239
193
const id = c.req.param("id")
240
194