You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.6 KiB
105 lines
2.6 KiB
const express = require('express')
|
|
const app = express();
|
|
const axios = require('axios');
|
|
const querystring = require('querystring');
|
|
|
|
app.get('/', async (req, res)=>{
|
|
|
|
const data = {
|
|
grant_type:'password',
|
|
username:process.env.REDDITUSR,
|
|
password:process.env.REDDITPWD
|
|
}
|
|
const auth = {
|
|
username: process.env.APPID,
|
|
password: process.env.APPSECRET
|
|
}
|
|
let response = await axios({
|
|
url:'https://www.reddit.com/api/v1/access_token',
|
|
method:'post',
|
|
auth:auth,
|
|
data:querystring.stringify(data)
|
|
})
|
|
|
|
const config = {
|
|
headers:{
|
|
Authorization: 'bearer '+response.data.access_token
|
|
}
|
|
}
|
|
response = await axios.get('https://oauth.reddit.com/user/mahuntington/saved?count=100', config)
|
|
|
|
res.render('all.ejs', {
|
|
posts: response.data.data.children.filter(post => post.data.subreddit === 'ProgrammerHumor' && post.data.removed_by_category === null),
|
|
next: response.data.data.after,
|
|
previous:null
|
|
})
|
|
|
|
})
|
|
|
|
app.get('/after/:after', async (req, res)=>{
|
|
const data = {
|
|
grant_type:'password',
|
|
username:process.env.REDDITUSR,
|
|
password:process.env.REDDITPWD
|
|
}
|
|
const auth = {
|
|
username: process.env.APPID,
|
|
password: process.env.APPSECRET
|
|
}
|
|
let response = await axios({
|
|
url:'https://www.reddit.com/api/v1/access_token',
|
|
method:'post',
|
|
auth:auth,
|
|
data:querystring.stringify(data)
|
|
})
|
|
|
|
const config = {
|
|
headers:{
|
|
Authorization: 'bearer '+response.data.access_token
|
|
}
|
|
}
|
|
response = await axios.get('https://oauth.reddit.com/user/mahuntington/saved?count=100&after='+req.params.after, config)
|
|
|
|
res.render('all.ejs', {
|
|
posts: response.data.data.children.filter(post => post.data.subreddit === 'ProgrammerHumor' && post.data.removed_by_category === null),
|
|
next: response.data.data.after,
|
|
previous: response.data.data.before
|
|
})
|
|
|
|
})
|
|
|
|
app.get('/before/:before', async (req, res)=>{
|
|
const data = {
|
|
grant_type:'password',
|
|
username:process.env.REDDITUSR,
|
|
password:process.env.REDDITPWD
|
|
}
|
|
const auth = {
|
|
username: process.env.APPID,
|
|
password: process.env.APPSECRET
|
|
}
|
|
let response = await axios({
|
|
url:'https://www.reddit.com/api/v1/access_token',
|
|
method:'post',
|
|
auth:auth,
|
|
data:querystring.stringify(data)
|
|
})
|
|
|
|
const config = {
|
|
headers:{
|
|
Authorization: 'bearer '+response.data.access_token
|
|
}
|
|
}
|
|
response = await axios.get('https://oauth.reddit.com/user/mahuntington/saved?count=100&before='+req.params.before, config)
|
|
|
|
res.render('all.ejs', {
|
|
posts: response.data.data.children.filter(post => post.data.subreddit === 'ProgrammerHumor' && post.data.removed_by_category === null),
|
|
next: response.data.data.after,
|
|
previous: response.data.data.before
|
|
})
|
|
|
|
})
|
|
app.listen(3002, ()=>{
|
|
console.log('listening');
|
|
})
|