31
32 // Load tasks
33 const tasksResponse = await fetch('/api/tasks', { headers });
34 if (tasksResponse.ok) {
35 const tasksData = await tasksResponse.json();
38
39 // Load transactions
40 const transactionsResponse = await fetch('/api/payments/transactions', { headers });
41 if (transactionsResponse.ok) {
42 const transactionsData = await transactionsResponse.json();
45
46 // Load today's summary
47 const summaryResponse = await fetch('/api/tasks/today-summary', { headers });
48 if (summaryResponse.ok) {
49 const summaryData = await summaryResponse.json();
74 try {
75 const token = localStorage.getItem('authToken');
76 const response = await fetch('/api/tasks/complete', {
77 method: 'POST',
78 headers: {
49 if (isAdminLogin) {
50 // Admin login
51 const response = await fetch('/api/admin/login', {
52 method: 'POST',
53 headers: { 'Content-Type': 'application/json' },
67 } else if (isLogin) {
68 // User login
69 const response = await fetch('/api/auth/login', {
70 method: 'POST',
71 headers: { 'Content-Type': 'application/json' },
85 } else {
86 // User registration
87 const response = await fetch('/api/auth/register', {
88 method: 'POST',
89 headers: { 'Content-Type': 'application/json' },
31 if (adminToken) {
32 // Check admin token validity
33 const response = await fetch('/api/admin/dashboard', {
34 headers: {
35 'Authorization': `Bearer ${adminToken}`
47 if (token) {
48 // Verify user token
49 const response = await fetch('/api/auth/verify', {
50 method: 'POST',
51 headers: {
17await runMigrations();
18
19// API Routes
20app.route('/api/auth', auth);
21app.route('/api/tasks', tasks);
22app.route('/api/payments', payments);
23app.route('/api/admin', admin);
24
25// Serve static files
50 status: 'ok',
51 timestamp: new Date().toISOString(),
52 message: 'EarnBD API is running'
53 });
54});
78
79const getRandomVerse = async () => {
80 const ESV_API_TOKEN = Deno.env.get("ESV_API_TOKEN");
81 const reference = getRandomVerseReference();
82 const params = new URLSearchParams({
93 "indent-psalm-doxology": "0"
94 });
95 const url = `https://api.esv.org/v3/passage/text/?${params.toString()}`;
96 const resp = await fetch(url, {
97 headers: {
98 Authorization: `Token ${ESV_API_TOKEN}`,
99 },
100 });
73The Val.town migration maintains the same core functionality while modernizing the implementation to use Deno and Val.town's HTTP handler format.
74
75### API Usage
76
77```
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]);
18 finish_reason?: string;
19 num_images?: number;
20 our_api_token: boolean;
21}
22
1import { useState, useEffect } from "react";
2
3const USER_ENDPOINT = "/api/user";
4
5export function useUser() {
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