Skip to content

Commit

Permalink
Show qr for all possible addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
robmcelhinney committed May 18, 2020
1 parent cb6daf6 commit 04b984f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 19 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})


Expand Down Expand Up @@ -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')))
}
2 changes: 2 additions & 0 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 04b984f

Please sign in to comment.