2018-07-14 23:13:31 +00:00
|
|
|
import { toBase10, toBase36 } from 'utils'
|
2018-01-14 13:41:00 +00:00
|
|
|
|
2018-01-13 17:20:08 +00:00
|
|
|
const baseURL = 'https://elastic.pushshift.io'
|
2018-02-03 17:19:19 +00:00
|
|
|
const postURL = `${baseURL}/rs/submissions/_search?source=`
|
2018-01-14 13:41:00 +00:00
|
|
|
const commentURL = `${baseURL}/rc/comments/_search?source=`
|
2018-01-13 17:20:08 +00:00
|
|
|
|
2018-02-03 17:19:19 +00:00
|
|
|
export const getPost = threadID => {
|
2018-01-14 19:21:53 +00:00
|
|
|
const elasticQuery = {
|
|
|
|
|
query: {
|
|
|
|
|
term: {
|
2018-07-14 21:24:23 +00:00
|
|
|
id: toBase10(threadID)
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-14 19:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2018-07-14 21:24:23 +00:00
|
|
|
window.fetch(postURL + JSON.stringify(elasticQuery))
|
2018-07-14 23:13:31 +00:00
|
|
|
.then(response => response.json())
|
|
|
|
|
.then(response => {
|
|
|
|
|
const post = response.hits.hits[0]._source
|
2018-02-03 17:19:19 +00:00
|
|
|
post.id = toBase36(post.id)
|
|
|
|
|
return post
|
2018-01-14 21:25:54 +00:00
|
|
|
})
|
2018-01-14 19:21:53 +00:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 21:51:38 +00:00
|
|
|
// export const getComments = threadID => (
|
|
|
|
|
// fetch(`https://api.pushshift.io/reddit/comment/search?link_id=${threadID}&limit=10000`)
|
|
|
|
|
// .then(json)
|
|
|
|
|
// .then(data => data.data)
|
|
|
|
|
// .then(comments => {
|
|
|
|
|
// comments.forEach(comment => {
|
|
|
|
|
// comment.link_id = comment.link_id.split('_')[1]
|
|
|
|
|
// comment.parent_id = comment.parent_id.split('_')[1]
|
|
|
|
|
// })
|
|
|
|
|
// return comments
|
|
|
|
|
// })
|
|
|
|
|
// )
|
2018-02-06 03:07:30 +00:00
|
|
|
|
2018-02-17 21:51:38 +00:00
|
|
|
export const getComments = threadID => {
|
|
|
|
|
const elasticQuery = {
|
|
|
|
|
query: {
|
|
|
|
|
match: {
|
2018-07-14 21:24:23 +00:00
|
|
|
link_id: toBase10(threadID)
|
|
|
|
|
}
|
2018-02-17 21:51:38 +00:00
|
|
|
},
|
|
|
|
|
size: 10000,
|
|
|
|
|
_source: [
|
2018-07-14 21:24:23 +00:00
|
|
|
'author', 'body', 'created_utc', 'parent_id', 'score', 'subreddit', 'link_id'
|
|
|
|
|
]
|
2018-02-17 21:51:38 +00:00
|
|
|
}
|
2018-02-06 03:07:30 +00:00
|
|
|
|
2018-02-17 21:51:38 +00:00
|
|
|
return (
|
2018-07-14 21:24:23 +00:00
|
|
|
window.fetch(commentURL + JSON.stringify(elasticQuery))
|
2018-07-14 23:13:31 +00:00
|
|
|
.then(response => response.json())
|
|
|
|
|
.then(response => {
|
|
|
|
|
const comments = response.hits.hits
|
|
|
|
|
return comments.map(comment => {
|
|
|
|
|
comment._source.id = toBase36(comment._id)
|
|
|
|
|
comment._source.link_id = toBase36(comment._source.link_id)
|
2018-02-06 03:07:30 +00:00
|
|
|
|
2018-07-14 23:13:31 +00:00
|
|
|
// Missing parent id === direct reply to thread
|
|
|
|
|
if (!comment._source.parent_id) {
|
|
|
|
|
comment._source.parent_id = threadID
|
|
|
|
|
} else {
|
|
|
|
|
comment._source.parent_id = toBase36(comment._source.parent_id)
|
|
|
|
|
}
|
2018-02-06 03:07:30 +00:00
|
|
|
|
2018-07-14 23:13:31 +00:00
|
|
|
return comment._source
|
|
|
|
|
})
|
|
|
|
|
})
|
2018-02-17 21:51:38 +00:00
|
|
|
)
|
|
|
|
|
}
|