Skip to content

Commit

Permalink
added finding ipv4
Browse files Browse the repository at this point in the history
Added a functionality to automatically detect the ipv4 address of the device
  • Loading branch information
ionicc committed Mar 28, 2018
1 parent d5442a9 commit 02bffa2
Show file tree
Hide file tree
Showing 58 changed files with 7,984 additions and 14 deletions.
32 changes: 27 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
var express = require('express');
var qrTerminal = require('qrcode-terminal');
var chalk = require('chalk');
var fs = require('fs');
var localIpV4Address = require('local-ipv4-address');

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

var app = express();

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

var ipv4 = constants.IPv4;
var ipv4 = "http://192.168.1.2:3000";

app.listen(port, (req,res) => {
console.log("Server is live");
localIpV4Address().then(function(ipAddress){
ipv4 = ipAddress;
});


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);
}

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");
misc.header();
qrTerminal.generate(ipv4);

});

app.get('/', (req,res) => {
console.log("A GET req to the server was recieved");
res.sendFile(__dirname + "/files_to_send" + "/" + process.argv[2]);
console.log(`A download was observed from ${req.ip}`);
res.sendFile(pathInitial + process.argv[2]);
});
}
5 changes: 1 addition & 4 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
module.exports = {
owner: "Sagar",
IPv4: "http://192.168.1.2:3000"
owner: "Sagar"
}

//A lot to be added :D
13 changes: 8 additions & 5 deletions lib/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ var fig = require('figlet');
var chalk = require('chalk');

module.exports.header = function () {
console.log("--------------------------------------------------");
console.log("File to be sent: " +process.argv[2]);
console.log("--------------------------------------------------");
console.log(chalk.green("--------------------------------------------------"));
console.log(chalk.green("File to be sent: " +process.argv[2]));
console.log(chalk.green("--------------------------------------------------"));
}

module.exports.emoji = figlet('(〜^∇^)〜', (err, data) => {
module.exports.emoji = fig('SCAN IT :)', (err, data) => {
if(err) {
console.log('Oops, something went wrong D:');
return;
}
else {
console.log(data);
console.log(chalk.green(data));
}
});


//Misc is turning out to be the place for all the party code :D
165 changes: 165 additions & 0 deletions node_modules/ansi-styles/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/ansi-styles/license

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

88 changes: 88 additions & 0 deletions node_modules/ansi-styles/package.json

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

Loading

0 comments on commit 02bffa2

Please sign in to comment.