nbbaier/paginatedResponse

References

Referenced 2 times

Expanded search endpoint

This is a mirrored version of the Val Town API /search/vals endpoint, meant mostly for use with pomdtr's vscode extension. It allows for more sophisticated filtering of the results of a search.

Readme
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;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { fetchPaginatedData } from "https://esm.town/v/nbbaier/fetchPaginatedData";
import { paginatedResponse } from "https://esm.town/v/nbbaier/paginatedResponse";
import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
const id = Deno.env.get("USER_ID");
const vals = await fetchPaginatedData(
`${API_URL}/v1/users/${id}/vals`,
{
headers: { Authorization: `Bearer ${Deno.env.get("valtown")}` },
},
);
export default async function(req: Request): Promise<Response> {
return Response.json({ url: `${API_URL}/v1/users/${id}/vals` }); // paginatedResponse(req, vals, 100);
}
1
Next