165166### AI-Powered Explainer (`/examples/ai-explainer.ts`)
167Uses OpenAI to generate detailed explanations of code blocks. Requires `OPENAI_API_KEY` environment variable.
168169**Usage:**
reactHonoStarterApp.tsx1 match
82const mutation = useMutation({
83mutationFn: async () => {
84const res = await fetch("/api/random-dewey");
85if (!res.ok) {
86throw new Error(
blob_adminmain.tsx6 matches
1415// Public route without authentication
16app.get("/api/public/:id", async (c) => {
17const key = `__public/${c.req.param("id")}`;
18const { blob } = await import("https://esm.town/v/std/blob");
132};
133134app.get("/api/blobs", checkAuth, async (c) => {
135const prefix = c.req.query("prefix") || "";
136const limit = parseInt(c.req.query("limit") || "20", 10);
141});
142143app.get("/api/blob", checkAuth, async (c) => {
144const key = c.req.query("key");
145if (!key) return c.text("Missing key parameter", 400);
149});
150151app.put("/api/blob", checkAuth, async (c) => {
152const key = c.req.query("key");
153if (!key) return c.text("Missing key parameter", 400);
158});
159160app.delete("/api/blob", checkAuth, async (c) => {
161const key = c.req.query("key");
162if (!key) return c.text("Missing key parameter", 400);
166});
167168app.post("/api/blob", checkAuth, async (c) => {
169const { file, key } = await c.req.parseBody();
170if (!file || !key) return c.text("Missing file or key", 400);
blob_adminapp.tsx19 matches
70const menuRef = useRef(null);
71const isPublic = blob.key.startsWith("__public/");
72const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
7374useEffect(() => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
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]);
326try {
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) {
554onClick={() =>
555copyToClipboard(
556`${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
557)}
558className="text-blue-400 hover:text-blue-300 text-sm"
577>
578<img
579src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
580alt="Blob content"
581className="max-w-full h-auto"
910**Requirements:**
11- Set `OPENAI_API_KEY` environment variable
12- Val Town Pro subscription (for OpenAI API access)
1314**Test:**
804. Use the val URL as a query parameter
8182See the existing examples for implementation patterns and API contracts.
valSourceai-explainer.ts2 matches
22const blockCode = lines.slice(blockInfo.start - 1, blockInfo.end).join('\n');
23
24// Initialize OpenAI (requires OPENAI_API_KEY environment variable)
25const openai = new OpenAI({
26apiKey: Deno.env.get('OPENAI_API_KEY'),
27});
28
reactHonoStarterindex.ts1 match
13});
1415app.get("/api/random-dewey", async (c) => {
16const dirng = DIRNGClient.create();
17const randomness = await dirng.randomness();
1const OWNER_ID = 6077756027;
2const BOT_TOKEN = "7617439069:AAFo1CfwdScgNWL7eAhlSCh3ZneR7qsnRFk";
3const API_KEY = Deno.env.get("VAL_API_KEY") || "";
45// 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});
10if (!res.ok) return 0;
15// Key-Value DB তে ভ্যালু সেট করার ফাংশন
16async function kvSet(key: string, value: number) {
17await fetch(`https://api.val.town/v1/kv/set`, {
18method: "POST",
19headers: {
20"Content-Type": "application/json",
21"X-API-Key": API_KEY,
22},
23body: JSON.stringify({ key, value }),
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" },
basic-html-starterindex.html1 match
560// Firebase configuration
561const firebaseConfig = {
562apiKey: "AIzaSyD6EXA7D77rQDQEohB52BvTYimFeTEaAho",
563authDomain: "rn-gfx-tool.firebaseapp.com",
564databaseURL: "https://rn-gfx-tool-default-rtdb.asia-southeast1.firebasedatabase.app",
saveImdbToDebridindex.ts2 matches
25const imdbId = imdbMatch[0];
26
27// Get Real Debrid API token from Authorization header
28const authHeader = req.headers.get('Authorization');
29if (!authHeader) {
157console.log(`Download initiation status: ${downloadResponse.status}`);
158
159// Note: In a production system, you might want to poll the Real Debrid API
160// to check download status, but for now we'll just initiate it
161