4const location = "prospect heights, brooklyn"; // <-- change to place, city, or zip code
5
6export async function aqi(interval: Interval) {
7 const data = await easyAQI({ location });
8 if (!interval.lastRunAt) {
68});
69
70/** Sample Function Listener */
71app.function("sample_step", async ({ client, inputs, fail, logger }) => {
72 try {
73 const { user_id } = inputs;
135})();
136
137export default async function handleGetRequest(): Promise<Response> {
138 const html = `
139 <html>
7}
8
9export function CommitList({ commits }: CommitListProps) {
10 const [expandedCommit, setExpandedCommit] = useState<string | null>(null);
11
13}
14
15export function RepoSelector({
16 owner,
17 repo,
13}
14
15export function UserProfile({ user, onUpdate }: UserProfileProps) {
16 const [username, setUsername] = useState(user.username || "");
17 const [isEditing, setIsEditing] = useState(false);
4import { SESSIONS_TABLE, USER_TABLE } from "./schema.ts";
5
6export function generateSessionToken(): string {
7 const bytes = new Uint8Array(20);
8 crypto.getRandomValues(bytes);
11}
12
13export async function createSession(token: string, userId: number): Promise<Session> {
14 const sessionId = encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
15 const session: Session = {
25}
26
27export async function validateSessionToken(token: string): Promise<SessionValidationResult> {
28 const sessionId = encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
29 const { rows } = await sqlite.execute(
87}
88
89export async function invalidateSession(sessionId: string): Promise<void> {
90 await sqlite.execute(`DELETE FROM ${SESSIONS_TABLE} WHERE id = ?`, [sessionId]);
91}
5export const MAGIC_LINKS_TABLE = "lucia_demo_magic_links_v2";
6
7async function createTables() {
8 await sqlite.execute(`
9 CREATE TABLE IF NOT EXISTS ${USER_TABLE} (
7
8// Hash a token using sha256
9function hashToken(token: string): string {
10 return encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
11}
12
13// Create a magic link token for the given email
14export async function createMagicLinkToken(userEmail: string): Promise<string> {
15 const token = generateSessionToken();
16 const tokenHash = hashToken(token);
27
28// Send a magic link email
29export async function sendMagicLinkEmail(url: string, userEmail: string, token: string): Promise<boolean> {
30 try {
31 const magicLink = `${url}/auth/magic-link/${token}`;
55
56// Validate a magic link token and create a session
57export async function validateMagicLinkToken(token: string): Promise<{ valid: boolean; userId?: number }> {
58 const now = Math.floor(Date.now() / 1000);
59 const tokenHash = hashToken(token);
6}
7
8export function LoginForm({ onError }: LoginFormProps) {
9 const [email, setEmail] = useState("");
10 const [isSubmitting, setIsSubmitting] = useState(false);
16}
17
18export function App({ initialData }: { initialData: InitialData }) {
19 const [user, setUser] = useState<User | null>(initialData.user);
20 const [error, setError] = useState<string | null>(initialData.error);
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": "*",