diff --git a/index.js b/index.js index bcd829a..21f2d52 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,18 @@ "use strict" const exec = require('child-process-promise').exec const MAX_BUFFER_SIZE = 2000 * 1024; -const applescript = require("applescript") +const applescript = require('applescript') const macNetworkDrive = { list: function list() { - let fetchDisks = exec("/bin/df", { + let fetchDisks = exec('/bin/df', { maxBuffer: MAX_BUFFER_SIZE }); let completePromise = new Promise((resolve, reject) => { fetchDisks.then(result => { - if (typeof result.stderr === "string" && result.stderr.length !== 0) { + if (typeof result.stderr === 'string' && result.stderr.length !== 0) { reject(stderr) } @@ -26,7 +26,7 @@ const macNetworkDrive = { for (let line of pathList) { let matches = line.match(re); if (matches) { - drivePath["\\\\" + matches[1].replace('/', '\\') + "\\"] = matches[2]; + drivePath[matches[1].replace(/\\/g, '/')] = matches[2]; } } resolve(drivePath) @@ -42,8 +42,8 @@ const macNetworkDrive = { find: function find(drivePath) { let completePromise = new Promise((resolve, reject) => { - if ("string" !== typeof drivePath || 0 === drivePath.length) { - reject("Invalid path"); + if ('string' !== typeof drivePath || 0 === drivePath.length) { + reject('Invalid path'); } macNetworkDrive.list().then(networkDrives => { @@ -52,9 +52,6 @@ const macNetworkDrive = { continue; } - if (drivePath.charAt(drivePath.length - 1) != "\\") - drivePath += "\\" - if (currentDrivePath.toUpperCase() === drivePath.toUpperCase()) { resolve(networkDrives[currentDrivePath]); } @@ -69,22 +66,17 @@ const macNetworkDrive = { mount: function mount(drivePath, localPath = null, username = null, password = null) { /* parametetr localPath is unused -> allow to have the same signature */ let completePromise = new Promise((resolve, reject) => { - - let test = macNetworkDrive.find(drivePath).then(result => { + macNetworkDrive.find(drivePath).then(result => { if (result !== undefined) { resolve(result) } else { - let connectPath = "" + let connectPath = '' let serverPath = drivePath if (username != null && password != null) { - username = username.replace("\\", "\\\\") connectPath = `${username}:${password}@` } - serverPath = serverPath.replace("\\\\", "") - serverPath = serverPath.replace("\\", "/") - let pathDrive = `smb://${connectPath}${serverPath}` let mountScript = ` tell application "Finder" @@ -98,7 +90,7 @@ const macNetworkDrive = { applescript.execString(mountScript, (err, result) => { if (err || result === undefined) { if (err === undefined) - reject("Unable to connect") + reject('Unable to connect') reject(err) } diff --git a/package.json b/package.json index 339f94d..a992578 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "applescript": "^1.0.0", "child-process-promise": "^2.2.1" }, - "os":["darwin"], "bugs":{ "url" : "https://github.com/Fllorent0D/MacNetworkDriveJS/issues", "email" : "f.cardoen@me.com"