diff --git a/config/config.js b/config/config.js new file mode 100644 index 0000000..f9d2dc1 --- /dev/null +++ b/config/config.js @@ -0,0 +1,13 @@ +module.exports = { + database:{ + /* + Here is an example structure of the config file + You can ofcourse change anything here to suit your needs + This structure is useful if you are using a mysql/mariadb database for example + */ + host:"", // Server IP and port if you have set a different port + username:"", // Username for the database user + password:"", // Password for the database user + database:"" // Name of the database + } +} \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..5205247 --- /dev/null +++ b/main.js @@ -0,0 +1,58 @@ +// Loading required packages +require("./requires.js") +console.log(start); + + +// Initialising map to be used to store the functionality later on for reloadability +mapFunctions = new Map() + + +// Loading the Function Map +var path = `${mainDir}/services/modules` +var folders = fs.readdirSync(path).filter(function (file) { + return fs.statSync(path+'/'+file).isDirectory(); +}); +folders.forEach(element => { + var commandFiles = fs.readdirSync(`${path}/${element}`).filter(file => file.endsWith('.js') && !file.startsWith("index")); + for (const file of commandFiles) { + delete require.cache[require.resolve(`${path}/${element}/${file}`)]; + const command = require(`${path}/${element}/${file}`); + mapFunctions.set(command.name, command); + } +}); + + + +// The startup information for the project, here you can add stuff that might be nice to see when the app starts +mapFunctions.get("Startup_function").function() +console.log("------------------------------------ Status ------------------------------------"); +console.log(__dirname); +console.log(platform); +console.log(`The Startup took ${new Date() - start}ms`) +console.log(`${mapFunctions.size} Function modules loaded`); +console.log("--------------------------------------------------------------------------------"); + + + + +// --------------------------------------------------------- CLI COMMANDS --------------------------------------------------------- // + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + + +rl.on("line", data =>{ + const args = data.trim().split(" "); + const command = args.shift().toLowerCase(); + mapFunctions.get("cliCommands").function(command, args) +}) + + + + + +// ----------------------------------------------------------- ELECTRON ----------------------------------------------------------- // + +// TODO - Add Electron support to the project diff --git a/package.json b/package.json index 649f09f..394d549 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,8 @@ "dependencies": { "cli-progress": "^3.12.0", "ffmpeg-static": "^5.2.0", - "fluent-ffmpeg": "^2.1.3" + "fluent-ffmpeg": "^2.1.3", + "express": "^5.1.0" }, "devDependencies": { "@types/cli-progress": "^3.11.6", @@ -11,5 +12,24 @@ "@types/node": "^24.9.2", "ts-node": "^10.9.2", "typescript": "^5.9.3" - } -} \ No newline at end of file + }, + "name": "video2document", + "version": "1.0.0", + "description": "To make it easy for you to get started with GitLab, here's a list of recommended next steps.", + "main": "main.js", + "directories": { + "doc": "docs", + "test": "tests" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://gitlab.rlp.net/proj-wise2526-video2document/video2document" + }, + "author": "", + "license": "ISC" +} + + diff --git a/requires.js b/requires.js new file mode 100644 index 0000000..e85038d --- /dev/null +++ b/requires.js @@ -0,0 +1,10 @@ +// Here you can define all the packages that you want to use +// You can also define variables that you want to be able to use in your entire project, like platform or mainDir in this example +// Make sure to define them like these examples here, as they will then be available as global variables throughout your entire project +start = new Date() +platform = process.platform +mainDir = __dirname +fs = require("fs") +readline = require("readline") +config = require("./config/config") + diff --git a/services/modules/document/.gitkeep b/services/modules/document/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/services/modules/document/chatgpt.js b/services/modules/document/chatgpt.js new file mode 100644 index 0000000..6e9034e --- /dev/null +++ b/services/modules/document/chatgpt.js @@ -0,0 +1,8 @@ +module.exports = { + name:"chatgpt", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()" + type:"document", // value used to differentiate each module to order them in the UI + displayname:"ChatGPT", // The displayname used within the UI + async function(parameter){ + // TODO add code to actually send the transcript to ChatGPT and get a response back + } +} \ No newline at end of file diff --git a/services/modules/transcription/.gitkeep b/services/modules/transcription/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/services/modules/transcription/assembly.js b/services/modules/transcription/assembly.js new file mode 100644 index 0000000..3b28dad --- /dev/null +++ b/services/modules/transcription/assembly.js @@ -0,0 +1,8 @@ +module.exports = { + name:"assembly", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()" + type:"transcription", // value used to differentiate each module to order them in the UI + displayname:"Assembly", // The displayname used within the UI + async function(parameter){ + // TODO add code to actually process the audio file + } +} \ No newline at end of file diff --git a/services/modules/transcription/example.js b/services/modules/transcription/example.js new file mode 100644 index 0000000..c86ad86 --- /dev/null +++ b/services/modules/transcription/example.js @@ -0,0 +1,10 @@ +module.exports = { + name:"example", // Unique name for our function that will later be used to get the function from the map via "mapFunctions.get("example").function()" + type:"example-type", // value used to differentiate each module to order them in the UI + displayname:"Example", // The displayname used within the UI + async function(randomParameter){ + // Here we put a simple console.log to show how the system works + // This function will be called from the @startup.js function in the utility folder + console.log(`\n------------\nThis is the example function called by the ${randomParameter} function\n------------\n`); + } +} \ No newline at end of file diff --git a/services/modules/utility/@startup.js b/services/modules/utility/@startup.js new file mode 100644 index 0000000..1b0e79c --- /dev/null +++ b/services/modules/utility/@startup.js @@ -0,0 +1,9 @@ +module.exports = { + name:"Startup_function", + async function(){ + // Put any code here that you want to be executed on startup + + // We are now calling the example function from the example folder + mapFunctions.get("example").function("Startup") + } +} \ No newline at end of file diff --git a/services/modules/utility/cliCommands.js b/services/modules/utility/cliCommands.js new file mode 100644 index 0000000..b249749 --- /dev/null +++ b/services/modules/utility/cliCommands.js @@ -0,0 +1,30 @@ +module.exports = { + name:"cliCommands", + async function(command, args){ + switch(command){ + case "exit": + process.exit(1); + break; + case "reload": + mapFunctions.clear() + // Reloading the Function Map + var path = `${mainDir}/services/modules` + var folders = fs.readdirSync(path).filter(function (file) { + return fs.statSync(path+'/'+file).isDirectory(); + }); + folders.forEach(element => { + var commandFiles = fs.readdirSync(`${path}/${element}`).filter(file => file.endsWith('.js') && !file.startsWith("index")); + for (const file of commandFiles) { + delete require.cache[require.resolve(`${path}/${element}/${file}`)]; + const command = require(`${path}/${element}/${file}`); + mapFunctions.set(command.name, command); + } + }); + console.log(`Reloaded ${mapFunctions.size} modules`) + break; + default: + console.log("This is not a recognised command"); + break; + }; + } +}