endpointsget_vals_endpoints.tsx11 matches
1export default async function(req: Request) {
2try {
3const apiKey = Deno.env.get("VALTOWN_API_TOKEN");
45if (!apiKey) {
6return new Response(
7JSON.stringify({ error: "VALTOWN_API_TOKEN not found" }, null, 2),
8{ status: 400, headers: { "Content-Type": "application/json" } },
9);
1112// Get my vals using the authenticated /me/vals endpoint
13const valsResponse = await fetch("https://api.val.town/v2/me/vals", {
14headers: {
15"Authorization": `Bearer ${apiKey}`,
16"Content-Type": "application/json",
17},
20if (!valsResponse.ok) {
21const errorText = await valsResponse.text();
22console.log("API Error response:", errorText);
23throw new Error(
24`Failed to fetch vals: ${valsResponse.status} ${valsResponse.statusText}. Response: ${errorText}`,
42for (const val of vals) {
43try {
44// Use the files API to get the actual file structure
45const filesResponse = await fetch(
46`https://api.val.town/v2/vals/${val.id}/files?path=&recursive=true&limit=100`,
47{
48headers: {
49"Authorization": `Bearer ${apiKey}`,
50"Content-Type": "application/json",
51},
80// First get the file metadata to get the HTTP URL
81const fileContentResponse = await fetch(
82`https://api.val.town/v2/vals/${val.id}/files?path=${encodeURIComponent(endpointsFile.path)}`,
83{
84headers: {
85"Authorization": `Bearer ${apiKey}`,
86"Content-Type": "application/json",
87},
HTTP_examplesREADME.md3 matches
1# Val Town Docs - HTTP Examples
23HTTP triggers let you expose an API or website from your file.
45They are built on the web-standard
6[Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and
7[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects,
8so are compatible with a number of web frameworks like
9[Hono](https://hono.dev/) and [Peko](https://github.com/sejori/peko).
umbrellaRemindermain.tsx1 match
11// Get weather data from Open-Meteo
12const weatherUrl =
13`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&hourly=precipitation_probability&timezone=auto&forecast_days=1`;
14const weatherResponse = await fetch(weatherUrl);
15const weatherData = await weatherResponse.json();
untitled-4124index.html1 match
6<title>DigiLocalsTV News Channel</title>
7<link rel="stylesheet" href="/style.css">
8<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
9<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
10</head>
untitled-1267main.tsx30 matches
8<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
9<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
10<script src="https://apis.google.com/js/api.js"></script>
11<style>
12@media print {
137</div>
138<script>
139// Google Drive API कॉन्फ़िगरेशन
140const CLIENT_ID = '706189550353-bbmvs2tklgqfm2jcanf0aqmrdm6ves5i.apps.googleusercontent.com';
141const API_KEY = 'AIzaSyCPCjta_S_c4FYnnNKaRXWb6eaojXg4fqc';
142const DISCOVERY_DOCS = ['https://www.googleapis.com/discovery/v1/apis/drive/v3/rest'];
143const SCOPES = 'https://www.googleapis.com/auth/drive.file';
144let tokenClient;
145let gapiInited = false;
146let gisInited = false;
147160}
161162// Google API शुरू करें
163function gapiLoaded() {
164gapi.load('client', initializeGapiClient);
165}
166167async function initializeGapiClient() {
168try {
169await gapi.client.init({
170apiKey: API_KEY,
171discoveryDocs: DISCOVERY_DOCS,
172});
173gapiInited = true;
174maybeEnableButtons();
175} catch (error) {
176console.error('GAPI शुरू करने में त्रुटि:', error);
177Swal.fire({
178title: 'त्रुटि',
179text: 'Google API शुरू करने में विफल। कृपया API_KEY और CLIENT_ID जाँचें।',
180icon: 'error',
181confirmButtonText: 'ठीक है'
196197function maybeEnableButtons() {
198if (gapiInited && gisInited) {
199document.getElementById('signInBtn').disabled = false;
200}
218};
219220if (gapi.client.getToken() === null) {
221tokenClient.requestAccessToken({prompt: 'consent'});
222} else {
353// Google Drive पर एक्सेल फाइल अपलोड करें
354async function uploadToGoogleDrive(newSale) {
355if (!gapi.client.getToken()) {
356Swal.fire({
357title: 'त्रुटि',
398let fileId;
399try {
400const searchResponse = await gapi.client.drive.files.list({
401q: "name='zari_sales.xlsx' and trashed=false",
402fields: 'files(id, name)'
432if (fileId) {
433// मौजूदा फाइल अपडेट करें
434response = await fetch(`https://www.googleapis.com/upload/drive/v3/files/${fileId}?uploadType=multipart`, {
435method: 'PATCH',
436headers: new Headers({ 'Authorization': 'Bearer ' + gapi.client.getToken().access_token }),
437body: form
438});
439} else {
440// नई फाइल बनाएँ
441response = await fetch('https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart', {
442method: 'POST',
443headers: new Headers({ 'Authorization': 'Bearer ' + gapi.client.getToken().access_token }),
444body: form
445});
792document.getElementById('clearFilterBtn').addEventListener('click', clearFilters);
793794// Google API और Identity Services लोड करें
795function loadGapiAndGis() {
796const gapiScript = document.createElement('script');
797gapiScript.src = 'https://apis.google.com/js/api.js';
798gapiScript.onload = gapiLoaded;
799document.body.appendChild(gapiScript);
800801const gisScript = document.createElement('script');
805}
806807loadGapiAndGis();
808809// प्रारंभिक डिस्प्ले अपडेट
12app.get("/frontend/**/*", c => serveFile(c.req.path, import.meta.url));
1314// Add your API routes here
15// app.get("/api/data", c => c.json({ hello: "world" }));
1617// Unwrap and rethrow Hono errors as the original error
36}
3738export interface ApiResponse<T = any> {
39success: boolean;
40data?: T;
todo-appTodoList.tsx1 match
179<span className="text-sm text-gray-500">{getCategoryLabel(todo.category)}</span>
180<span className="text-sm">{getPriorityIcon(todo.priority)}</span>
181<span className="text-xs text-gray-500 capitalize">{todo.priority === 'high' ? 'Alta' : todo.priority === 'medium' ? 'Média' : 'Baixa'} prioridade</span>
182{isOverdue(todo.dueDate) && !todo.completed && (
183<span className="text-xs bg-red-100 text-red-700 px-2 py-1 rounded-full">
19```
20├── backend/
21│ ├── index.ts # Servidor Hono com API REST
22│ └── README.md
23├── frontend/
36```
3738## 🚀 API Endpoints
3940- `GET /` - Página inicial (landing page ou app)
41- `GET /api/todos` - Buscar tarefas do usuário
42- `POST /api/todos` - Criar nova tarefa
43- `PUT /api/todos/:id` - Atualizar tarefa
44- `DELETE /api/todos/:id` - Excluir tarefa
4546## 🔧 Tecnologias
3import { blob } from "https://esm.town/v/std/blob";
4import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
5import type { Todo, User, CreateTodoRequest, UpdateTodoRequest, ApiResponse } from "../shared/types.ts";
67const app = new Hono();
69});
7071// API Routes
7273// Get todos for authenticated user
74app.get("/api/todos", async (c) => {
75const email = c.req.header("X-LastLogin-Email");
76
77if (!email) {
78return c.json<ApiResponse>({ success: false, error: "Not authenticated" }, 401);
79}
8081try {
82const userData = await getUserData(email);
83return c.json<ApiResponse<Todo[]>>({ success: true, data: userData.todos });
84} catch (error) {
85return c.json<ApiResponse>({ success: false, error: "Failed to fetch todos" }, 500);
86}
87});
8889// Create new todo
90app.post("/api/todos", async (c) => {
91const email = c.req.header("X-LastLogin-Email");
92
93if (!email) {
94return c.json<ApiResponse>({ success: false, error: "Not authenticated" }, 401);
95}
96114await saveUserData(userData);
115116return c.json<ApiResponse<Todo>>({ success: true, data: newTodo });
117} catch (error) {
118return c.json<ApiResponse>({ success: false, error: "Failed to create todo" }, 500);
119}
120});
121122// Update todo
123app.put("/api/todos/:id", async (c) => {
124const email = c.req.header("X-LastLogin-Email");
125const todoId = c.req.param("id");
126
127if (!email) {
128return c.json<ApiResponse>({ success: false, error: "Not authenticated" }, 401);
129}
130135const todoIndex = userData.todos.findIndex(todo => todo.id === todoId);
136if (todoIndex === -1) {
137return c.json<ApiResponse>({ success: false, error: "Todo not found" }, 404);
138}
139148await saveUserData(userData);
149150return c.json<ApiResponse<Todo>>({ success: true, data: updatedTodo });
151} catch (error) {
152return c.json<ApiResponse>({ success: false, error: "Failed to update todo" }, 500);
153}
154});
155156// Delete todo
157app.delete("/api/todos/:id", async (c) => {
158const email = c.req.header("X-LastLogin-Email");
159const todoId = c.req.param("id");
160
161if (!email) {
162return c.json<ApiResponse>({ success: false, error: "Not authenticated" }, 401);
163}
164168const todoIndex = userData.todos.findIndex(todo => todo.id === todoId);
169if (todoIndex === -1) {
170return c.json<ApiResponse>({ success: false, error: "Todo not found" }, 404);
171}
172174await saveUserData(userData);
175176return c.json<ApiResponse>({ success: true });
177} catch (error) {
178return c.json<ApiResponse>({ success: false, error: "Failed to delete todo" }, 500);
179}
180});