decorator_routermain.tsx4 matches
18}
1920export function get(path: string) {
21return (
22target: (query: Record<string, string>, ctx: Context) => unknown,
37}
3839export function post(path: string) {
40return (target: (body: any, ctx: Context) => unknown, _context: ClassMethodDecoratorContext) => {
41_registered.push({ method: "POST", path });
49}
5051export function all(path: string) {
52return (target: (ctx: Context) => unknown, _context: ClassMethodDecoratorContext) => {
53_registered.push({ method: "*", path });
61}
6263export function use(path: string) {
64return (target: (ctx: Context) => unknown, _context: ClassMethodDecoratorContext) => {
65app.use(path, async (request: Request, { params, next }) => {
1# OpenAI ChatGPT helper function
23This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.
1import type { ChatCompletion, ChatCompletionCreateParamsNonStreaming, Message } from "npm:@types/openai";
23async function getOpenAI() {
4// if you don't have a key, use our std library version
5if (Deno.env.get("OPENAI_API_KEY") === undefined) {
14/**
15* Initiates a chat conversation with OpenAI's GPT model and retrieves the content of the first response.
16* This function can handle both single string inputs and arrays of message objects.
17* It supports various GPT models, allowing for flexibility in choosing the model based on the application's needs.
18*
21* @returns {Promise<string>} A promise that resolves to the content of the first response from the completion.
22*/
23export async function chat(
24input: string | Message[],
25options?: Omit<ChatCompletionCreateParamsNonStreaming, "messages">,
whiteMongoosemain.tsx1 match
2import { renderToString } from "npm:react-dom/server";
34export default async function(req: Request) {
5return new Response(
6renderToString(
markdown_downloadmain.tsx9 matches
15* @returns markdown in string
16*/
17export async function html2markdown(html: string): Promise<string> {
18if (AgentMarkdownImport) {
19// TurndownService doesn't work on cf
32* @returns markdown in string
33*/
34export async function readability2markdown(html: string): Promise<{ title: string; markdown: string }> {
35const doc = await (new DOMParser().parseFromString(html, "text/html"));
3642}
4344function getYoutubeVideoID(url: URL): string | null {
45const regExp = /(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/i;
46const match = url.href.match(regExp);
48}
4950function response(message: string, contentType = "text/markdown"): Response {
51const headers = new Headers();
52headers.set("Access-Control-Allow-Origin", "*");
61}
6263function err(msg: string): Response {
64const errorMessage = JSON.stringify({
65error: {
71}
7273function fudgeURL(url: string) {
74try {
75return new URL(url);
80}
8182function processInput(req: Request) {
83let ret = {
84url: undefined as undefined | URL,
107}
108109export default async function(req: Request): Promise<Response> {
110const action = processInput(req);
111const url = action.url;
181* Simple UI that takes a url
182*/
183export function generate_ui(input_description: string, link: string, link_text: string): string {
184const html = `
185<!DOCTYPE html>
MarkdownCommandmain.tsx1 match
5import { def_from_simple } from "https://raw.githubusercontent.com/curtcox/CommandInterpreter/main/command/ToolsForCommandWriters.ts";
67async function markdown(url: string) {
8const encoded = encodeURIComponent(url);
9const response = await fetch(`https://markdown.download/?url=${encoded}`);
valTownLogotypeReactmain.tsx1 match
2import React from "npm:react";
34export default function ValTownLogo(props: React.SVGProps<SVGSVGElement>) {
5return (
6<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 442 79" {...props}>
valTownSearchmain.tsx1 match
5const githubQuery = (query: string) => encodeURIComponent(`${query} repo:pomdtr/val-town-mirror path:vals/`);
67async function handler(req: Request) {
8const url = new URL(req.url);
9
2import { render } from "npm:preact-render-to-string";
34export default async function(req: Request) {
5return new Response(
6render(
1# Render form and save data
23This val provides a web-based interface for collecting email addresses. It features a dual-functionality approach: when accessed via a web browser using a GET request, it serves an HTML form where users can submit their email address. If the script receives a POST request, it implies that the form has been submitted, and it proceeds to handle the incoming data.
45Fork this val to customize it and use it on your account.