You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Display link to resources and display them via server.
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import { shim } from 'lib/shim.js'
|
||||
|
||||
const tcpPortUsed = require('tcp-port-used');
|
||||
|
||||
const netUtils = {};
|
||||
|
||||
netUtils.ip = async () => {
|
||||
@ -12,4 +14,20 @@ netUtils.ip = async () => {
|
||||
return ip.ip;
|
||||
}
|
||||
|
||||
netUtils.findAvailablePort = async (possiblePorts, extraRandomPortsToTry = 20) => {
|
||||
for (let i = 0; i < extraRandomPortsToTry; i++) {
|
||||
possiblePorts.push(Math.floor(8000 + Math.random() * 2000));
|
||||
}
|
||||
|
||||
let port = null;
|
||||
for (let i = 0; i < possiblePorts.length; i++) {
|
||||
let inUse = await tcpPortUsed.check(possiblePorts[i]);
|
||||
if (!inUse) {
|
||||
port = possiblePorts[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return port;
|
||||
}
|
||||
|
||||
export { netUtils };
|
Reference in New Issue
Block a user