UNPKG

@trap_stevo/filenet

Version:

Provides the groundbreaking solution for real-time, OTA (Over-The-Air) file transfer, streamlining client-to-client sharing with unmatched efficiency and effortless, on-the-fly handling. Whether managing peer-to-peer or client-server transfers, FileNet en

93 lines (92 loc) 3.22 kB
#!/usr/bin/env node "use strict"; const FileTideClient = require("@trap_stevo/filetide-client"); const FileTide = require("@trap_stevo/filetide"); const fs = require("fs"); const args = process.argv.slice(2); let configFilePath = null; let positionalArgs = []; const flags = {}; let noMessager = false; for (let i = 0; i < args.length; i++) { const arg = args[i]; if (arg === "--config" && args[i + 1]) { configFilePath = args[i + 1]; i++; } else if (arg === "--no-messager") { noMessager = true; } else if (arg.startsWith("--")) { const flagName = arg.slice(2); const flagValue = args[i + 1] && !args[i + 1].startsWith("--") ? args[i + 1] : true; flags[flagName] = flagValue; if (flagValue !== true) i++; } else { positionalArgs.push(arg); } } let config = {}; if (configFilePath) { try { const fileData = fs.readFileSync(configFilePath, "utf-8"); config = JSON.parse(fileData); console.log("Config file loaded: ", configFilePath); } catch (error) { console.error("Could not read or parse config file: ", error.message); config = {}; console.log("Proceeding using default configurations..."); } } const port = positionalArgs[0] || config.port || 8869; const serverUrl = positionalArgs[1] || config.serverUrl || `http://localhost:${port}`; const room = positionalArgs[2] || config.room || "file-room"; const clientID = positionalArgs[3] || config.clientID || "FileNetServer"; const options = { port: port, ...config.options, ...JSON.parse(positionalArgs[4] || "{}") }; const messagerOptions = { maxHttpBufferSize: 5e9, pingTimeout: 3600000, pingInterval: 60000, ...config.messagerOptions, ...JSON.parse(positionalArgs[5] || "{}") }; const transportOptions = { parallelChunks: 3, maxRetries: 3, ...config.transportOptions, ...JSON.parse(positionalArgs[6] || "{}") }; const messagerSettings = { maxReconnectionAttempts: 15, reconnectionAttempts: 15, maxReconnectionDelay: 10000, ...config.messagerSettings, ...JSON.parse(positionalArgs[7] || "{}") }; const fileT = new FileTide(); fileT.launchFileTide(options, fileNet => { if (!noMessager) { const fileTideClient = new FileTideClient(clientID, serverUrl, room); fileTideClient.startClient(options, messagerOptions, transportOptions, messagerSettings, fileMessager => {}, () => {}, () => {}, (transferData, forwardResponse) => { FileTide.outputGradient(`${transferData.clientID} wants ${transferData.transferType === "requestSend" ? "you to send:" : "to transfer you:"}\n\n\t${transferData.path}.\n\nDo you accept (Y/n)?`, ["#3c97b0", "#7addeb"]); if (config.autoAccept) { forwardResponse(true, transferData); return; } if (config.acceptForClients && config.acceptForClients.includes(transferData.clientID)) { forwardResponse(true, transferData); return; } if (config.autoDeny) { forwardResponse(false, transferData); return; } if (config.denyForClients && config.denyForClients.includes(transferData.clientID)) { forwardResponse(false, transferData); return; } }, () => {}, () => {}, config.enableTransferBarrier || true); } });