mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
16 lines
569 B
JavaScript
16 lines
569 B
JavaScript
import { chunk, flatten } from '../../utils'
|
|
import { getAuth } from './auth'
|
|
|
|
export const getComments = commentIDs => (
|
|
getAuth()
|
|
.then(auth => (
|
|
Promise.all(chunk(commentIDs, 100).map(ids => fetchComments(ids, auth))).then(flatten)
|
|
))
|
|
)
|
|
|
|
export const fetchComments = (commentIDs, auth) => (
|
|
fetch(`https://oauth.reddit.com/api/info?id=${commentIDs.map(id => `t1_${id}`).join()}`, auth)
|
|
.then(response => response.json())
|
|
.then(results => results.data.children)
|
|
.then(commentsData => commentsData.map(commentData => commentData.data))
|
|
)
|