an example CDN for atproto
Any image on the ATmosphere can be referenced using its DID and CID. Therefore, making an image CDN for any image on the network is extremely easy. This repo is an example using Cloudflare Images.
Simply visit https://atproto.pictures/img/<DID>/<CID>
to get the image. The image will be fetched from the ATmosphere and transformed/cached by Cloudflare.
- Cache the PDS resolution. Use Worker KV or something.
- Adjust the quality settings. This example is ultra compressed, for a laugh. Also costs. But mostly laughs.
- Verify the CID. In a production setting, you will want to verify that the blob that the PDS returns actually matches the CID - theoretically, it might not! The simplest way to do this is to load the blob into memory and hash it, and make sure it matches. Cache this heavily!