|
|
|
@ -3,18 +3,18 @@ const app = express();
|
|
|
|
const axios = require('axios');
|
|
|
|
const axios = require('axios');
|
|
|
|
const querystring = require('querystring');
|
|
|
|
const querystring = require('querystring');
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/', async (req, res)=>{
|
|
|
|
const data = {
|
|
|
|
|
|
|
|
grant_type:'password',
|
|
|
|
const data = {
|
|
|
|
username:process.env.REDDITUSR,
|
|
|
|
grant_type:'password',
|
|
|
|
password:process.env.REDDITPWD
|
|
|
|
username:process.env.REDDITUSR,
|
|
|
|
}
|
|
|
|
password:process.env.REDDITPWD
|
|
|
|
const auth = {
|
|
|
|
}
|
|
|
|
username: process.env.APPID,
|
|
|
|
const auth = {
|
|
|
|
password: process.env.APPSECRET
|
|
|
|
username: process.env.APPID,
|
|
|
|
}
|
|
|
|
password: process.env.APPSECRET
|
|
|
|
|
|
|
|
}
|
|
|
|
const getToken = async ()=>{
|
|
|
|
let response = await axios({
|
|
|
|
const response = await axios({
|
|
|
|
url:'https://www.reddit.com/api/v1/access_token',
|
|
|
|
url:'https://www.reddit.com/api/v1/access_token',
|
|
|
|
method:'post',
|
|
|
|
method:'post',
|
|
|
|
auth:auth,
|
|
|
|
auth:auth,
|
|
|
|
@ -26,39 +26,19 @@ app.get('/', async (req, res)=>{
|
|
|
|
Authorization: 'bearer '+response.data.access_token
|
|
|
|
Authorization: 'bearer '+response.data.access_token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
response = await axios.get('https://oauth.reddit.com/user/mahuntington/saved?count=100', config)
|
|
|
|
return config
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
res.render('all.ejs', {
|
|
|
|
const generate = async (req, res)=>{
|
|
|
|
posts: response.data.data.children.filter(post => post.data.subreddit === 'ProgrammerHumor' && post.data.removed_by_category === null),
|
|
|
|
|
|
|
|
next: response.data.data.after,
|
|
|
|
let url = `https://oauth.reddit.com/user/mahuntington/saved?count=100`;
|
|
|
|
previous:null
|
|
|
|
|
|
|
|
})
|
|
|
|
if(req.params.direction){
|
|
|
|
|
|
|
|
url += `&${req.params.direction}=${req.params.page}`
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
const config = await getToken()
|
|
|
|
headers:{
|
|
|
|
const response = await axios.get(url, config)
|
|
|
|
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', {
|
|
|
|
res.render('all.ejs', {
|
|
|
|
posts: response.data.data.children.filter(post => post.data.subreddit === 'ProgrammerHumor' && post.data.removed_by_category === null),
|
|
|
|
posts: response.data.data.children.filter(post => post.data.subreddit === 'ProgrammerHumor' && post.data.removed_by_category === null),
|
|
|
|
@ -66,39 +46,12 @@ app.get('/after/:after', async (req, res)=>{
|
|
|
|
previous: response.data.data.before
|
|
|
|
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 = {
|
|
|
|
app.get('/', generate)
|
|
|
|
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', {
|
|
|
|
app.get('/:direction/:page', generate)
|
|
|
|
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, ()=>{
|
|
|
|
app.listen(3002, ()=>{
|
|
|
|
console.log('listening');
|
|
|
|
console.log('listening');
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|