Skip to content

Commit

Permalink
Added stuff
Browse files Browse the repository at this point in the history
-Added comments
-Tested freeport but failed in the current build
  • Loading branch information
ionicc committed Mar 29, 2018
1 parent 02bffa2 commit 0ba87ba
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 7 deletions.
35 changes: 29 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,63 @@
/* QR-FILETRANSFER done in NodeJS
*
* Inspired from @claudiodangelis qr-filetransfer written in Go
* @claudiodangelis https://github.com/claudiodangelis
*/

//Initialising dependencies
var express = require('express');
var qrTerminal = require('qrcode-terminal');
var chalk = require('chalk');
var fs = require('fs');
var localIpV4Address = require('local-ipv4-address');
var localIpV4Address = require("local-ipv4-address");

//Calling local scripts

var misc = require("./lib/misc.js");
var constants = require("./lib/constants.js");

//Initialising express
var app = express();

const port = 3000 || process.env.PORT;
//Defining constants for path and port
const pathInitial = __dirname + "/";
var pathTotal = pathInitial + process.argv[2];

var ipv4 = "http://192.168.1.2:3000";
//Using the constant values in lib/constants.js
//TODO: Constant values shouldn't be usued at all. It could break in any other device.

var ipv4 = constants.ipv4;
var fPort = constants.port;

//Getting the localIP of the device
localIpV4Address().then(function(ipAddress){
ipv4 = ipAddress;
});

//Defining a string in the form http://ip-address:port for the qr generation
const finalIP = ipv4 + ":" + fPort;

//Checking the arguments passed
if(process.argv.length != 3) {
console.log(chalk.red(":/ Something's missing in the arguments"));
console.log(chalk.green("It should be something like node index.js i_am_so_great.pdf"));
process.exit(0);
}

//Checking if the file exists
if(!fs.existsSync(pathTotal)) {
console.log(chalk.red("The file does not exist, Please check the file path again"));
}
else {

app.listen(port, (req,res) => {
//console.log("Server is live");
//Initialising the server
app.listen(fPort, (req,res) => {
console.log("Server is live at port" + fPort);
misc.header();
qrTerminal.generate(ipv4);

//Generating the qrcode
qrTerminal.generate(finalIP);
console.log(finalIP);

});

Expand Down
6 changes: 5 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports = {
owner: "Sagar"
owner: "Sagar",
port: "3000",
ipv4: "http://192.168.1.2"
}

//Incase localIPv4Address fails, Assign the local IP of your machine from here
9 changes: 9 additions & 0 deletions node_modules/freeport/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/freeport/lib/freeport.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions node_modules/freeport/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions node_modules/freeport/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions node_modules/freeport/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/get-port/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/get-port/license

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions node_modules/get-port/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions node_modules/get-port/readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"chalk": "^2.3.2",
"express": "^4.16.3",
"figlet": "^1.2.0",
"freeport": "^1.0.5",
"get-port": "^3.2.0",
"local-ipv4-address": "0.0.2",
"qrcode-terminal": "^0.12.0"
}
Expand Down

0 comments on commit 0ba87ba

Please sign in to comment.