12
13 useEffect(() => {
14 fetchMessages();
15 }, []);
16
17 const fetchMessages = async () => {
18 const response = await fetch("/messages");
19 const data = await response.json();
20 setMessages(data);
29 setInput("");
30
31 const response = await fetch("/chat", {
32 method: "POST",
33 headers: { "Content-Type": "application/json" },
71});
72
73export default app.fetch;
35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
39 headers: {
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
54 headers: {
18 setLoading(true);
19 try {
20 const response = await fetch(`/generate?prompt=${encodeURIComponent(prompt)}`, { method: 'POST' });
21 const data = await response.json();
22 setImageUrl(data.imageUrl);
23 // After generating, fetch the updated list of images
24 fetchImages();
25 } catch (error) {
26 console.error("Error generating image:", error);
33 const [selectedImage, setSelectedImage] = useState<GeneratedImage | null>(null);
34
35 const fetchImages = async () => {
36 try {
37 const response = await fetch('/images');
38 const data = await response.json();
39 setImages(data);
40 } catch (error) {
41 console.error("Error fetching images:", error);
42 }
43 };
44
45 React.useEffect(() => {
46 fetchImages();
47 }, []);
48
6
7export default async function(req: Request): Promise<Response> {
8 // ============= Data Fetching =================
9 const today = new Date();
10 const tomorrow = addDays(today, 1);
11 const data = await fetch(
12 `https://api.stage.teamsurfboard.com/api/v1/schedule?start=${today.toISOString()}&end=${tomorrow.toISOString()}`,
13 {
1import { email } from "https://esm.town/v/std/email";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3
4export async function dailyDadJoke() {
5 let { setup, punchline } = await fetchJSON("https://official-joke-api.appspot.com/random_joke");
6 return email({
7 text: punchline,
1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
2import { Readability } from "npm:@mozilla/readability";
3
16
17async function readableHtmlFromUrl(url: URL, options?: RequestInit): Promise<string> {
18 const body = await fetchText(url.toString(), options);
19 return readableHtmlFromText(body);
20}
11
12 const apiUrl = `https://api.github.com/repos/${user}/${repo}/contents`;
13 const response = await fetch(apiUrl);
14 const contents = await response.json();
15
18 fileList = contents.map(file => `<li>${file.name} (${file.type})</li>`).join("");
19 } else {
20 fileList = "<li>Error: Unable to fetch repository contents</li>";
21 }
22
46 <input type="text" id="user" placeholder="GitHub Username">
47 <input type="text" id="repo" placeholder="Repository Name">
48 <button onclick="fetchFiles()">Fetch Files</button>
49 <div id="result"></div>
50
51 <script>
52 async function fetchFiles() {
53 const user = document.getElementById('user').value;
54 const repo = document.getElementById('repo').value;
56 result.innerHTML = 'Loading...';
57
58 const response = await fetch(\`/api/files?user=\${user}&repo=\${repo}\`);
59 const html = await response.text();
60 result.innerHTML = html;
73 userInput.value = '';
74
75 const response = await fetch('/chat', {
76 method: 'POST',
77 headers: { 'Content-Type': 'application/json' },
137
138export default async function server(req: Request): Promise<Response> {
139 return app.fetch(req);
140}
72
73export default {
74 fetch: app.fetch,
75 port: 3000,
76};