Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=api&page=547&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=api

Returns an array of strings in format "username" or "username/projectName"

Found 25399 results for "api"(7504ms)

pipedream-connectauth.tsx16 matches

@wolf•Updated 2 months ago
5// in-memory cache
6const users = {};
7async function getValTownUser(apiKey: string) {
8 if (users[apiKey]) return users[apiKey];
9 try {
10 const vt = new ValTown({ bearerToken: apiKey });
11 const user = await vt.me.profile.retrieve();
12 users[apiKey] = user;
13 return user;
14 } catch (error) {
20// Helper function to get current user from cookie
21export async function getCurrentUser(c: any) {
22 const apiKey = getCookie(c, "vt_api_key");
23 console.log("Cookie check - API key found:", !!apiKey);
24 if (!apiKey) return null;
25 return getValTownUser(apiKey);
26}
27
31// Login endpoint
32app.post("/login", async (c) => {
33 const { apiKey } = await c.req.json();
34
35 if (!apiKey) {
36 return c.json({ error: "API key is required" }, 400);
37 }
38
39 const result = await validateVeaalTownUser(apiKey);
40
41 if (!result.success) {
42 return c.json({ error: "Invalid Val Town API key" }, 401);
43 }
44
45 // Set secure cookie with API key
46 setCookie(c, "vt_api_key", apiKey, {
47 httpOnly: true,
48 secure: true,
60// Logout endpoint
61app.post("/logout", (c) => {
62 deleteCookie(c, "vt_api_key");
63 return c.json({ success: true });
64});

jaktapp1main.tsx31 matches

@mundal•Updated 2 months ago
201 font-weight: 600;
202 color: #495057;
203 text-transform: capitalize;
204 font-size: 0.9em;
205 }
546
547 <script>
548 const API_BASE = window.location.origin + '/api';
549
550 window.onload = () => {
555 async function refreshStatus() {
556 try {
557 const response = await fetch(API_BASE + '/status');
558 const result = await response.json();
559
570 async function loadStats() {
571 try {
572 const response = await fetch(API_BASE + '/stats');
573 const result = await response.json();
574
625
626 try {
627 const response = await fetch(API_BASE + '/log-observation', {
628 method: 'POST',
629 headers: { 'Content-Type': 'application/json' },
675
676 try {
677 const response = await fetch(API_BASE + '/log-harvest', {
678 method: 'POST',
679 headers: { 'Content-Type': 'application/json' },
759 async function viewStats() {
760 try {
761 const response = await fetch(API_BASE + '/stats');
762 const result = await response.json();
763 showResponse('quick-stats', result, response.ok);
769 async function viewObservations() {
770 try {
771 const response = await fetch(API_BASE + '/observations');
772 const result = await response.json();
773 showResponse('quick-stats', result, response.ok);
779 async function viewHarvests() {
780 try {
781 const response = await fetch(API_BASE + '/harvests');
782 const result = await response.json();
783 showResponse('quick-stats', result, response.ok);
809}
810
811// API endpoint handler
812async function huntingAPI(req: Request, path: string, method: string, corsHeaders: any): Promise<Response> {
813 const url = new URL(req.url);
814
815 // GET /api/status
816 if (method === "GET" && path === "/status") {
817 const status = getAllAreasStatus();
822 }
823
824 // POST /api/log-observation
825 if (method === "POST" && path === "/log-observation") {
826 const body = await req.json();
860 }
861
862 // POST /api/log-harvest
863 if (method === "POST" && path === "/log-harvest") {
864 const body = await req.json();
923 }
924
925 // GET /api/observations
926 if (method === "GET" && path === "/observations") {
927 const area = url.searchParams.get("area");
943 }
944
945 // GET /api/harvests
946 if (method === "GET" && path === "/harvests") {
947 const area = url.searchParams.get("area");
963 }
964
965 // GET /api/stats
966 if (method === "GET" && path === "/stats") {
967 const stats = {
1035 }
1036
1037 // GET /api/ - API documentation
1038 if (method === "GET" && path === "/") {
1039 const docs = {
1040 name: "Hunting Area Management API",
1041 version: "1.0.0",
1042 endpoints: {
1043 "GET /api/status": "Get current quota status for all areas",
1044 "POST /api/log-observation": "Record deer sighting",
1045 "POST /api/log-harvest": "Record deer shot",
1046 "GET /api/observations": "List observations",
1047 "GET /api/harvests": "List harvests",
1048 "GET /api/stats": "Get comprehensive statistics",
1049 },
1050 areas: AREA_NAMES,
1058 }
1059
1060 // 404 for unknown API endpoints
1061 return new Response(
1062 JSON.stringify({
1063 success: false,
1064 error: "API endpoint not found",
1065 }),
1066 { status: 404, headers: { ...corsHeaders, "Content-Type": "application/json" } },
1098 }
1099
1100 // Handle API routes
1101 if (path.startsWith("/api/")) {
1102 const apiPath = path.replace("/api", "");
1103 return await huntingAPI(req, apiPath, method, corsHeaders);
1104 }
1105

getGoogleCalendarEvents1main.tsx2 matches

@thebigmacmurray•Updated 2 months ago
5
6export async function getCalendars(accountId: string) {
7 const calendarAPI = await pipeDreamGoogle("calendar", accountId);
8 const calendars = await calendarAPI.calendarList.list();
9
10 return calendars.data.items;

Townie2index.ts4 matches

@wolf•Updated 2 months ago
44);
45
46// token middleware for API requests
47app.all("/api/*", async (c, next) => {
48 if (c.req.path === "/api/stripe-webhook") {
49 return next();
50 }
58});
59
60app.route("/api", backend);
61
62app.get("/frontend/*", (c) => {

Townie2val-summary.ts3 matches

@wolf•Updated 2 months ago
18 SUM(num_images) as total_images
19 FROM ${USAGE_TABLE}
20 WHERE val_id = ? AND our_api_token = 1
21 GROUP BY val_id
22 `, [valId]);
34 FROM ${INFERENCE_CALLS_TABLE} i
35 JOIN ${USAGE_TABLE} u ON i.usage_id = u.id
36 WHERE u.val_id = ? AND u.our_api_token = 1
37 GROUP BY u.val_id
38 `, [valId]);
41 const requestsResult = await sqlite.execute(`
42 SELECT * FROM ${USAGE_TABLE}
43 WHERE val_id = ? AND our_api_token = 1
44 ORDER BY timestamp DESC
45 `, [valId]);

Townie2val-detail.ts1 match

@wolf•Updated 2 months ago
18 finish_reason?: string;
19 num_images?: number;
20 our_api_token: boolean;
21}
22

Townie2useUser.tsx1 match

@wolf•Updated 2 months ago
1import { useState, useEffect } from "react";
2
3const USER_ENDPOINT = "/api/user";
4
5export function useUser() {

Townie2user-summary.ts2 matches

@wolf•Updated 2 months ago
20 SUM(num_images) as total_images
21 FROM ${USAGE_TABLE}
22 WHERE our_api_token = 1
23 `;
24
41 FROM ${INFERENCE_CALLS_TABLE} i
42 JOIN ${USAGE_TABLE} u ON i.usage_id = u.id
43 WHERE u.our_api_token = 1
44 `;
45

Townie2user-detail.ts2 matches

@wolf•Updated 2 months ago
1import { renderLayout } from "./layout.ts";
2import { formatNumber, formatPrice, formatDate, formatBoolean } from "../utils/formatters.ts";
3import { CreditAddition } from "../api/credit-additions.ts";
4
5interface UserSummaryRow {
33 finish_reason?: string;
34 num_images?: number;
35 our_api_token: boolean;
36}
37

Townie2useProject.tsx2 matches

@wolf•Updated 2 months ago
1import { useState, useEffect } from "react";
2
3const PROJECT_ENDPOINT = "/api/project";
4const FILES_ENDPOINT = "/api/project-files";
5
6export function useProject(projectId: string, branchId?: string) {

PixelPixelApiMonitor1 file match

@selfire1•Updated 1 hour ago
Regularly polls the API and messages on an error.

weatherApp1 file match

@dcm31•Updated 7 hours ago
A simple weather app with dropdown cities using Open-Meteo API
fapian
<("<) <(")> (>")>
Kapil01