108// });
109
110// export default app.fetch;
111export default () => Response.json("Broken import, sad");
44 }
45
46 const postHtml = await fetch(`https://www.instagram.com/p/${id}/`).then((
47 response,
48 ) => response.text());
55
56 return {
57 imageUrl: await fetch(`https://www.instagram.com/p/${id}/media/?size=l`, {
58 headers: {
59 "Accept":
66 "Host": "www.instagram.com",
67 "Priority": "u=0, i",
68 "Sec-Fetch-Dest": "document",
69 "Sec-Fetch-Mode": "navigate",
70 "Sec-Fetch-Site": "none",
71 "Sec-Fetch-User": "?1",
72 "TE": "trailers",
73 "Upgrade-Insecure-Requests": "1",
39 if (c.req.query("proxyImage") === "true") {
40 try {
41 const imageResponse = await fetch(imageUrl);
42 if (!imageResponse.ok) {
43 throw new Error(`Failed to fetch image: ${imageResponse.status}`);
44 }
45
50 headers: { "Content-Type": contentType },
51 });
52 } catch (fetchError) {
53 if (fetchError instanceof Error) {
54 return c.json({
55 error: "Failed to proxy image: " + fetchError.message,
56 }, 502);
57 }
106 if (c.req.query("proxyImage") === "true") {
107 try {
108 const imageResponse = await fetch(imageUrl);
109 if (!imageResponse.ok) {
110 throw new Error(`Failed to fetch image: ${imageResponse.status}`);
111 }
112
117 headers: { "Content-Type": contentType },
118 });
119 } catch (fetchError) {
120 if (fetchError instanceof Error) {
121 return c.json({
122 error: "Failed to proxy image: " + fetchError.message,
123 }, 502);
124 }
151});
152
153export default app.fetch;
154
12
131. Enter an Instagram post URL in the input field
142. The application will fetch the image and caption
153. Copy the text with attribution using the "Copy Text" button
164. Save the image (on mobile tap and hold)
12 useEffect(() => {
13 if (url) {
14 fetch(`/extract?url=${encodeURIComponent(url)}`)
15 .then((response) => response.json())
16 .then((data) => {
20 })
21 .catch((error) => {
22 console.error("Error fetching data:", error);
23 setResultText("Error fetching data");
24 setResultImage("");
25 });
1# Bing Image of the Day Archive
2
3This Val Town project fetches, displays, and archives the Bing Image of the Day, providing an API to access both current and historical images.
4
5## Overview
6
7- Fetch the current Bing Image of the Day
8- Archive images to Val Town blob storage with date-based naming
9- List all archived images with their dates
1/**
2 * Helper function to fetch the Bing Image of the Day
3
4 * @returns Promise containing the image response
5 */
6export async function fetchBingImage(): Promise<Response> {
7 try {
8 // Fetch the HTML page
9 const pageResponse = await fetch("https://bing.gifposter.com");
10 const html = await pageResponse.text();
11
17 const imageUrl = match[1].replace("_mb", "");
18
19 // Fetch the actual image
20 const imageResponse = await fetch(imageUrl);
21
22 if (!imageResponse.ok) {
23 throw new Error(`Failed to fetch image: ${imageResponse.status}`);
24 }
25
35 } catch (error) {
36 console.error("Error:", error);
37 return new Response(`Error fetching image: ${error.message}`, {
38 status: 500,
39 headers: { "Content-Type": "text/plain" },
1import { blob } from "https://esm.town/v/std/blob";
2import { fetchBingImage } from "./fetchBingImage.tsx";
3
4/**
7export async function backupBingImage(): Promise<void> {
8 try {
9 // Fetch the Bing image of the day using our helper
10 const response = await fetchBingImage();
11
12 if (!response.ok) {
26 console.log(`Bing image of the day saved: ${filename}`);
27 } catch (error) {
28 console.error("Failed to fetch or save Bing image:", error);
29 }
30}
15
16 // Exchange code for tokens
17 const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
18 method: "POST",
19 headers: { "Content-Type": "application/x-www-form-urlencoded" },
29 const { access_token, id_token } = await tokenResponse.json();
30
31 // Fetch user info
32 const userInfoResponse = await fetch("https://www.googleapis.com/oauth2/v3/userinfo", {
33 headers: { Authorization: `Bearer ${access_token}` },
34 });
41});
42
43export default app.fetch;