This commit is contained in:
2024-01-05 22:06:34 -05:00
parent c8f00cdeaf
commit abc547c642
34 changed files with 6586 additions and 1561 deletions

56
controller/auth.js Normal file
View File

@ -0,0 +1,56 @@
'use strict';
const {User, AuthToken} = require('>/models');
class Auth{
static errors = {
login: function(){
let error = new Error('LDAPLoginFailed');
error.name = 'LDAPLoginFailed';
error.message = `Invalid Credentials, login failed.`;
error.status = 401;
return error;
}
}
static async login(data){
try{
let user = await User.login(data);
let token = await AuthToken.create({username: user.username});
return {user, token}
}catch(error){
console.log('login error', error);
throw this.errors.login();
}
}
static async checkToken(token){
try{
token = await AuthToken.get(token);
if(token && token.check()) return token;
throw this.errors.login();
}catch(error){
throw this.errors.login();
}
}
static async logout(data){
let token = await AuthToken.get(data);
await token.destroy();
}
}
Auth.logOut = async function(data){
try{
}catch(error){
throw error;
}
}
module.exports = {Auth};

7
controller/index.js Normal file
View File

@ -0,0 +1,7 @@
'use strict';
module.exports = {
auth: require('./auth'),
pubsub: require('./pubsub'),
torrent: require('./torrent'),
}

6
controller/pubsub.js Normal file
View File

@ -0,0 +1,6 @@
const {PubSub} = require('p2psub');
ps = new PubSub();
module.exports = ps;

15
controller/torrent.js Normal file
View File

@ -0,0 +1,15 @@
'use strict';
const ps = require('./pubsub.js');
const {Torrent} = require('>/models');
console.log('here!!!!!!!!!!!!!')
setInterval(async function(){
ps.publish('torrent:server:status', await Torrent.trClient.sessionStats())
}, 3000);
// ps.subscribe(/./g, function(...args){
// console.log('event', args);
// });