Created
August 3, 2026 22:24
-
-
Save JanMiksovsky/adcec48c029d0217621da9b7395e2c0f to your computer and use it in GitHub Desktop.
Sketch of Cloudinary async map driver
This file contains hidden or 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
| import assert from "node:assert/strict"; | |
| // Return a map of all images in the Cloudinary account | |
| export default async function (API_KEY, API_SECRET) { | |
| assert.ok(API_KEY && API_SECRET, "Cloudinary credentials missing."); | |
| return { | |
| async get(key) { | |
| return Origami.fetch( | |
| `https://res.cloudinary.com/stephanmax/image/upload/f_avif,w_1000,c_limit/${key}`, | |
| ); | |
| }, | |
| async *keys() { | |
| let finished = false; | |
| let next = ""; | |
| const keys = []; | |
| while (!finished) { | |
| const url = `https://api.cloudinary.com/v1_1/stephanmax/resources/image/upload?next_cursor=${next}`; | |
| console.warn(`Requesting ${url}`); | |
| const response = await fetch(url, { | |
| headers: new Headers({ | |
| Authorization: `Basic ${btoa(`${API_KEY}:${API_SECRET}`)}`, | |
| }), | |
| }); | |
| const json = await response.json(); | |
| for (const image of json.resources) { | |
| keys.push(`${image.public_id}.avif`); | |
| } | |
| finished = !json.next_cursor; | |
| next = json.next_cursor; | |
| } | |
| return keys; | |
| }, | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment