Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save danielberndt/eb59230c4ac5c2fd7edaa27dfb2b2e89 to your computer and use it in GitHub Desktop.

Select an option

Save danielberndt/eb59230c4ac5c2fd7edaa27dfb2b2e89 to your computer and use it in GitHub Desktop.
Codecks Gists
let subdomain = YOUR_SUBDOMAIN
let deckNumber = TAKE_NUMBER_FROM_URL
let cardQuery = `cards({"deck":{"accountSeq":${deckNumber}},"coverFileId":null})`
let query = {_root: [{account: [{[cardQuery]: [{attachments:[{file:["id","meta"]}]}]}]}]}
let result = await fetch(`https://api.codecks.io?query=${JSON.stringify(query)}&x-account=${subdomain}`).then(r => r.json())
for (let cardId of result.account[result._root.account][cardQuery]) {
let card = result.card[cardId]
if (!card.attachments.length) continue;
let files = card.attachments.map(a => result.file[result.attachment[a].file])
let img = files.find(f => f.meta.type)
if (!img) continue
await fetch(`https://api.codecks.io/dispatch/cards/update?x-account=${subdomain}`, {
headers: {"content-type": "application/json"},
body: JSON.stringify({id: cardId, coverFileId: img.id}),
method: "POST",
});
await new Promise(r => setTimeout(r, 100))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment