Skip to content

Instantly share code, notes, and snippets.

@rayriffy
Created May 4, 2019 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayriffy/a868f126b88d697cd5c7e7eb7f97cd07 to your computer and use it in GitHub Desktop.
Save rayriffy/a868f126b88d697cd5c7e7eb7f97cd07 to your computer and use it in GitHub Desktop.
/**
* Functions for query data from NHentai API
* @param {int} id Gallery ID
*/
const getRawData = async id => {
try {
// Using reverse proxy server to avoid CORS issue
const out = await axios.get(`https://nh-express-git-master.rayriffy.now.sh/api/gallery/${id}`)
return {
status: 'success',
data: {
id: id,
raw: out.data,
},
}
} catch (err) {
console.log(`cannot process ${id} with code ${err.code}`)
return {
status: 'failure',
data: {
id: id,
},
}
}
}
const queue = new TaskQueue(Promise, MAX_SIMULTANEOUS_DOWNLOADS)
const res = {}
res.tags = result.data.allTagJson
res.data = await Promise.all(
result.data.allDataJson.edges.map(queue.wrap(async edge => await getRawData(edge.node.nh_id))),
)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment