OpenTownieChat.tsx5 matches
8import { ChatMessages } from "./ChatMessages.tsx";
9import { ChatInput } from "./ChatInput.tsx";
10import { ApiKeyWarning } from "./ApiKeyWarning.tsx";
11import { processFiles } from "./ImageUpload.tsx";
12import { Preview } from "./Preview.tsx";
15project,
16bearerToken,
17anthropicApiKey,
18setProject,
19}: {
20project: any;
21bearerToken: string;
22anthropicApiKey: string;
23setProject: (project: any) => void;
24}) {
57project,
58branchId,
59anthropicApiKey,
60bearerToken,
61selectedFiles,
170171<div className="p-6 flex flex-col h-full w-full">
172<ApiKeyWarning show={!anthropicApiKey} />
173
174<div className="flex flex-col lg:flex-row gap-4">
OpenTownieBranchControl.tsx2 matches
37setIsLoadingBranches(true);
38try {
39const response = await fetch(`/api/project-branches?projectId=${projectId}`, {
40headers: {
41"Authorization": `Bearer ${bearerToken}`,
107const fetchBranches = async () => {
108try {
109const response = await fetch(`/api/project-branches?projectId=${projectId}`, {
110headers: {
111"Authorization": `Bearer ${bearerToken}`,
OpenTownieApp.tsx3 matches
17export function App() {
18const [bearerToken, setBearerToken] = useLocalStorage("bearer", "");
19const [anthropicApiKey, setAnthropicApiKey] = useLocalStorage("anthropic_api_key", "");
20const [projectJSON, setProjectJSON] = useLocalStorage("project", "");
21const [project, setProject_] = useState(safeParse(projectJSON));
30setBearerToken("");
31setShowLogin(false);
32// Keep the anthropic API key in case the user wants to reuse it
33}
3441<Chat
42bearerToken={bearerToken}
43anthropicApiKey={anthropicApiKey}
44project={project}
45setProject={setProject}
OpenTownieapi.ts1 match
3{ bearerToken, projectId, branchId }: { bearerToken: string; projectId: string; branchId?: string },
4) {
5const url = new URL("/api/project-files", window.location.origin);
6url.searchParams.append("projectId", projectId);
7if (branchId) {
OpenTownieApiKeyWarning.tsx4 matches
2import React from "https://esm.sh/react@18.2.0?dev";
34interface ApiKeyWarningProps {
5show: boolean;
6}
78export function ApiKeyWarning({ show }: ApiKeyWarningProps) {
9if (!show) return null;
10
11return (
12<div className="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4 mb-4 rounded">
13<p className="font-bold">Anthropic API Key Missing</p>
14<p>Please log out and add your Anthropic API key to use this app.</p>
15</div>
16);
blob_adminmain.tsx6 matches
1516// Public route without authentication
17app.get("/api/public/:id", async (c) => {
18const key = `__public/${c.req.param("id")}`;
19const { blob } = await import("https://esm.town/v/std/blob");
133};
134135app.get("/api/blobs", checkAuth, async (c) => {
136const prefix = c.req.query("prefix") || "";
137const limit = parseInt(c.req.query("limit") || "20", 10);
142});
143144app.get("/api/blob", checkAuth, async (c) => {
145const key = c.req.query("key");
146if (!key) return c.text("Missing key parameter", 400);
150});
151152app.put("/api/blob", checkAuth, async (c) => {
153const key = c.req.query("key");
154if (!key) return c.text("Missing key parameter", 400);
159});
160161app.delete("/api/blob", checkAuth, async (c) => {
162const key = c.req.query("key");
163if (!key) return c.text("Missing key parameter", 400);
167});
168169app.post("/api/blob", checkAuth, async (c) => {
170const { file, key } = await c.req.parseBody();
171if (!file || !key) return c.text("Missing file or key", 400);
blob_adminapp.tsx19 matches
70const menuRef = useRef(null);
71const isPublic = blob.key.startsWith("__public/");
72const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
7374useEffect(() => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
275const handleSave = async () => {
276try {
277await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278method: "PUT",
279body: editContent,
287const handleDelete = async (key) => {
288try {
289await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290setBlobs(blobs.filter(b => b.key !== key));
291if (selectedBlob && selectedBlob.key === key) {
304const key = `${searchPrefix}${file.name}`;
305formData.append("key", encodeKey(key));
306await fetch("/api/blob", { method: "POST", body: formData });
307const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308setBlobs([newBlob, ...blobs]);
326try {
327const fullKey = `${searchPrefix}${key}`;
328await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329method: "PUT",
330body: "",
341const handleDownload = async (key) => {
342try {
343const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344const blob = await response.blob();
345const url = window.URL.createObjectURL(blob);
360if (newKey && newKey !== oldKey) {
361try {
362const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363const content = await response.blob();
364await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365method: "PUT",
366body: content,
367});
368await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370if (selectedBlob && selectedBlob.key === oldKey) {
380const newKey = `__public/${key}`;
381try {
382const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383const content = await response.blob();
384await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385method: "PUT",
386body: content,
387});
388await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390if (selectedBlob && selectedBlob.key === key) {
399const newKey = key.slice(9); // Remove "__public/" prefix
400try {
401const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402const content = await response.blob();
403await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404method: "PUT",
405body: content,
406});
407await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409if (selectedBlob && selectedBlob.key === key) {
554onClick={() =>
555copyToClipboard(
556`${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
557)}
558className="text-blue-400 hover:text-blue-300 text-sm"
577>
578<img
579src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
580alt="Blob content"
581className="max-w-full h-auto"
23export default async function(interval: Interval) {
4// Use open-meteo for free weather API
5const response = await fetch(
6"https://api.open-meteo.com/v1/forecast?latitude=-1.2921&longitude=36.8219¤t_weather=true&temperature_unit=celsius&windspeed_unit=km/h&precipitation_unit=millimeters&timezone=Africa/Nairobi",
7);
8const weatherData = await response.json();
17Timestamp: ${new Date().toLocaleString("en-US", { timeZone: "Africa/Nairobi" })}
1819Powered by Open-Meteo Weather API
20Source: ${import.meta.url.replace("esm.town", "val.town")}
21`;
scintillatingLimeParakeetmain.tsx5 matches
22useEffect(() => {
23async function fetchFacts() {
24const response = await fetch("/api/facts");
25const data = await response.json();
26setFacts(data);
31useEffect(() => {
32async function fetchDailyFact() {
33const response = await fetch("/api/daily-fact");
34const data = await response.json();
35setDailyFact(data);
143`);
144145// Handle API routes
146const url = new URL(request.url);
147if (url.pathname === "/api/facts") {
148const facts = await sqlite.execute(`
149SELECT * FROM ${KEY}_facts_${SCHEMA_VERSION}
154}
155156if (url.pathname === "/api/daily-fact") {
157const dailyFact = await sqlite.execute(`
158SELECT * FROM ${KEY}_facts_${SCHEMA_VERSION}
trustingYellowChickadeemain.tsx5 matches
22useEffect(() => {
23async function fetchFacts() {
24const response = await fetch("/api/facts");
25const data = await response.json();
26setFacts(data);
31useEffect(() => {
32async function fetchDailyFact() {
33const response = await fetch("/api/daily-fact");
34const data = await response.json();
35setDailyFact(data);
143`);
144145// Handle API routes
146const url = new URL(request.url);
147if (url.pathname === "/api/facts") {
148const facts = await sqlite.execute(`
149SELECT * FROM ${KEY}_facts_${SCHEMA_VERSION}
154}
155156if (url.pathname === "/api/daily-fact") {
157const dailyFact = await sqlite.execute(`
158SELECT * FROM ${KEY}_facts_${SCHEMA_VERSION}