김대연

Update channel list API

FRONT_URI =
FRONT_PORT =
HOST_URI = [twitch end point url]
SOCKET_PORT= [backend socket server port]
TWITCH_CLIENT= [twitch dev client id]
......
This diff is collapsed. Click to expand it.
......@@ -10,11 +10,12 @@
"author": "Daeyeonkim97",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"axios": "^0.21.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"ejs": "^3.1.5",
"express": "^4.17.1",
"pkg.json": "^2.0.8",
"request": "^2.88.2",
"socket.io": "^3.0.3",
"tmi.js": "^1.5.0"
......
......@@ -19,7 +19,7 @@ var opts = {
username: process.env.BOT_USERNAME,
password: process.env.OAUTH_TOKEN
},
channels: ["tmwardo"]
channels: []
};
// Create a client with our options
var client = new tmi.client(opts); //twitch chatbot client
......@@ -31,20 +31,15 @@ app.use(bodyParser.json());
app.set('view engine', 'ejs');
app.set('views', './testviews');
// client.opts.channels;
let a = 0;
app.get('/', (req, res) => {
res.render('chat');
});
app.get('/list',(req,res) => {
var result = []
for (var i = 0; i<client.channels.length; i++){
result.push(client.channels[i].slice(1))
}
res.send(result)
app.get('/channels',(req,res) => {
//console.log(channels)
res.send(channels)
});
app.post('/jointest',async (req,res)=>{
......@@ -52,8 +47,10 @@ app.post('/jointest',async (req,res)=>{
JoinChannel(req.body.streamer);
res.send(req.body.streamer)
});
console.log(`https://id.twitch.tv/oauth2/authorize?response_type=code&approval_prompt=auto&redirect_uri=${process.env.HOST_URI+':'+process.env.SOCKET_PORT}/join&client_id=${process.env.TWITCH_CLIENT}`)
////////////////////////oauth////////////////////////
var channels = []
const axios = require('axios')
app.get('/oauth',(req,res)=>{
let codeAddr = `https://id.twitch.tv/oauth2/authorize?response_type=code&approval_prompt=auto&redirect_uri=${process.env.HOST_URI+':'+process.env.SOCKET_PORT}/join&client_id=${process.env.TWITCH_CLIENT}`
......@@ -72,7 +69,17 @@ app.get('/join', async (req,res)=>{
}
).then(resp2=>{
JoinChannel(resp2.data.login)
res.redirect("http://localhost:8000?authenticated=true") // 이거 프론트 유알엘임
axios.get(`https://api.twitch.tv/kraken/channels/${resp2.data.user_id}`,
{
headers:{
'Accept' : 'application/vnd.twitchtv.v5+json',
'Client-ID' : process.env.TWITCH_CLIENT
}
}
).then(resp3=>{
channels.push(resp3.data);
})
res.redirect(`${process.env.FRONT_URI}:${process.env.FRONT_PORT}/?authenticated=true`) // 이거 프론트 유알엘임
})
})
......