1import { basicAuthMiddleware } from "./auth.ts";
2import { handleApiRequest } from "./api/index.ts";
3import { getRequests } from "./api/requests.ts";
4import { getUserSummary } from "./api/user-summary.ts";
5import { getInferenceCalls } from "./api/inference-calls.ts";
6import { renderDashboard } from "./views/dashboard.ts";
7import { renderRequests } from "./views/requests.ts";
22const path = url.pathname;
2324// Handle API requests
25if (path.startsWith("/api/")) {
26return handleApiRequest(req);
27}
28
45/**
6* Handle API requests
7*/
8export async function handleApiRequest(req: Request): Promise<Response> {
9const url = new URL(req.url);
10const path = url.pathname.replace("/api/", "");
11
12try {
13// Route to the appropriate API handler
14if (path === "requests") {
15const usageId = url.searchParams.get("usage_id");
59}
60} catch (error) {
61console.error("API error:", error);
62return new Response(JSON.stringify({ error: error.message }), {
63status: 500,
42</h2>
43<ol>
44<li>Login with your Val Town API token (with projects:read, projects:write, user:read permissions)</li>
45<li>Select a project to work on</li>
46<li>Chat with Claude about your code</li>
79</div>
80<h3>Cost Tracking</h3>
81<p>See estimated API usage costs for each interaction</p>
82</div>
83</section>
92<ul>
93<li>React frontend with TypeScript</li>
94<li>Hono API server backend</li>
95<li>Web Audio API for sound notifications</li>
96<li>AI SDK for Claude integration</li>
97</ul>
98<p>
99The application proxies requests to the Anthropic API and Val Town API, allowing Claude to view and edit your
100project files directly.
101</p>
social_data_api_projectproxy-api.ts23 matches
1/**
2* SocialData API Proxy for Cloudflare Workers
3* Acts as a backend for the X Search UI, handling API key management,
4* and request forwarding to SocialData API.
5*
6* This proxy runs on Cloudflare Workers and connects to:
7* - Supabase for authentication and user management
8* - Cloudflare D1 for tweet storage
9* - SocialData API for Twitter/X data
10*/
1141try {
42// Supabaseの公開鍵を使ってJWTを検証するのが理想ですが、
43// 簡易的な実装としてSupabase APIを利用して検証します
44const supabaseUrl = env.SUPABASE_URL;
45const supabaseKey = env.SUPABASE_SERVICE_KEY;
50}
5152// Supabase Auth APIを利用してユーザー情報を取得
53const response = await fetch(`${supabaseUrl}/auth/v1/user`, {
54headers: {
55"Authorization": `Bearer ${token}`,
56"apikey": supabaseKey,
57},
58});
69headers: {
70"Authorization": `Bearer ${supabaseKey}`,
71"apikey": supabaseKey,
72},
73});
104105/**
106* Forward request to SocialData API
107* @param {string} query - Search query
108* @param {string} type - Search type (Latest or Top)
113async function forwardToSocialData(query, type, cursor, env) {
114try {
115const apiKey = env.SOCIAL_DATA_API_KEY;
116if (!apiKey) {
117throw new Error("SOCIAL_DATA_API_KEY environment variable not set");
118}
119120const apiUrl = new URL("https://api.socialdata.tools/twitter/search");
121apiUrl.searchParams.set("query", query);
122apiUrl.searchParams.set("type", type || "Latest");
123if (cursor) {
124apiUrl.searchParams.set("cursor", cursor);
125}
126127const response = await fetch(apiUrl.toString(), {
128headers: {
129"Authorization": `Bearer ${apiKey}`,
130"Accept": "application/json",
131},
136try {
137const errorData = await response.json();
138errorText = errorData.message || `API Error: ${response.statusText}`;
139} catch {
140errorText = `API Error: ${response.statusText}`;
141}
142throw new Error(errorText);
167"Content-Type": "application/json",
168"Authorization": `Bearer ${supabaseKey}`,
169"apikey": supabaseKey,
170"Prefer": "return=minimal",
171},
344ctx.waitUntil(incrementSearchCount(authResult.userId, env));
345346// Forward request to SocialData API
347const data = await forwardToSocialData(query, type, cursor, env);
348450JSON.stringify({
451status: "ok",
452message: "SocialData API Proxy is running",
453environment: "Cloudflare Workers",
454}),
ipv4-counterindex.ts2 matches
15await initDatabase();
1617// API endpoint to get visit data
18app.get("/api/visits", async (c) => {
19const visits = await getAllVisits();
20const totalVisits = await getTotalVisits();
226227// Add engagement filters
228// Always use min_ (greater than or equal to) for API filters
229if (likesCount) {
230finalQuery += ` min_faves:${likesCount}`;
236237// Note: Replies count, bookmark count, and views count might not be directly filterable
238// in the Twitter/X API. These may need to be filtered client-side after fetching.
239240return finalQuery.trim();
272maxTweets: parseInt(maxTweets),
273filters: {
274// These filters will be applied client-side if the API doesn't support them directly
275// Always use "greater than or equal to" filtering
276repliesCount: repliesCount
380// Helper to check if a tweet meets the client-side filter criteria
381const meetsCriteria = (tweet) => {
382// Apply any client-side filters here that the API doesn't support
383// Only perform "greater than or equal to" checks
384401}
402403// Apply like count filter if not handled by API
404if (likesCount && tweet.favorite_count !== undefined) {
405if (tweet.favorite_count < parseInt(likesCount)) return false;
406}
407408// Apply retweet count filter if not handled by API
409if (retweetsCount && tweet.retweet_count !== undefined) {
410if (tweet.retweet_count < parseInt(retweetsCount)) return false;
ipv4-counterindex.html1 match
125document.getElementById('refresh-btn').addEventListener('click', async () => {
126try {
127const response = await fetch('/api/visits');
128const data = await response.json();
129updateUI(data);
StarterPackFeedsneynar.ts2 matches
1const baseUrl = '/neynar-proxy?path='
2// const baseUrl = "https://api.neynar.com/v2/farcaster/";
34export async function fetchNeynarGet(path: string) {
8'Content-Type': 'application/json',
9'x-neynar-experimental': 'true',
10'x-api-key': 'NEYNAR_API_DOCS',
11},
12})
StarterPackFeedsApp.tsx3 matches
60<div className="">✷ Farcaster mini app manifest + webhook + embed metadata</div>
61<div className="">✷ Farcaster notifications (storing tokens, sending recurring notifications, ...)</div>
62<div className="">✷ Neynar API integration for Farcaster data</div>
63<div className="">✷ Hosted on Val Town (instant deployments on save)</div>
64<div className="">
7475// function Database() {
76// const queryFn = () => fetch('/api/counter/get').then((r) => r.json())
77// const { data, refetch } = useQuery({ queryKey: ['counter'], queryFn })
78// return (
80// {/* <h2 className="font-semibold">Database Example</h2> */}
81// <div className="">Counter value: {data}</div>
82// <Button variant="outline" onClick={() => fetch('/api/counter/increment').then(refetch)}>
83// Increment
84// </Button>
StarterPackFeedsneynar.ts4 matches
1const NEYNAR_API_KEY = Deno.env.get("NEYNAR_API_KEY") || "NEYNAR_API_DOCS";
2const headers = {
3"Content-Type": "application/json",
4"x-api-key": NEYNAR_API_KEY,
5};
67export const fetchGet = async (path: string) => {
8return await fetch("https://api.neynar.com/v2/farcaster/" + path, {
9method: "GET",
10headers: headers,
1314export const fetchPost = async (path: string, body: any) => {
15return await fetch("https://api.neynar.com/v2/farcaster/" + path, {
16method: "POST",
17headers: headers,