mirror of
https://github.com/gurnec/removeddit.git
synced 2026-03-11 08:54:27 +00:00
Started on Reddits API, token fetching is done
This commit is contained in:
parent
df46b5bde9
commit
78374850f9
7 changed files with 71 additions and 4 deletions
|
|
@ -1 +0,0 @@
|
|||
s
|
||||
0
src/js/components/StatusBox.js
Normal file
0
src/js/components/StatusBox.js
Normal file
|
|
@ -2,11 +2,27 @@ import React from 'react'
|
|||
import {prettyScore} from 'utils'
|
||||
|
||||
export default class Thread extends React.Component {
|
||||
constructor() {
|
||||
super()
|
||||
|
||||
this.state = {
|
||||
url: '',
|
||||
thumbnailWidth: 70,
|
||||
thumbnailHeight: 70,
|
||||
thumbnail: '',
|
||||
position: 0,
|
||||
score: 0
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
render () {
|
||||
const url = this.props.url.replace('reddit.com', 'removeddit.com')
|
||||
let thumbnail
|
||||
let thumbnailWidth = this.props.thread.thumbnail_width ? this.props.thread.thumbnail_width * 0.5 : 70
|
||||
let thumbnailHeight = this.props.thread.thumbnail_height ? this.props.thread.thumbnail_height * 0.5 : 70
|
||||
const thumbnailWidth = this.props.thread.thumbnail_width ? this.props.thread.thumbnail_width * 0.5 : 70
|
||||
const thumbnailHeight = this.props.thread.thumbnail_height ? this.props.thread.thumbnail_height * 0.5 : 70
|
||||
|
||||
if(['self', 'default', 'image', 'nsfw'].includes(this.props.thread.thumbnail)) {
|
||||
thumbnail = <a href={url} className='thumbnail thumbnail-<%= thread.thumbnail%>'></a>
|
||||
|
|
@ -17,7 +33,6 @@ export default class Thread extends React.Component {
|
|||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div className='thread'>
|
||||
|
|
|
|||
|
|
@ -8,3 +8,8 @@ ReactDOM.render(
|
|||
<App />,
|
||||
document.getElementById("app")
|
||||
)
|
||||
|
||||
|
||||
// import Reddit from './reddit'
|
||||
|
||||
// Reddit.comments(1,2).then(() => console.log('lololololololol'))
|
||||
|
|
|
|||
3
src/js/reddit/clientID.js
Normal file
3
src/js/reddit/clientID.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Change this to your own client ID: https://www.reddit.com/prefs/apps
|
||||
// The app NEEDS TO BE an installed app and NOT a web apps
|
||||
export default 'YSidAws9twqCZg'
|
||||
42
src/js/reddit/index.js
Normal file
42
src/js/reddit/index.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import clientID from './clientID'
|
||||
import {json} from 'utils'
|
||||
|
||||
// Reddit API
|
||||
const init = {
|
||||
headers: {
|
||||
'Authorization': ''
|
||||
}
|
||||
}
|
||||
|
||||
let hasToken = false
|
||||
|
||||
const tokenInit = {
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + btoa(clientID + ':'),
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
|
||||
},
|
||||
method: 'POST',
|
||||
body: 'grant_type='+encodeURIComponent('https://oauth.reddit.com/grants/installed_client')+'&device_id=DO_NOT_TRACK_THIS_DEVICE'
|
||||
}
|
||||
|
||||
const fetchToken = () => {
|
||||
if(hasToken) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
return fetch('https://www.reddit.com/api/v1/access_token', tokenInit)
|
||||
.then(json)
|
||||
.then(json => {
|
||||
init.headers.Authorization = 'bearer ' + json.access_token;
|
||||
hasToken = true
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
comments(subreddit, threadID) {
|
||||
return fetchToken()
|
||||
.then(() => console.log('hi'))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,9 @@ import SnuOwnd from 'libraries/snuownd.js'
|
|||
|
||||
const markdown = SnuOwnd.getParser()
|
||||
|
||||
// JSON parsing for fetch
|
||||
export const json = x => x.json()
|
||||
|
||||
// Parse comments
|
||||
export const parse = text => {
|
||||
return markdown.render(text)
|
||||
|
|
|
|||
Loading…
Reference in a new issue