Add playlist, video and ad skeleton

This commit is contained in:
Yûki VACHOT 2021-10-30 03:10:15 +02:00
parent e87c4bb146
commit 5f73ec72bc
20 changed files with 414 additions and 65 deletions

View file

@ -1,9 +0,0 @@
const {sendError} = require ("./response.config");
function checkFormat(req, res){
if(req.get('Content-Type') !== 'application/json') {
return sendError(res, 401, -1, "Invalid header format (please use JSON)");
}
return true; // Is valid
}
module.exports = checkFormat

View file

@ -0,0 +1,8 @@
module.exports = {
youtube: {
baseAPIUrl: 'https://www.youtube.com/'
},
dailymotion: {
baseAPIUrl: 'https://api.dailymotion.com/'
}
};

View file

@ -0,0 +1,5 @@
module.exports = {
User: 0,
Advertiser: 5,
Admin: 10
};

View file

@ -12,9 +12,10 @@ const JWTRS256_PRIVATE_KEY = Buffer.from(process.env.JWTRS256_PRIVATE_KEY, 'base
const JWTRS256_PUBLIC_KEY = Buffer.from(process.env.JWTRS256_PUBLIC_KEY, 'base64').toString('utf-8');
function createSessionJWT (login, role) {
function createSessionJWT (id, login, role) {
return sessionJWTConfig.sign(
{
id: id,
login: login,
role: role,
midExp: Math.floor(Date.now() / 1000) + 1800
@ -29,21 +30,22 @@ function createSessionJWT (login, role) {
function createSessionCookie(req, res, payload) {
let jwtToken;
if (typeof payload.login !== 'undefined' &&
if (typeof payload.id !== 'undefined' &&
typeof payload.login !== 'undefined' &&
typeof payload.role !== 'undefined' &&
typeof payload.midExp !== 'undefined' &&
(Math.floor(Date.now() / 1000) <= payload.midExp)) {
jwtToken = req.headers.cookie;
}
else {
jwtToken = createSessionJWT(payload.login, payload.role);
jwtToken = createSessionJWT(payload.id, payload.login, payload.role);
}
res.cookie('SESSIONID', jwtToken, {httpOnly:true, secure:false});
}
function decodeSessionCookie(sessionid) {
if (typeof sessionid === 'undefined') {
return {login: -1, role: -1};
return {id: -1, login: -1, role: -1};
}
try {
const token = sessionJWTConfig.verify(
@ -53,7 +55,7 @@ function decodeSessionCookie(sessionid) {
return {token: token};
}
catch (err) {
return {login: -1, role: -1};
return {id: -1, login: -1, role: -1};
}
}
@ -83,7 +85,7 @@ function checkLogin(req, res, role=null){
if(role === null){
return token;
} else{
if(token.role !== 'undefined' && token.role === role){
if(token.role !== 'undefined' && role.includes(token.role)){
return token;
} else{
return sendError(res, 500, -1, "User doesn't have permission.", token);