xkcd/lib/xkcd.js
Henrique Dias cd14e6c2f6 feat: downloading
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
2019-04-28 18:59:07 +01:00

21 lines
434 B
JavaScript

const fetch = require('node-fetch')
async function getLatestId () {
const raw = await fetch(`https://xkcd.com/info.0.json`)
const data = await raw.json()
return data.num
}
async function getComic (id) {
const raw = await fetch(`https://xkcd.com/${id}/info.0.json`)
const data = await raw.json()
const img = await (await fetch(data.img)).buffer()
return { data, img }
}
module.exports = {
getLatestId,
getComic
}