35// Database querying.
36
37function parseResultSet<T>(row: ResultSet): T[] {
38 return row.rows.map((r) => Object.fromEntries(r.map((c, i) => [row.columns[i], c]))) as T[];
39}
67};
68
69// Client side javascript and template functions.
70
71const clientJavascript = async () => {
135 });
136
137 function createHeartBurst(event) {
138 const button = event.currentTarget;
139 const buttonContainer = button.closest(".heart-button-container");
174};
175
176function escapeHTML(html: string): string {
177 const escapeChars: { [char: string]: string } = {
178 "&": "&",
408 let encoder = new TextEncoder();
409
410 function isValidSVG(svgString) {
411 const parser = new DOMParser({
412 errorHandler: {
488
489app.get("/:id/img.svg", async (c) => {
490 function addSVGNamespace(svgString) {
491 if (!/^<\?xml/.test(svgString)) svgString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + svgString;
492 if (!/xmlns="http:\/\/www.w3.org\/2000\/svg"/.test(svgString))
2import { valTownBlogJSON } from "https://esm.town/v/stevekrouse/valTownBlogJSON";
3
4export async function valTownBlogRSS() {
5 const json = await valTownBlogJSON();
6 return new Response(dataToRSS(
133`;
134console.log(EventSource);
135async function* forward(query: QueryRequest, botName: string, accessKey: string) {
136 console.log(query, botName, accessKey);
137 const req = new Request(`https://api.poe.com/bot/${botName}`, {
149}
150
151async function* fetchEventSource(request: Request) {
152 const response = await fetch(request);
153 console.log(response.status, response.statusText);
40 window.location.href = url;
41 });
42 window.onerror = function(message, source, lineno, colno, error) {
43 console.error('An error occurred:', error);
44 errorDiv.textContent = 'An error occurred: ' + message;
83 console.log('Access token received');
84
85 async function fetchPlaylists() {
86 try {
87 const response = await axios.get('https://api.spotify.com/v1/me/playlists', {
111 }
112
113 async function fetchTracks(playlistId, playlistName) {
114 try {
115 const response = await axios.get(\`https://api.spotify.com/v1/playlists/\${playlistId}/tracks\`, {
7}
8
9export default async function handler(req: Request): Promise<Response> {
10 const headers = new Headers({
11 "Access-Control-Allow-Origin": "*",
9});
10
11export default async function(req: Request): Promise<Response> {
12 let currentDate = new Date().toISOString(); // Otherwise, we take the current date
13 await cloudflareR2client.putObject("transcription-" + currentDate + ".json", req.body);
4import axios from "npm:axios";
5
6export default async function main(req: Request): Promise<Response> {
7 const token = Deno.env.get("MASTODON_TOKEN");
8 const instance = "mastodon.social"; // Replace with your Mastodon instance if different
4import axios from "npm:axios";
5
6export default async function main(req: Request): Promise<Response> {
7 const token = Deno.env.get("PINBOARD_TOKEN");
8
3const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
4
5export default async function main(req: Request): Promise<Response> {
6 const url = new URL(req.url);
7 const user1 = url.searchParams.get("user1") || "ejfox";
8 const user2 = url.searchParams.get("user2") || "stevekrouse";
9
10 async function fetchUserActivity(username: string) {
11 const threeMonthsAgo = new Date(Date.now() - 90 * 24 * 60 * 60 * 1000).toISOString();
12 const response = await fetch(
20 }
21
22 function summarizeActivity(data: any[]): string {
23 const summary = [];
24 const repoSet = new Set<string>();
96 });
97 } catch (error) {
98 console.error("Error in main function:", error);
99 return new Response(`Error: ${error.message}. Please check the logs for more details.`, { status: 500 });
100 }
10const OPENAI_API_KEY = "your_openai_api_key"; // Replace with your actual OpenAI API key
11
12export default async function main(req: Request): Promise<Response> {
13 const url = new URL(req.url);
14 const user1 = url.searchParams.get('user1') || 'ejfox';
15 const user2 = url.searchParams.get('user2') || 'octocat';
16
17 async function fetchUserActivity(username: string) {
18 const oneYearAgo = new Date(Date.now() - 365 * 24 * 60 * 60 * 1000).toISOString();
19 const response = await fetch(`https://api.github.com/users/${username}/events?per_page=100&since=${oneYearAgo}`);
31 ]);
32
33 function summarizeActivity(data: any[]) {
34 const repoSet = new Set();
35 const languageSet = new Set();
A helper function to build a file's email
Simple functional CSS library for Val Town
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.