75```
7677See the [URLPattern API](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) for reference.
7879## Logout
1import { api } from "https://esm.town/v/pomdtr/api";
2import { zip } from "https://esm.town/v/pomdtr/sql";
3import { sqlite } from "https://esm.town/v/std/sqlite";
marineMoccasinLizardmain.tsx9 matches
49const fetchAnswersAndRankings = async () => {
50if (user) {
51const response = await fetch("/api/answers");
52const data = await response.json();
53setAnswers(data.answers);
59const saveAnswer = useCallback(async (newAnswer: Answer, losingAnswer: string) => {
60if (user) {
61await fetch("/api/answer", {
62method: "POST",
63headers: { "Content-Type": "application/json" },
70const clearAnswers = useCallback(async () => {
71if (user) {
72await fetch("/api/clear-answers", { method: "POST" });
73setAnswers([]);
74setRankings([]);
242const handleLogin = useCallback(async (e: React.FormEvent) => {
243e.preventDefault();
244const response = await fetch("/api/login", {
245method: "POST",
246headers: { "Content-Type": "application/json" },
314315const url = new URL(request.url);
316if (url.pathname === "/api/login") {
317const { username } = await request.json();
318await sqlite.execute(`INSERT OR IGNORE INTO ${KEY}_users (username) VALUES (?)`, [username]);
321}
322323if (url.pathname === "/api/answer") {
324const { questionId, answer, losingAnswer } = await request.json();
325const userId = 1; // In a real app, you'd get this from the session
333}
334335if (url.pathname === "/api/answers") {
336const userId = 1; // In a real app, you'd get this from the session
337const answers = (await sqlite.execute(`SELECT * FROM ${KEY}_answers WHERE user_id = ?`, [userId])).rows;
340}
341342if (url.pathname === "/api/clear-answers") {
343const userId = 1; // In a real app, you'd get this from the session
344await sqlite.execute(`DELETE FROM ${KEY}_answers WHERE user_id = ?`, [userId]);
411412const css = `
413@import url('https://fonts.googleapis.com/css2?family=Pacifico&family=Roboto:wght@300;400;500&display=swap');
414415:root {
npmExplorermain.tsx8 matches
1/**
2* This val creates an enhanced NPM package explorer using the npm registry API.
3* It displays a grid of npm packages with basic information, categories, and navigation.
4* The approach uses React for the frontend and fetch for API calls.
5* It includes a details view for each package, a link to the npm page, and category navigation.
6* Icons are added for each category, and additional pill boxes are included for specific topics.
40performance: "⚡",
41devops: "🚀",
42api: "🔌",
43authentication: "🔑",
44deployment: "📦",
276const category = url.searchParams.get("category") || "";
277278let apiUrl = `https://registry.npmjs.org/-/v1/search?text=${
279encodeURIComponent(searchTerm)
280}&size=${size}&from=${from}`;
281282if (category === "popular") {
283apiUrl += "&popularity=1.0";
284} else if (category === "new") {
285apiUrl += "&maintenance=0&quality=0&popularity=0";
286} else if (category !== "all" && category) {
287apiUrl += `&keywords=${encodeURIComponent(category)}`;
288}
289290try {
291const response = await fetch(apiUrl);
292const data = await response.json();
293return new Response(JSON.stringify(data), {
69) {
70return async (req: Request) => {
71const { api } = await import("https://esm.town/v/pomdtr/api");
72const { deleteCookie, getCookies, setCookie } = await import("jsr:@std/http/cookie");
73
sqliteExplorerAppREADME.md1 match
13## Authentication
1415Login to your SQLite Explorer with [password authentication](https://www.val.town/v/pomdtr/password_auth) with your [Val Town API Token](https://www.val.town/settings/api) as the password.
1617## Todos / Plans
sqliteExplorerAppmain.tsx2 matches
27<head>
28<title>SQLite Explorer</title>
29<link rel="preconnect" href="https://fonts.googleapis.com" />
3031<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32<link
33href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
34rel="stylesheet"
35/>
891. Click `Fork`
102. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
113. Click `Run`
12
6* Fork this val to your own profile.
7* Make a folder for the temporary vals that get generated, take the ID from the URL, and put it in `tempValsParentFolderId`.
8* If you want to use OpenAI models you need to set the `OPENAI_API_KEY` [env var](https://www.val.town/settings/environment-variables).
9* If you want to use Anthropic models you need to set the `ANTHROPIC_API_KEY` [env var](https://www.val.town/settings/environment-variables).
10* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
1112<img width=500 src="https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/7077d1b5-1fa7-4a9b-4b93-f8d01d3e4f00/public"/>
valleBlogV0README.md1 match
1* Fork this val to your own profile.
2* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
3