8
9 const validatePrompt = async () => {
10 const response = await fetch(`/validate?prompt=${encodeURIComponent(prompt)}`);
11 const data = await response.json();
12 setResult(data);
19 setError(null);
20 try {
21 const response = await fetch("/parse", {
22 method: "POST",
23 headers: { "Content-Type": "application/json" },
14
15 try {
16 const response = await fetch("/classify", {
17 method: "POST",
18 headers: { "Content-Type": "application/json" },
52
53 useEffect(() => {
54 // Fetch initial items and global chat messages
55 fetchItems();
56 fetchGlobalChatMessages();
57 }, []);
58
59 async function fetchItems() {
60 try {
61 const response = await fetch("/api/items");
62 const data = await response.json();
63
74 setItems(parsedItems);
75 } catch (error) {
76 console.error("Failed to fetch items", error);
77 setItems([]);
78 }
79 }
80
81 async function fetchGlobalChatMessages() {
82 try {
83 const response = await fetch("/api/global-chat");
84 const messages = await response.json();
85 setGlobalChatMessages(messages);
86 } catch (error) {
87 console.error("Failed to fetch global chat messages", error);
88 setGlobalChatMessages([]);
89 }
92 async function postNewItem(newItem: Omit<Item, "id" | "status">) {
93 try {
94 const response = await fetch("/api/items", {
95 method: "POST",
96 headers: {
120
121 try {
122 const response = await fetch("/api/global-chat", {
123 method: "POST",
124 headers: {
411 });
412 } catch (error) {
413 console.error("Error fetching global chat messages:", error);
414 return new Response(JSON.stringify({ error: "Failed to fetch messages" }), {
415 status: 500,
416 headers: { "Content-Type": "application/json" },
472 });
473 } catch (error) {
474 console.error("Error fetching items:", error);
475 return new Response(JSON.stringify({ error: "Failed to fetch items" }), {
476 status: 500,
477 headers: { "Content-Type": "application/json" },
1import { makeDay } from "https://esm.town/v/joseforonda/digesthelpers";
2import { fetchSources } from "https://esm.town/v/joseforonda/news";
3import { prepareNewsletter } from "https://esm.town/v/joseforonda/newsletter";
4import { email } from "https://esm.town/v/std/email";
31 try {
32 const sinceDate = makeDay(sinceDays);
33 const newsRaw = await fetchSources(sources, descMaxLength, sinceDate);
34 if (newsRaw.length > 0) {
35 const newsletterOutline = await prepareNewsletter(newsRaw, sinceDate, maxGroups);
15 const start = performance.now();
16 try {
17 res = await fetch(url);
18 end = performance.now();
19 status = res.status;
25 } catch (e) {
26 end = performance.now();
27 reason = `couldn't fetch: ${e}`;
28 ok = false;
29 }
19 : Math.floor((Date.now() - 2 * 24 * 60 * 60 * 1000) / 1000);
20
21 // Fetch and log tweets
22 const response = await socialDataSearch(`${query} since_time:${timeFrame}`);
23 console.log("Response from socialDataSearch:", response);
2// const baseUrl = "https://api.neynar.com/v2/farcaster/";
3
4export async function fetchNeynarGet(path: string) {
5 const res = await fetch(baseUrl + encodeURIComponent(path), {
6 method: "GET",
7 headers: {
15}
16
17export async function fetchNeynarGetPages(path: string, pages: number, dataKey: string) {
18 let data: any = [];
19 let cursor = "";
20 let pagesLeft = pages;
21 while (true) {
22 const res = await fetchNeynarGet(`${path}&cursor=${cursor}`);
23 data = [...data, ...res[dataKey]];
24 cursor = res?.next?.cursor;
35//////////
36
37export function fetchUser(username: string) {
38 return fetchNeynarGet(`user/by_username?username=${username}`).then(r => r.user);
39}
40export function fetchUsersById(fids: string) {
41 return fetchNeynarGet(`user/bulk?fids=${fids}`).then(r => r.users);
42}
43
44export function fetchUserFeed(fid: number) {
45 return fetchNeynarGet(
46 `feed?feed_type=filter&filter_type=fids&fids=${fid}&with_recasts=false&with_replies=false&limit=100&cursor=`,
47 ).then(r => r.casts);
48}
49
50export function fetchChannel(channelId: string) {
51 return fetchNeynarGet(`channel?id=${channelId}`).then(r => r.channel);
52}
53
54export function fetchChannelFeed(channelId: string) {
55 return fetchNeynarGet(
56 `feed/channels?channel_ids=${channelId}&with_recasts=false&limit=100`,
57 ).then(r => r.casts);
58}
59
60export function fetchChannelsFeed(channelIds: array) {
61 return fetchNeynarGet(
62 `feed/channels?channel_ids=${channelIds.join(",")}&with_recasts=false&limit=100`,
63 ).then(r => r.casts);
5};
6
7export const fetchGet = async (path: string) => {
8 return await fetch("https://api.neynar.com/v2/farcaster/" + path, {
9 method: "GET",
10 headers: headers,
12};
13
14export const fetchPost = async (path: string, body: any) => {
15 return await fetch("https://api.neynar.com/v2/farcaster/" + path, {
16 method: "POST",
17 headers: headers,
4import { embedMetadata, handleFarcasterEndpoints, iconUrl, name } from "./farcaster.ts";
5import { handleImageEndpoints } from "./image.tsx";
6import { fetchGet as fetchNeynarGet } from "./neynar.ts";
7
8const app = new Hono();
19
20app.get("/api/miniapps", async (c) => {
21 const response = await fetch(`https://client.warpcast.com/v1/top-frameapps?limit=100`).then(r => r.json()).then(r =>
22 r?.result?.frames
23 );
28 const url = new URL(c.req.url);
29 const path = url.searchParams.get("path");
30 const response = await fetchNeynarGet(path).then(r => r.json());
31 return c.json(response);
32});
73});
74
75// HTTP vals expect an exported "fetch handler"
76// This is how you "run the server" in Val Town with Hono
77export default app.fetch;