1import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
2
3export async function handler(request: Request) {
4 let url = "https://www.capfriendly.com/";
5 let res = await fetch(url);
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
35- [x] add export to CSV, and JSON (CSV and JSON helper functions written in [this val](https://www.val.town/v/nbbaier/sqliteExportHelpers). Thanks to @pomdtr for merging the initial version!)
36- [x] add listener for cmd+enter to submit query
11};
12
13async function createSessionTable(tableName: string) {
14 await sqlite.execute(`CREATE TABLE ${tableName} (
15 id TEXT NOT NULL PRIMARY KEY,
19}
20
21async function createSession(tableName: string, valSlug: string): Promise<Session> {
22 try {
23 const expires_at = new Date();
39}
40
41async function getSession(tableName: string, sessionID: string, valSlug: string): Promise<Session> {
42 try {
43 const { rows, columns } = await sqlite.execute({
60}
61
62async function fetchUser(token: string): Promise<{ id: string }> {
63 const resp = await fetch("https://api.val.town/v1/me", {
64 headers: {
74}
75
76async function verifyApiToken(token: string) {
77 try {
78 const [currentUser, requestUser] = await Promise.all([fetchUser(Deno.env.get("valtown")), fetchUser(token)]);
106</html>`;
107
108export function redirect(location: string): Response {
109 return new Response(null, {
110 headers: {
124const cookieName = "auth_session";
125
126export function passwordAuth(next, options?: PasswordAuthOptions) {
127 let passwords: string[];
128 if (!options?.password) {
37// });
38
39function parseResultSet<T>(row: ResultSet): T[] {
40 return row.rows.map((r) => Object.fromEntries(r.map((c, i) => [row.columns[i], c]))) as T[];
41}
51};
52
53function diffCircles(array1: Circle[], array2: Circle[]): Circle[] {
54 const changes: Circle[] = [];
55
74
75 const drag = (() => {
76 function dragstarted() {
77 d3.select(this).attr("stroke", "black");
78 }
79
80 function dragged(event, d) {
81 d3.select(this).raise().attr("cx", d.x = event.x).attr("cy", d.y = event.y);
82 }
83
84 function dragended() {
85 const x = d3.select(this).attr("cx");
86 const y = d3.select(this).attr("cy");
105 .call(drag)
106 .on("click", clicked);
107 function clicked(event, d) {
108 if (event.defaultPrevented) return; // dragged
109
1export default async function(req: Request): Promise<Response> {
2 if (req.method !== "POST") {
3 return new Response("Method not allowed", { status: 405 });
27const openai = new OpenAI();
28
29export async function twitterAlert({ lastRunAt }: Interval) {
30 let results = [];
31 for (const username of usernames) {
36 }
37
38 async function filterTweets(tweets) {
39 const completion = await openai.chat.completions.create({
40 messages: [
34});
35
36export function App() {
37 const example = examples[Math.floor(Math.random() * examples.length)];
38 const description = /* c.req.query("description") || */ example.user;
92 user: "website that shows the current time",
93 content: `/** @jsxImportSource npm:react */
94export default function() {
95 return <h1>{new Date().toLocaleTimeString()}</h1>;
96}`,
108];
109
110export async function compile(description: string) {
111 const messages = [
112 {
1export default async function(req: Request) {
2 const body = (await fetch("https://live.staticflickr.com/65535/53782948438_9b85e57a6c_o_d.png")).body
3 return new Response(body, {headers: {"Content-Type": "image/png"}});
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(
6);
7
8export async function uptimeCheck(url: string) {
9 let ok = true;
10 let reason: string;
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
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": "*",