vtProjectSearchweb.http.tsx1 match
1import { handler } from "./api.tsx";
2import { loadTypeaheadDataIntoMemory } from "./db.ts";
3
vtProjectSearchstyles.tsx4 matches
753}
754755.api-info {
756margin-top: 10px;
757}
758759.api-info summary {
760cursor: pointer;
761color: var(--primary-color);
763}
764765.api-docs {
766background-color: var(--code-bg);
767padding: 10px 15px;
772}
773774.api-docs code {
775display: inline-block;
776background-color: white;
vtProjectSearchimport.ts1 match
37profile_image_url: user.profileImageUrl,
38url: user.url,
39updated_at: new Date().toISOString(), // Using current time as the API doesn't provide updated_at
40});
41
vtProjectSearchdeno.lock2 matches
363},
364"redirects": {
365"https://esm.town/v/std/API_URL": "https://esm.town/v/std/API_URL?v=5",
366"https://esm.town/v/stevekrouse/sqlite": "https://esm.town/v/stevekrouse/sqlite?v=13"
367},
368"remote": {
369"https://docs.val.town/pagefind/pagefind.js": "43ee232b23e27fa6b00d4f71f08a165d35a824947525989c7a051843e408e0c0",
370"https://esm.town/v/std/API_URL?v=5": "46109f905a50e32281d3ffbe7b9c8209a778290c5274d83d131fba2d26c4974d",
371"https://esm.town/v/stevekrouse/sqlite?v=13": "3b613197e9da35db335dc2726c062c61f9247439c10a0c64c118994e200ffa46"
372}
vtProjectSearchcomponents.tsx8 matches
1062<link rel="icon" href="https://fav.farm/👀" />
1063<meta name="viewport" content="width=device-width, initial-scale=1" />
1064<link rel="preconnect" href="https://fonts.googleapis.com" />
1065<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous" />
1066<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,100..700;1,100..700&display=swap" rel="stylesheet" />
1067<style>
1068{styles}
1073<div className="header">
1074<h1><a href="/" className="title-link">Val Town Code Search</a><a href="https://val.town" className="valtown-link" style={{ marginLeft: 'auto' }} >Return to Val Town</a></h1>
1075<div className="api-info">
1076<details>
1077<summary>API Access</summary>
1078<div className="api-docs">
1079<p>You can access search results via JSON API by adding <code>format=json</code> to your query:</p>
1080{searchTerm ? (
1081<a href={`?q=${encodeURIComponent(searchTerm)}&page=${currentPage}&format=json`} target="_blank">
1210<div className="search-examples">
1211<a href="?q=fetch" className="example-link">fetch</a>
1212<a href="?q=api" className="example-link">api</a>
1213<a href="?q=database" className="example-link">database</a>
1214<a href="?q=image" className="example-link">image</a>
1355<div className="search-examples">
1356<a href="?q=fetch" className="example-link">fetch</a>
1357<a href="?q=api" className="example-link">api</a>
1358<a href="?q=database" className="example-link">database</a>
1359<a href="?q=image" className="example-link">image</a>
vtProjectSearchapi.tsx2 matches
13import { searchDocs, searchDocsCount } from "./docsearch.ts";
1415// Handle typeahead API requests
16export function handleTypeahead(req: Request): Response {
17const url = new URL(req.url);
99searchTerm
100? (needFullDocsData
101? searchDocs(searchTerm, page, pageSize, true) // Get full data for docs tab or JSON API
102: searchDocsCount(searchTerm).then(count => ({ results: [], totalResults: count }))) // Just get count for other tabs in HTML view
103: { results: [], totalResults: 0 }
26});
2728// --- API Routes for Memories ---
2930// GET /api/memories - Retrieve all memories
31app.get("/api/memories", async (c) => {
32const memories = await getAllMemories();
33return c.json(memories);
34});
3536// POST /api/memories - Create a new memory
37app.post("/api/memories", async (c) => {
38const body = await c.req.json<Omit<Memory, "id">>();
39if (!body.text) {
44});
4546// PUT /api/memories/:id - Update an existing memory
47app.put("/api/memories/:id", async (c) => {
48const id = c.req.param("id");
49const body = await c.req.json<Partial<Omit<Memory, "id">>>();
66});
6768// DELETE /api/memories/:id - Delete a memory
69app.delete("/api/memories/:id", async (c) => {
70const id = c.req.param("id");
71try {
83// --- Blob Image Serving Routes ---
8485// GET /api/images/:filename - Serve images from blob storage
86app.get("/api/images/:filename", async (c) => {
87const filename = c.req.param("filename");
88
blob_adminmain.tsx25 matches
73const menuRef = useRef(null);
74const isPublic = blob.key.startsWith("__public/");
75const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
7677useEffect(() => {
237setLoading(true);
238try {
239const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
240const data = await response.json();
241setBlobs(data);
264setBlobContentLoading(true);
265try {
266const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
267const content = await response.text();
268setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
278const handleSave = async () => {
279try {
280await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
281method: "PUT",
282body: editContent,
290const handleDelete = async (key) => {
291try {
292await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
293setBlobs(blobs.filter(b => b.key !== key));
294if (selectedBlob && selectedBlob.key === key) {
307const key = `${searchPrefix}${file.name}`;
308formData.append("key", encodeKey(key));
309await fetch("/api/blob", { method: "POST", body: formData });
310const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
311setBlobs([newBlob, ...blobs]);
329try {
330const fullKey = `${searchPrefix}${key}`;
331await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
332method: "PUT",
333body: "",
344const handleDownload = async (key) => {
345try {
346const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
347const blob = await response.blob();
348const url = window.URL.createObjectURL(blob);
363if (newKey && newKey !== oldKey) {
364try {
365const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
366const content = await response.blob();
367await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
368method: "PUT",
369body: content,
370});
371await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
372setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
373if (selectedBlob && selectedBlob.key === oldKey) {
383const newKey = `__public/${key}`;
384try {
385const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
386const content = await response.blob();
387await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
388method: "PUT",
389body: content,
390});
391await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
392setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
393if (selectedBlob && selectedBlob.key === key) {
402const newKey = key.slice(9); // Remove "__public/" prefix
403try {
404const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
405const content = await response.blob();
406await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
407method: "PUT",
408body: content,
409});
410await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
411setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
412if (selectedBlob && selectedBlob.key === key) {
557onClick={() =>
558copyToClipboard(
559`${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
560)}
561className="text-blue-400 hover:text-blue-300 text-sm"
580>
581<img
582src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
583alt="Blob content"
584className="max-w-full h-auto"
660661// Public route without authentication
662app.get("/api/public/:id", async (c) => {
663const key = `__public/${c.req.param("id")}`;
664const { blob } = await import("https://esm.town/v/std/blob");
778};
779780app.get("/api/blobs", checkAuth, async (c) => {
781const prefix = c.req.query("prefix") || "";
782const limit = parseInt(c.req.query("limit") || "20", 10);
787});
788789app.get("/api/blob", checkAuth, async (c) => {
790const key = c.req.query("key");
791if (!key) return c.text("Missing key parameter", 400);
795});
796797app.put("/api/blob", checkAuth, async (c) => {
798const key = c.req.query("key");
799if (!key) return c.text("Missing key parameter", 400);
804});
805806app.delete("/api/blob", checkAuth, async (c) => {
807const key = c.req.query("key");
808if (!key) return c.text("Missing key parameter", 400);
812});
813814app.post("/api/blob", checkAuth, async (c) => {
815const { file, key } = await c.req.parseBody();
816if (!file || !key) return c.text("Missing file or key", 400);
8## Hono
910This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
1112## Serving assets to the frontend
20### `index.html`
2122The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
2324We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
2526## CRUD API Routes
2728This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
2930## Errors
3132Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.
reactHonoExampleREADME.md5 matches
8## Hono
910This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
1112## Serving assets to the frontend
20### `index.html`
2122The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
2324We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
2526## CRUD API Routes
2728This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
2930## Errors
3132Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.