2018-01-31 04:56:04 +00:00
|
|
|
import { json, toBase10, toBase36, chunk, flatten } 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: {
|
|
|
|
|
id: toBase10(threadID),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2018-02-03 17:19:19 +00:00
|
|
|
fetch(postURL + JSON.stringify(elasticQuery))
|
2018-01-14 19:21:53 +00:00
|
|
|
.then(json)
|
|
|
|
|
.then(jsonData => jsonData.hits.hits[0]._source)
|
2018-02-03 17:19:19 +00:00
|
|
|
.then(post => {
|
|
|
|
|
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-04 02:07:05 +00:00
|
|
|
export const getComments = threadID => {
|
2018-01-14 13:41:00 +00:00
|
|
|
const elasticQuery = {
|
|
|
|
|
query: {
|
2018-02-04 02:07:05 +00:00
|
|
|
match: {
|
|
|
|
|
link_id: toBase10(threadID),
|
2018-01-14 13:41:00 +00:00
|
|
|
},
|
|
|
|
|
},
|
2018-02-04 02:07:05 +00:00
|
|
|
size: 10000,
|
2018-01-31 04:56:04 +00:00
|
|
|
_source: [
|
|
|
|
|
'author', 'body', 'created_utc', 'parent_id', 'score',
|
|
|
|
|
],
|
2018-01-14 13:41:00 +00:00
|
|
|
}
|
2018-01-13 17:20:08 +00:00
|
|
|
|
2018-01-14 13:41:00 +00:00
|
|
|
return (
|
|
|
|
|
fetch(commentURL + JSON.stringify(elasticQuery))
|
|
|
|
|
.then(json)
|
2018-01-31 04:56:04 +00:00
|
|
|
.then(jsonData => jsonData.hits.hits)
|
|
|
|
|
.then(comments => comments.map(comment => {
|
|
|
|
|
comment._source.id = toBase36(comment._id)
|
|
|
|
|
|
2018-02-04 16:44:04 +00:00
|
|
|
// Missing parent id === direct reply to thread
|
2018-01-31 04:56:04 +00:00
|
|
|
if (!comment._source.parent_id) {
|
2018-02-04 16:44:04 +00:00
|
|
|
comment._source.parent_id = threadID
|
|
|
|
|
} else {
|
|
|
|
|
comment._source.parent_id = toBase36(comment._source.parent_id)
|
2018-01-31 04:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return comment._source
|
|
|
|
|
}))
|
2018-01-14 13:41:00 +00:00
|
|
|
)
|
|
|
|
|
}
|