blob_adminmain.tsx1 match
199});
200201export default lastlogin((request: Request) => app.fetch(request));
blob_adminapp.tsx22 matches
231const [isDragging, setIsDragging] = useState(false);
232233const fetchBlobs = useCallback(async () => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
239} catch (error) {
240console.error("Error fetching blobs:", error);
241} finally {
242setLoading(false);
245246useEffect(() => {
247fetchBlobs();
248}, [fetchBlobs]);
249250const handleSearch = (e) => {
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
266setEditContent(content);
267} catch (error) {
268console.error("Error fetching blob content:", error);
269} finally {
270setBlobContentLoading(false);
275const handleSave = async () => {
276try {
277await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278method: "PUT",
279body: editContent,
287const handleDelete = async (key) => {
288try {
289await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290setBlobs(blobs.filter(b => b.key !== key));
291if (selectedBlob && selectedBlob.key === key) {
304const key = `${searchPrefix}${file.name}`;
305formData.append("key", encodeKey(key));
306await fetch("/api/blob", { method: "POST", body: formData });
307const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308setBlobs([newBlob, ...blobs]);
312}
313}
314fetchBlobs();
315};
316326try {
327const fullKey = `${searchPrefix}${key}`;
328await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329method: "PUT",
330body: "",
341const handleDownload = async (key) => {
342try {
343const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344const blob = await response.blob();
345const url = window.URL.createObjectURL(blob);
360if (newKey && newKey !== oldKey) {
361try {
362const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363const content = await response.blob();
364await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365method: "PUT",
366body: content,
367});
368await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370if (selectedBlob && selectedBlob.key === oldKey) {
380const newKey = `__public/${key}`;
381try {
382const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383const content = await response.blob();
384await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385method: "PUT",
386body: content,
387});
388await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390if (selectedBlob && selectedBlob.key === key) {
399const newKey = key.slice(9); // Remove "__public/" prefix
400try {
401const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402const content = await response.blob();
403await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404method: "PUT",
405body: content,
406});
407await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409if (selectedBlob && selectedBlob.key === key) {
1export async function urlGetter(sourceURl) {
2// convert object to array containing arrays with key value pairs. use map to iterate over the values then convert arrays to objects
3const response = await fetch(sourceURl);
4const html = await response.text();
5const matches = [...html.matchAll(/<a[^>]*href="([^"]+)"[^>]*>(.*?)<\/a>/g)].map((match) => match[1]);
25```
2627This will fetch the source from `https://esm.town/v/nbbaier/sqliteExplorerApp@100-main/main.tsx` and display it with annotations.
2829### Custom Functions
1221231. **URL Parsing**: Extracts the val path from the URL
1242. **Source Fetching**: Fetches source code from `https://esm.town/v/{path}`
1253. **Language Detection**: Determines language from file extension
1264. **Syntax Highlighting**: Applies syntax highlighting using Prism.js
141## Error Handling
142143- Returns 404 if the source URL cannot be fetched
144- Returns 400 for invalid path formats
145- Returns 500 for other errors with error messages
168
169try {
170// Fetch the source code
171const response = await fetch(sourceUrl);
172if (!response.ok) {
173return c.text(`Failed to fetch source: ${response.status}`, 404);
174}
175
380async function detectBlock(code, line, column) {
381if (blockDetectorUrl) {
382const response = await fetch(blockDetectorUrl, {
383method: 'POST',
384headers: { 'Content-Type': 'application/json' },
393async function explainBlock(code, blockInfo) {
394if (blockExplainerUrl) {
395const response = await fetch(blockExplainerUrl, {
396method: 'POST',
397headers: { 'Content-Type': 'application/json' },
538}
539540export default app.fetch;
reactHonoStarterApp.tsx2 matches
53mutationFn: async () => {
54// Get quantum bytes
55const res = await fetch("/api/random-dewey");
56if (!res.ok) {
57throw new Error(
58"Failed to fetch random numbers. The quantum source might be temporarily unavailable."
59);
60}
reactHonoStarterindex.ts1 match
37});
3839export default app.fetch; // This is the entry point for HTTP vals
40
5// Key-Value DB āĻĨā§āĻā§ āĻā§āϝāĻžāϞ⧠āĻĒāĻžāĻā§āĻžāϰ āĻĢāĻžāĻāĻļāύ
6async function kvGet(key: string): Promise<number> {
7const res = await fetch(`https://api.val.town/v1/kv/get?key=${key}`, {
8headers: { "X-API-Key": API_KEY },
9});
15// Key-Value DB āϤ⧠āĻā§āϝāĻžāϞ⧠āϏā§āĻ āĻāϰāĻžāϰ āĻĢāĻžāĻāĻļāύ
16async function kvSet(key: string, value: number) {
17await fetch(`https://api.val.town/v1/kv/set`, {
18method: "POST",
19headers: {
49// āĻŽā§āϏā§āĻ āĻĒāĻžāĻ āĻžāύā§āϰ āĻĢāĻžāĻāĻļāύ
50async function sendMessage(chat_id: number, text: string, reply_markup: any = null) {
51await fetch(`https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`, {
52method: "POST",
53headers: { "Content-Type": "application/json" },
reactHonoStarterindex.ts2 matches
21});
2223// HTTP vals expect an exported "fetch handler"
24// This is how you "run the server" in Val Town with Hono
25export default app.fetch;
saveImdbToDebridindex.ts7 matches
39: authHeader;
40
41// Fetch streams from Torrentio
42const torrentioUrl = `https://torrentio.strem.fun/realdebrid=${rdToken}/stream/movie/${imdbId}.json`;
43
44console.log(`Fetching streams from: ${torrentioUrl}`);
45
46const torrentioResponse = await fetch(torrentioUrl);
47if (!torrentioResponse.ok) {
48return new Response(`Error: Failed to fetch streams from Torrentio (${torrentioResponse.status}: ${torrentioResponse.statusText})`, {
49status: 500,
50headers: { 'Content-Type': 'text/plain' }
131if (isCached) {
132// Stream is already cached, just make the range request
133const rangeResponse = await fetch(selectedStream.url, {
134headers: {
135'Range': 'bytes=0-0' // Request only the first byte
146
147// First, make a request to initiate the download
148const downloadResponse = await fetch(selectedStream.url, {
149method: 'GET',
150headers: {
162} else {
163// Fallback for streams that don't match our expected patterns
164const rangeResponse = await fetch(selectedStream.url, {
165headers: {
166'Range': 'bytes=0-0'