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");
766};
767768app.get("/api/blobs", checkAuth, async (c) => {
769const prefix = c.req.query("prefix") || "";
770const limit = parseInt(c.req.query("limit") || "20", 10);
775});
776777app.get("/api/blob", checkAuth, async (c) => {
778const key = c.req.query("key");
779if (!key) return c.text("Missing key parameter", 400);
783});
784785app.put("/api/blob", checkAuth, async (c) => {
786const key = c.req.query("key");
787if (!key) return c.text("Missing key parameter", 400);
792});
793794app.delete("/api/blob", checkAuth, async (c) => {
795const key = c.req.query("key");
796if (!key) return c.text("Missing key parameter", 400);
800});
801802app.post("/api/blob", checkAuth, async (c) => {
803const { file, key } = await c.req.parseBody();
804if (!file || !key) return c.text("Missing file or key", 400);
1import { api } from "https://esm.town/v/pomdtr/api";
2import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
3import { Marp } from "npm:@marp-team/marp-core";
5export default async function() {
6const { author, name } = extractValInfo(import.meta.url);
7const { readme } = await api(`/v1/alias/${author}/${name}`);
89const marp = new Marp();
22<meta name="viewport" content="width=device-width, initial-scale=1.0">
23<title>DevStats Dashboard</title>
24<link rel="preconnect" href="https://fonts.googleapis.com">
25<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
26<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap" rel="stylesheet">
27<script src="https://cdn.tailwindcss.com"></script>
28<script src="https://esm.town/v/std/catch"></script>
126type Rows = Awaited<ReturnType<typeof getRows>>
127128app.get("/api", async function apiRoute(c) {
129try {
130return c.json(await getRows())
cerebras_coderREADME.md2 matches
451. Sign up for [Cerebras](https://cloud.cerebras.ai/)
62. Get a Cerebras API Key
73. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
89# Todos
cerebras_codermain.tsx1 match
9const STARTER_PROMPTS = [
10"todo list app persisted in local storage",
11"weather app using open-meteo API",
12"interactive markdown editor with live preview",
13"pomodoro timer with sound notifications",
FetchBasicREADME.md1 match
1# Framer Fetch: Basic
23A basic example of an API endpoint to use with Framer Fetch. CORS headers are permissive by default on Val Town, so no need to set them.
2import { Parser } from "npm:xml2js";
34const apiBase = "https://data.rijksmuseum.nl/";
5const resolverBase = "https://id.rijksmuseum.nl/";
618manifest.setMetadata(metadata);
19manifest.setSeeAlso([{
20id: apiBase + id + "?_profile=la-framed",
21type: "Dataset",
22label: { "en": ["Linked Art Framed"] },
5152function getImageInformation(record: any) {
53const imageApiEndpoint = record?.["rdf:RDF"]?.["svcs:Service"]?.[0]?.$?.["rdf:about"];
54if (imageApiEndpoint) {
55return fetch(imageApiEndpoint)
56.then(resp => resp.json())
57.catch((err) => console.log(`Error fetching Image Information from ${imageApiEndpoint}`, err));
58} else return null;
59}
147["Accept", "application/rdf+xml"],
148]);
149const url = new URL(apiBase + id);
150const parser = new Parser();
151return fetch(url, { headers })
8import { Wide } from 'https://esm.town/v/maxm/wide';
910// Use your Val Town API Token to create a session
11const wide = new Wide(await ValSession.new(Deno.env.get("valtown")))
12
1import { ValSession } from "https://esm.town/v/maxm/valSession";
2// import type { TSearchFilter, WideApi } from "https://esm.town/v/maxm/wideApi";
3type WideApi = any;
4type TSearchFilter = any;
5import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
78const { htmlUrl } = extractValInfo(import.meta.url);
9const _client = hc<WideApi>("https://maxm-wideapi.web.val.run/");
1011export class Wide {
14constructor(sessionToken: string) {
15// TODO: can we use a global client?
16this.#client = hc<WideApi>("https://maxm-wideapi.web.val.run/");
17this.#sessionToken = sessionToken;
18}
7576export default async function(req: Request): Promise<Response> {
77// Use your Val Town API Token to create a session
78const wide = new Wide(await ValSession.new(Deno.env.get("valtown")));
79await wide.write([{
98<script>hljs.highlightAll();</script>
99<style>
100@import url('https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght@900&family=Roboto+Mono:wght@400;700&display=swap');
101
102* {
196import { Wide } from 'https://esm.town/v/maxm/wide';
197198// Use your Val Town API Token to create a session
199const wide = new Wide(await ValSession.new(Deno.env.get("valtown")))
200
inspiringLavenderTakinREADME.md2 matches
451. Sign up for [Cerebras](https://cloud.cerebras.ai/)
62. Get a Cerebras API Key
73. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
89# Todos