From 04b984f3c5c6e49e1a68eeefcd7c32991556a3ac Mon Sep 17 00:00:00 2001 From: robmcelhinney Date: Mon, 18 May 2020 22:54:31 +0100 Subject: [PATCH] Show qr for all possible addresses --- package.json | 2 +- server.js | 27 +++++++++++++++++++-------- todo.txt | 2 ++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 4c0b6d0..934a1c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@robmcelhinney/qr-file-share", - "version": "0.1.4", + "version": "0.1.5", "description": "Node.js http server allowing for file transfers over local area network made easier with QR code output on start.", "main": "server.js", "bin": "bin.js", diff --git a/server.js b/server.js index 4096113..f0b647d 100644 --- a/server.js +++ b/server.js @@ -24,19 +24,30 @@ module.exports = ({base_path, compression}) => { app.listen(port, () => { // get local ip address from https://gist.github.com/sviatco/9054346#gistcomment-1810845 - let address, - ifaces = require('os').networkInterfaces() + let addresses = new Set() + let ifaces = require('os').networkInterfaces() + for (let dev in ifaces) { ifaces[dev].filter((details) => details.family === 'IPv4' && details.internal === false ? address = details.address: undefined) + // console.log("address: ", address) + addresses.add(address) } - const full_address = "http://" + address + ":" + port - console.log("Server listening on port: ", port) - console.log("Scan QR code or go to " + full_address) - - qrcode.generate(full_address); + addresses = Array.from(addresses) + if (addresses.length == 0) { + return + } + // console.log("addresses: ", addresses) + for (address of addresses) { + const full_address = "http://" + address + ":" + port + console.log("Server listening on port: ", port) + console.log("Scan QR code or go to " + full_address) + + qrcode.generate(full_address) + console.log("\n") + } }) @@ -289,5 +300,5 @@ module.exports = ({base_path, compression}) => { }) - app.use(express.static(path.join(__dirname, 'client/build'))); + app.use(express.static(path.join(__dirname, 'client/build'))) } \ No newline at end of file diff --git a/todo.txt b/todo.txt index 7b28796..e67a9d7 100644 --- a/todo.txt +++ b/todo.txt @@ -2,3 +2,5 @@ Change file icon based on file? Document for text or empty file icon for media? Handle download error when file/dir missing. + +Sort files by name/size/date \ No newline at end of file