pipedream-connectauth.tsx16 matches
5// in-memory cache
6const users = {};
7async function getValTownUser(apiKey: string) {
8if (users[apiKey]) return users[apiKey];
9try {
10const vt = new ValTown({ bearerToken: apiKey });
11const user = await vt.me.profile.retrieve();
12users[apiKey] = user;
13return user;
14} catch (error) {
20// Helper function to get current user from cookie
21export async function getCurrentUser(c: any) {
22const apiKey = getCookie(c, "vt_api_key");
23console.log("Cookie check - API key found:", !!apiKey);
24if (!apiKey) return null;
25return getValTownUser(apiKey);
26}
2731// Login endpoint
32app.post("/login", async (c) => {
33const { apiKey } = await c.req.json();
3435if (!apiKey) {
36return c.json({ error: "API key is required" }, 400);
37}
3839const result = await validateVeaalTownUser(apiKey);
4041if (!result.success) {
42return c.json({ error: "Invalid Val Town API key" }, 401);
43}
4445// Set secure cookie with API key
46setCookie(c, "vt_api_key", apiKey, {
47httpOnly: true,
48secure: true,
60// Logout endpoint
61app.post("/logout", (c) => {
62deleteCookie(c, "vt_api_key");
63return c.json({ success: true });
64});
201font-weight: 600;
202color: #495057;
203text-transform: capitalize;
204font-size: 0.9em;
205}
546547<script>
548const API_BASE = window.location.origin + '/api';
549550window.onload = () => {
555async function refreshStatus() {
556try {
557const response = await fetch(API_BASE + '/status');
558const result = await response.json();
559
570async function loadStats() {
571try {
572const response = await fetch(API_BASE + '/stats');
573const result = await response.json();
574
625626try {
627const response = await fetch(API_BASE + '/log-observation', {
628method: 'POST',
629headers: { 'Content-Type': 'application/json' },
675676try {
677const response = await fetch(API_BASE + '/log-harvest', {
678method: 'POST',
679headers: { 'Content-Type': 'application/json' },
759async function viewStats() {
760try {
761const response = await fetch(API_BASE + '/stats');
762const result = await response.json();
763showResponse('quick-stats', result, response.ok);
769async function viewObservations() {
770try {
771const response = await fetch(API_BASE + '/observations');
772const result = await response.json();
773showResponse('quick-stats', result, response.ok);
779async function viewHarvests() {
780try {
781const response = await fetch(API_BASE + '/harvests');
782const result = await response.json();
783showResponse('quick-stats', result, response.ok);
809}
810811// API endpoint handler
812async function huntingAPI(req: Request, path: string, method: string, corsHeaders: any): Promise<Response> {
813const url = new URL(req.url);
814815// GET /api/status
816if (method === "GET" && path === "/status") {
817const status = getAllAreasStatus();
822}
823824// POST /api/log-observation
825if (method === "POST" && path === "/log-observation") {
826const body = await req.json();
860}
861862// POST /api/log-harvest
863if (method === "POST" && path === "/log-harvest") {
864const body = await req.json();
923}
924925// GET /api/observations
926if (method === "GET" && path === "/observations") {
927const area = url.searchParams.get("area");
943}
944945// GET /api/harvests
946if (method === "GET" && path === "/harvests") {
947const area = url.searchParams.get("area");
963}
964965// GET /api/stats
966if (method === "GET" && path === "/stats") {
967const stats = {
1035}
10361037// GET /api/ - API documentation
1038if (method === "GET" && path === "/") {
1039const docs = {
1040name: "Hunting Area Management API",
1041version: "1.0.0",
1042endpoints: {
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},
1050areas: AREA_NAMES,
1058}
10591060// 404 for unknown API endpoints
1061return new Response(
1062JSON.stringify({
1063success: false,
1064error: "API endpoint not found",
1065}),
1066{ status: 404, headers: { ...corsHeaders, "Content-Type": "application/json" } },
1098}
10991100// Handle API routes
1101if (path.startsWith("/api/")) {
1102const apiPath = path.replace("/api", "");
1103return await huntingAPI(req, apiPath, method, corsHeaders);
1104}
1105
getGoogleCalendarEvents1main.tsx2 matches
56export async function getCalendars(accountId: string) {
7const calendarAPI = await pipeDreamGoogle("calendar", accountId);
8const calendars = await calendarAPI.calendarList.list();
910return calendars.data.items;
44);
4546// token middleware for API requests
47app.all("/api/*", async (c, next) => {
48if (c.req.path === "/api/stripe-webhook") {
49return next();
50}
58});
5960app.route("/api", backend);
6162app.get("/frontend/*", (c) => {
Townie2val-summary.ts3 matches
18SUM(num_images) as total_images
19FROM ${USAGE_TABLE}
20WHERE val_id = ? AND our_api_token = 1
21GROUP BY val_id
22`, [valId]);
34FROM ${INFERENCE_CALLS_TABLE} i
35JOIN ${USAGE_TABLE} u ON i.usage_id = u.id
36WHERE u.val_id = ? AND u.our_api_token = 1
37GROUP BY u.val_id
38`, [valId]);
41const requestsResult = await sqlite.execute(`
42SELECT * FROM ${USAGE_TABLE}
43WHERE val_id = ? AND our_api_token = 1
44ORDER BY timestamp DESC
45`, [valId]);
Townie2val-detail.ts1 match
18finish_reason?: string;
19num_images?: number;
20our_api_token: boolean;
21}
22
Townie2useUser.tsx1 match
1import { useState, useEffect } from "react";
23const USER_ENDPOINT = "/api/user";
45export function useUser() {
Townie2user-summary.ts2 matches
20SUM(num_images) as total_images
21FROM ${USAGE_TABLE}
22WHERE our_api_token = 1
23`;
24
41FROM ${INFERENCE_CALLS_TABLE} i
42JOIN ${USAGE_TABLE} u ON i.usage_id = u.id
43WHERE u.our_api_token = 1
44`;
45
Townie2user-detail.ts2 matches
1import { renderLayout } from "./layout.ts";
2import { formatNumber, formatPrice, formatDate, formatBoolean } from "../utils/formatters.ts";
3import { CreditAddition } from "../api/credit-additions.ts";
45interface UserSummaryRow {
33finish_reason?: string;
34num_images?: number;
35our_api_token: boolean;
36}
37
Townie2useProject.tsx2 matches
1import { useState, useEffect } from "react";
23const PROJECT_ENDPOINT = "/api/project";
4const FILES_ENDPOINT = "/api/project-files";
56export function useProject(projectId: string, branchId?: string) {