-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Render thumbnails for graphers by uuid (#3880)
This PR duplicates the thumbnail rendering logic into the top level so that we can render pngs at `/grapher/SLUG.png` and svgs at `/grapher/SLUG.svg`. It also adds thumbnail rendering at `/grapher/by-uuid/UUID.png` and `.svg`. The HTML rewriting (of og images) is changed to point to the new `/grapher/SLUG.png` route. The old thumbnail rendering at `/grapher/thumbnail/SLUG` is kept for now so that existing fetches will still work until the various cached versions of the HTML have expired.
- Loading branch information
Showing
8 changed files
with
139 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Env } from "./env.js" | ||
import { | ||
Etag, | ||
GrapherIdentifier, | ||
fetchAndRenderGrapher, | ||
} from "./grapherRenderer.js" | ||
|
||
export async function handleThumbnailRequest( | ||
id: GrapherIdentifier, | ||
searchParams: URLSearchParams, | ||
env: Env, | ||
_etag: Etag, | ||
ctx: EventContext<unknown, any, Record<string, unknown>>, | ||
extension: "png" | "svg" | ||
) { | ||
const url = new URL(env.url) | ||
const shouldCache = !url.searchParams.has("nocache") | ||
|
||
const cache = caches.default | ||
console.log("Handling", env.url, ctx.request.headers.get("User-Agent")) | ||
if (shouldCache) { | ||
console.log("Checking cache") | ||
const maybeCached = await cache.match(ctx.request) | ||
console.log("Cache check result", maybeCached ? "hit" : "miss") | ||
if (maybeCached) return maybeCached | ||
} | ||
const resp = await fetchAndRenderGrapher(id, searchParams, extension, env) | ||
if (shouldCache) { | ||
resp.headers.set("Cache-Control", "public, s-maxage=3600, max-age=3600") | ||
ctx.waitUntil(caches.default.put(ctx.request, resp.clone())) | ||
} else | ||
resp.headers.set( | ||
"Cache-Control", | ||
"public, s-maxage=0, max-age=0, must-revalidate" | ||
) | ||
return resp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters