Implemented back-end for basic time-based queueing system.

This commit is contained in:
rainbow napkin 2025-01-19 15:13:31 -05:00
parent f38eae170d
commit 4f6b3318a0
11 changed files with 329 additions and 140 deletions

View file

@ -37,6 +37,10 @@ module.exports.exceptionHandler = function(res, err){
module.exports.errorHandler(res, err.message, "Caught Exception");
}
module.exports.socketErrorHandler = function(socket, msg, type = "Generic"){
return socket.emit("error", {errors: [{type, msg, date: new Date()}]});
}
module.exports.socketExceptionHandler = function(socket, err){
//If we're being verbose
if(config.verbose){
@ -45,7 +49,7 @@ module.exports.socketExceptionHandler = function(socket, err){
}
//if not yell at the browser for fucking up, and tell it what it did wrong.
return socket.emit("error", {errors: [{type: "Caught Exception", msg: err.message, date: new Date()}]});
return module.exports.socketErrorHandler(socket, err.msg, "Caught Exception");
}
module.exports.socketCriticalExceptionHandler = function(socket, err){

68
src/utils/media/yanker.js Normal file
View file

@ -0,0 +1,68 @@
/*Canopy - The next generation of stoner streaming software
Copyright (C) 2024-2025 Rainbownapkin and the TTN Community
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
//NPM Imports
const validator = require('validator');//No express here, so regular validator it is!
//local import
const iaUtil = require('./internetArchiveUtils');
const media = require('../../app/channel/media/media');
module.exports.yankMedia = async function(url){
const pullType = await this.getMediaType(url);
if(pullType == 'ia'){
//Create empty list to hold media objects
const mediaList = [];
//Pull metadata from IA
const mediaInfo = await iaUtil.fetchMetadata(url);
//for every compatible and relevant file returned from IA
for(let file of mediaInfo.files){
//Split file path by directories
const path = file.name.split('/');
//pull filename from path
const name = path[path.length - 1];
//Construct link from pulled info
const link = `https://archive.org/download/${mediaInfo.metadata.identifier}/${file.name}`;
//Create new media object from file info
mediaList.push(new media(name, name, link, 'ia', Number(file.length)));
}
//return media object list
return mediaList;
}else{
//return null to signify a bad url
return null;
}
}
module.exports.getMediaType = async function(url){
//Check if we have a valid url
if(!validator.isURL(url)){
//If not toss the fucker out
return null;
}
//If we have link to a resource from archive.org
if(url.match(/^https\:\/\/archive.org\//g)){
//return internet archive code
return "ia";
}
return null;
}