18 event.preventDefault();
19 const text = document.getElementById('text').value;
20 const response = await fetch('/summarize', {
21 method: 'POST',
22 headers: { 'Content-Type': 'application/json' },
18 event.preventDefault();
19 const text = document.getElementById('text').value;
20 const response = await fetch('/generate', {
21 method: 'POST',
22 headers: { 'Content-Type': 'application/json' },
18 event.preventDefault();
19 const text = document.getElementById('text').value;
20 const response = await fetch('/classify', {
21 method: 'POST',
22 headers: { 'Content-Type': 'application/json' },
93 async callHuggingFaceAPI(payload, options) {
94 try {
95 const response = await fetch(`${HUGGING_FACE_API_URL}/${this.model}`, {
96 method: "POST",
97 headers: {
50});
51
52export default app.fetch;
53
1async function fetchUser(token: string): Promise<{ id: string }> {
2 const resp = await fetch("https://api.val.town/v1/me", {
3 headers: {
4 Authorization: `Bearer ${token}`,
7
8 if (resp.status !== 200) {
9 throw new Error("Could not fetch user");
10 }
11
15export async function verifyToken(token: string) {
16 try {
17 const [currentUser, requestUser] = await Promise.all([fetchUser(Deno.env.get("valtown")), fetchUser(token)]);
18 return currentUser.id == requestUser.id;
19 } catch (_) {
110 return comments;
111 } catch (error) {
112 console.error(`Error fetching comments for task ${taskId}:`, error);
113 return [];
114 }
135async function downloadImage(url) {
136 try {
137 const response = await fetch(url, {
138 headers: {
139 Authorization: `Bearer ${TODOIST_API_KEY}`,
322
323 try {
324 const response = await fetch(url, {
325 method: "POST",
326 headers: headers,
349
350 try {
351 const response = await fetch(url, {
352 method: "POST",
353 headers: headers,
373
374 try {
375 const response = await fetch(url, {
376 method: "POST",
377 headers: headers,
403
404 try {
405 const response = await fetch(url, { method: "GET", headers: headers });
406 if (!response.ok) {
407 throw new Error(`HTTP error! status: ${response.status}`);
1import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3import { getDocs } from "https://esm.town/v/stevekrouse/getSqliteDateMeDocs";
4import { thisWebURL } from "https://esm.town/v/stevekrouse/thisWebURL";
40export async function setupDatabase() {
41 await createTable();
42 const docs = await fetchJSON(thisWebURL());
43 return docs.map(args =>
44 sqlite.execute({
10// Generic loader that forwards on requests for that page's JSON data
11function loader({ request }) {
12 return fetch(request, {
13 headers: {
14 "Content-Type": "application/json",
20function action({ request }) {
21 if (request.method === "GET") { throw Error("GET not expected here - something is wrong."); }
22 return fetch(request);
23}
24
14async function reverseGeocodeNominat(lat, lng) {
15 const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}&zoom=13`;
16 const response = await fetch(url);
17 const json = await response.json();
18 return json;