stevensDemoApp.tsx17 matches
82const [cookieAndTeaMode, setCookieAndTeaMode] = useState(false);
8384// Fetch images from backend instead of blob storage directly
85useEffect(() => {
86// Set default background color in case image doesn't load
89}
9091// Fetch avatar image
92fetch("/api/images/stevens.jpg")
93.then((response) => {
94if (response.ok) return response.blob();
103});
104105// Fetch wood background
106fetch("/api/images/wood.jpg")
107.then((response) => {
108if (response.ok) return response.blob();
129}, []);
130131const fetchMemories = useCallback(async () => {
132setLoading(true);
133setError(null);
134try {
135const response = await fetch(API_BASE);
136if (!response.ok) {
137throw new Error(`HTTP error! status: ${response.status}`);
154}
155} catch (e) {
156console.error("Failed to fetch memories:", e);
157setError(e.message || "Failed to fetch memories.");
158} finally {
159setLoading(false);
162163useEffect(() => {
164fetchMemories();
165}, [fetchMemories]);
166167const handleAddMemory = async (e: React.FormEvent) => {
176177try {
178const response = await fetch(API_BASE, {
179method: "POST",
180headers: { "Content-Type": "application/json" },
188setNewMemoryTags("");
189setShowAddForm(false);
190await fetchMemories();
191} catch (e) {
192console.error("Failed to add memory:", e);
199200try {
201const response = await fetch(`${API_BASE}/${id}`, {
202method: "DELETE",
203});
205throw new Error(`HTTP error! status: ${response.status}`);
206}
207await fetchMemories();
208} catch (e) {
209console.error("Failed to delete memory:", e);
231232try {
233const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
234method: "PUT",
235headers: { "Content-Type": "application/json" },
240}
241setEditingMemory(null);
242await fetchMemories();
243} catch (e) {
244console.error("Failed to update memory:", e);
HtmlSpecialCharsDemoindex.ts1 match
15app.get("/frontend/**/*", c => serveFile(c.req.path, import.meta.url));
1617export default app.fetch;
HtmlSpecialCharsDemoApp.tsx1 match
67useEffect(() => {
8fetch("https://htmlspecialcharsdemo.val.run/api/data")
9.then(resp => resp.text())
10.then(text => setData(text));
1export default async function(req: Request): Promise<Response> {
2const url = new URL(req.url);
3return fetch(new URL(url.pathname + url.search, "https://charmaine--6a875a3820ff11f0b157569c3dd06744.web.val.run"), {
4method: req.method,
5headers: req.headers,
28const projectUrl = `https://www.val.town/x/${username}/${projectName}`;
2930// First, get the project ID by fetching the project details
31let projectId;
32let endpointUrl: string | undefined; // Initialize as undefined, explicitly type
33try {
34const projectResponse = await fetch(`https://api.val.town/v1/alias/projects/${username}/${projectName}`, {
35headers: {
36"Authorization": `Bearer ${apiKey}`,
49}
5051// Fetch the project files to get the endpoint URL
52const filesResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files?path=`, {
53headers: {
54"Authorization": `Bearer ${apiKey}`,
5758if (!filesResponse.ok) {
59// Still throw if fetching files fails
60throw new Error(`Failed to get project files: ${filesResponse.status}`);
61}
73}
74} catch (error) {
75// Catch errors from fetching project details or files (but not the missing endpoint specifically)
76console.error("Error getting project details or files:", error);
77// Rethrow because fetching project details is critical for proceeding
78throw new Error(`Error preparing project details: ${error.message}`);
79}
97try {
98// First, get the val ID
99const valResponse = await fetch(`https://api.val.town/v1/alias/${valOwner}/${valName}`, {
100headers: {
101"Authorization": `Bearer ${apiKey}`,
104105if (!valResponse.ok) {
106throw new Error(`Failed to fetch val details: ${valResponse.status}`);
107}
108122const redirectCode = `export default async function(req: Request): Promise<Response> {
123const url = new URL(req.url);
124return fetch(new URL(url.pathname + url.search, "${endpointUrl}"), {
125method: req.method,
126headers: req.headers,
148console.log(`Version update body for ${valOwner}/${valName}:`, JSON.stringify(versionUpdateBody).substring(0, 200) + "...");
149150const versionUpdateResponse = await fetch(versionUpdateUrl, {
151method: "POST",
152headers: {
174};
175176const readmeUpdateResponse = await fetch(readmeUpdateUrl, {
177method: "PUT", // Use PUT as documented for updating val properties
178headers: {
3// Define an intermediate type for the processing array
4interface ProcessingValInfo extends ValInfo {
5val?: any; // Store the fetched val data here
6success: boolean;
7error?: string;
34// Use existing project
35projectId = existingProjectId;
36// Fetch existing project details to get name and author
37const projectDetailsResponse = await fetch(`https://api.val.town/v1/projects/${projectId}`, {
38headers: { "Authorization": `Bearer ${apiKey}` },
39});
40if (!projectDetailsResponse.ok) {
41const errorText = await projectDetailsResponse.text();
42throw new Error(`Failed to fetch existing project details: ${errorText}`);
43}
44const projectDetails = await projectDetailsResponse.json();
6768// Create the new project
69const projectResponse = await fetch("https://api.val.town/v1/projects", {
70method: "POST",
71headers: {
100const convertedVals: ProcessingValInfo[] = []; // Use the defined type here
101102// First pass: fetch all vals and track them
103for (const valInfo of vals) {
104try {
105// Fetch the val details
106const valResponse = await fetch(`https://api.val.town/v1/alias/${valInfo.username}/${valInfo.valName}`, {
107headers: { "Authorization": `Bearer ${apiKey}` },
108});
115valName: valInfo.valName,
116success: false,
117error: `Failed to fetch val: ${errorText}`,
118});
119continue;
131username: valInfo.username,
132valName: valInfo.valName,
133val: val, // Store the fetched val
134success: true,
135});
155156// Add the file to the project (use the determined projectId)
157const fileResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files?path=${filePath}`, {
158method: "POST",
159headers: {
188// Generate and add README.md
189const readmeContent = generateReadme(finalProjectName, vals, convertedVals);
190await fetch(`https://api.val.town/v1/projects/${projectId}/files/README.md`, {
191method: "POST",
192headers: {
32let func = `(async () => {
33try {
34await fetch(import.meta.url, {
35method: "POST",
36headers: {
cerebras_coderindex.ts1 match
181182try {
183const response = await fetch("/", {
184method: "POST",
185body: JSON.stringify({
cerebras_coderindex.ts1 match
181182try {
183const response = await fetch("/", {
184method: "POST",
185body: JSON.stringify({
2829// create http request
30const res = await fetch("https://api.capacities.io/save-to-daily-note", {
31method: "POST",
32headers: {