Public
HTTP
nbbaier-mirroredsearchapi.web.val.run
January 16, 2024
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { fetchPaginatedData } from "https://esm.town/v/nbbaier/fetchPaginatedData";
import { paginatedResponse } from "https://esm.town/v/nbbaier/paginatedResponse";
import { Hono } from "npm:hono";
const app = new Hono();
app.get("/", async c => {
const req = c.req;
const params = req.queries();
const endpoint = `https://api.val.town/v1/search/vals?query=${params.q}`;
// TODO figure out a way to pass a user's valtown here when via the vscode extension
const data = await fetchPaginatedData(endpoint);
// TODO add more filters (search params)
let vals = data;
if (params.name) { vals = vals.filter(val => val.name.includes(params.name)); }
if (params.user) { vals = vals.filter(val => val.author.username === `@${params.user}`); }
if (params.privacy) { vals = vals.filter(val => val.privacy === params.privacy); }
// TODO add sorting
return paginatedResponse(req, vals);
});
export default app.fetch;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
January 16, 2024