Comparing version 1.0.1 to 1.1.0
# WebDAV-client changelog | ||
## 1.1.0 | ||
_2017-08-30_ | ||
* Add transpilation process for published library | ||
## 1.0.1 | ||
@@ -4,0 +9,0 @@ _2017-08-07_ |
{ | ||
"name": "webdav", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "WebDAV client for NodeJS", | ||
"main": "source/index.js", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "babel --out-dir dist source", | ||
"generate:docs": "jsdoc2md 'source/**/*.js' > API.md", | ||
"prepare": "npm run build", | ||
"test": "npm run test:lint && npm run test:unit", | ||
"test:lint": "eslint source/ && eslint test/specs/", | ||
"test:unit": "mocha -r test/specs/index.js test/specs/**/*.spec.js" | ||
"test:unit": "npm run build && mocha -r test/specs/index.js test/specs/**/*.spec.js" | ||
}, | ||
@@ -36,2 +38,4 @@ "repository": { | ||
"devDependencies": { | ||
"babel-cli": "~6.26.0", | ||
"babel-preset-env": "~1.6.0", | ||
"buffer-equals": "~1.0.4", | ||
@@ -42,2 +46,4 @@ "chai": "^3.5.0", | ||
"eslint": "~4.4.0", | ||
"eslint-config-prettier": "~2.3.0", | ||
"eslint-plugin-prettier": "~2.1.2", | ||
"exists-file": "~3.0.2", | ||
@@ -47,2 +53,3 @@ "jsdoc-to-markdown": "^3.0.0", | ||
"mocha": "^3.1.0", | ||
"prettier": "~1.5.3", | ||
"rimraf": "~2.6.1", | ||
@@ -49,0 +56,0 @@ "sinon": "^3.0.0", |
@@ -0,3 +1,5 @@ | ||
"use strict"; | ||
function generateBasicAuthHeader(username, password) { | ||
return "Basic " + (new Buffer(username + ":" + password)).toString("base64"); | ||
return "Basic " + Buffer.from(username + ":" + password).toString("base64"); | ||
} | ||
@@ -4,0 +6,0 @@ |
@@ -1,16 +0,18 @@ | ||
var deepmerge = require("deepmerge"); | ||
"use strict"; | ||
var authTools = require("./auth.js"), | ||
urlTools = require("./url.js"); | ||
const deepmerge = require("deepmerge"); | ||
var directoryContents = require("./interface/directoryContents.js"), | ||
createDir = require("./interface/createDirectory.js"), | ||
createStream = require("./interface/createStream.js"), | ||
deletion = require("./interface/delete.js"), | ||
getFile = require("./interface/getFile.js"), | ||
quota = require("./interface/quota.js"), | ||
move = require("./interface/moveFile.js"), | ||
putFile = require("./interface/putFile.js"), | ||
stats = require("./interface/stat.js"); | ||
const authTools = require("./auth.js"); | ||
const urlTools = require("./url.js"); | ||
const directoryContents = require("./interface/directoryContents.js"); | ||
const createDir = require("./interface/createDirectory.js"); | ||
const createStream = require("./interface/createStream.js"); | ||
const deletion = require("./interface/delete.js"); | ||
const getFile = require("./interface/getFile.js"); | ||
const quota = require("./interface/quota.js"); | ||
const move = require("./interface/moveFile.js"); | ||
const putFile = require("./interface/putFile.js"); | ||
const stats = require("./interface/stat.js"); | ||
/** | ||
@@ -50,3 +52,3 @@ * Client adapter | ||
function createClient(remoteURL, username, password) { | ||
var baseOptions = { | ||
const baseOptions = { | ||
headers: {}, | ||
@@ -57,7 +59,9 @@ remotePath: urlTools.extractURLPath(remoteURL), | ||
if (username && username.length > 0) { | ||
baseOptions.headers.Authorization = authTools.generateBasicAuthHeader(username, password); | ||
baseOptions.headers.Authorization = authTools.generateBasicAuthHeader( | ||
username, | ||
password | ||
); | ||
} | ||
return { | ||
/** | ||
@@ -71,6 +75,3 @@ * Create a directory | ||
createDirectory: function createDirectory(dirPath, options) { | ||
var createOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
); | ||
const createOptions = deepmerge(baseOptions, options || {}); | ||
return createDir.createDirectory(dirPath, createOptions); | ||
@@ -87,6 +88,3 @@ }, | ||
createReadStream: function createReadStream(remoteFilename, options) { | ||
var createOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
); | ||
const createOptions = deepmerge(baseOptions, options || {}); | ||
return createStream.createReadStream(remoteFilename, createOptions); | ||
@@ -103,7 +101,7 @@ }, | ||
createWriteStream: function createWriteStream(remoteFilename, options) { | ||
var createOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
const createOptions = deepmerge(baseOptions, options || {}); | ||
return createStream.createWriteStream( | ||
remoteFilename, | ||
createOptions | ||
); | ||
return createStream.createWriteStream(remoteFilename, createOptions); | ||
}, | ||
@@ -119,6 +117,3 @@ | ||
deleteFile: function deleteFile(remotePath, options) { | ||
var deleteOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
); | ||
const deleteOptions = deepmerge(baseOptions, options || {}); | ||
return deletion.deleteFile(remotePath, deleteOptions); | ||
@@ -134,8 +129,11 @@ }, | ||
*/ | ||
getDirectoryContents: function getDirectoryContents(remotePath, options) { | ||
var getOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
getDirectoryContents: function getDirectoryContents( | ||
remotePath, | ||
options | ||
) { | ||
const getOptions = deepmerge(baseOptions, options || {}); | ||
return directoryContents.getDirectoryContents( | ||
remotePath, | ||
getOptions | ||
); | ||
return directoryContents.getDirectoryContents(remotePath, getOptions); | ||
}, | ||
@@ -151,6 +149,3 @@ | ||
getFileContents: function getFileContents(remoteFilename, options) { | ||
var getOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
); | ||
const getOptions = deepmerge(baseOptions, options || {}); | ||
getOptions.format = getOptions.format || "binary"; | ||
@@ -160,5 +155,5 @@ if (["binary", "text"].indexOf(getOptions.format) < 0) { | ||
} | ||
return (getOptions.format === "text") ? | ||
getFile.getFileContentsString(remoteFilename, getOptions) : | ||
getFile.getFileContentsBuffer(remoteFilename, getOptions); | ||
return getOptions.format === "text" | ||
? getFile.getFileContentsString(remoteFilename, getOptions) | ||
: getFile.getFileContentsBuffer(remoteFilename, getOptions); | ||
}, | ||
@@ -173,6 +168,3 @@ | ||
getQuota: function getQuota(options) { | ||
var getOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
); | ||
const getOptions = deepmerge(baseOptions, options || {}); | ||
return quota.getQuota(getOptions); | ||
@@ -190,6 +182,3 @@ }, | ||
moveFile: function moveFile(remotePath, targetRemotePath, options) { | ||
var moveOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
); | ||
const moveOptions = deepmerge(baseOptions, options || {}); | ||
return move.moveFile(remotePath, targetRemotePath, moveOptions); | ||
@@ -206,7 +195,8 @@ }, | ||
*/ | ||
putFileContents: function putFileContents(remoteFilename, data, options) { | ||
var putOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
); | ||
putFileContents: function putFileContents( | ||
remoteFilename, | ||
data, | ||
options | ||
) { | ||
const putOptions = deepmerge(baseOptions, options || {}); | ||
return putFile.putFileContents(remoteFilename, data, putOptions); | ||
@@ -223,9 +213,5 @@ }, | ||
stat: function stat(remotePath, options) { | ||
var getOptions = deepmerge( | ||
baseOptions, | ||
options || {} | ||
); | ||
const getOptions = deepmerge(baseOptions, options || {}); | ||
return stats.getStat(remotePath, getOptions); | ||
} | ||
}; | ||
@@ -235,5 +221,3 @@ } | ||
module.exports = { | ||
createClient | ||
}; |
@@ -1,6 +0,8 @@ | ||
var setFetchMethod = require("./request.js").setFetchMethod, | ||
createClient = require("./factory.js").createClient; | ||
"use strict"; | ||
const setFetchMethod = require("./request.js").setFetchMethod; | ||
const createClient = require("./factory.js").createClient; | ||
createClient.setFetchMethod = setFetchMethod; | ||
module.exports = createClient; |
@@ -1,14 +0,17 @@ | ||
var joinURL = require("url-join"); | ||
"use strict"; | ||
var fetch = require("../request.js").fetch, | ||
responseHandlers = require("../response.js"); | ||
const joinURL = require("url-join"); | ||
const fetch = require("../request.js").fetch; | ||
const responseHandlers = require("../response.js"); | ||
function createDirectory(dirPath, options) { | ||
var fetchURL = joinURL(options.remoteURL, dirPath), | ||
fetchOptions = { | ||
method: "MKCOL", | ||
headers: options.headers | ||
}; | ||
return fetch(fetchURL, fetchOptions) | ||
.then(responseHandlers.handleResponseCode); | ||
const fetchURL = joinURL(options.remoteURL, dirPath); | ||
const fetchOptions = { | ||
method: "MKCOL", | ||
headers: options.headers | ||
}; | ||
return fetch(fetchURL, fetchOptions).then( | ||
responseHandlers.handleResponseCode | ||
); | ||
} | ||
@@ -15,0 +18,0 @@ |
@@ -1,12 +0,14 @@ | ||
var Stream = require("stream"), | ||
joinURL = require("url-join"), | ||
deepmerge = require("deepmerge"); | ||
"use strict"; | ||
var fetch = require("../request.js").fetch, | ||
responseHandlers = require("../response.js"); | ||
const Stream = require("stream"); | ||
const joinURL = require("url-join"); | ||
const deepmerge = require("deepmerge"); | ||
var PassThroughStream = Stream.PassThrough; | ||
const fetch = require("../request.js").fetch; | ||
const responseHandlers = require("../response.js"); | ||
const PassThroughStream = Stream.PassThrough; | ||
function createReadStream(filePath, options) { | ||
var outStream = new PassThroughStream(); | ||
const outStream = new PassThroughStream(); | ||
getFileStream(filePath, options) | ||
@@ -23,4 +25,4 @@ .then(function __handleStream(stream) { | ||
function createWriteStream(filePath, options) { | ||
var writeStream = new PassThroughStream(), | ||
headers = deepmerge({}, options.headers); | ||
const writeStream = new PassThroughStream(); | ||
const headers = deepmerge({}, options.headers); | ||
// if (typeof options.range === "object" && typeof options.range.start === "number") { | ||
@@ -36,8 +38,8 @@ // var rangeHeader = "bytes=" + options.range.start + "-"; | ||
} | ||
var fetchURL = joinURL(options.remoteURL, filePath), | ||
fetchOptions = { | ||
method: "PUT", | ||
headers: headers, | ||
body: writeStream | ||
}; | ||
const fetchURL = joinURL(options.remoteURL, filePath); | ||
const fetchOptions = { | ||
method: "PUT", | ||
headers: headers, | ||
body: writeStream | ||
}; | ||
fetch(fetchURL, fetchOptions); | ||
@@ -48,4 +50,7 @@ return writeStream; | ||
function getFileStream(filePath, options) { | ||
var rangeHeader; | ||
if (typeof options.range === "object" && typeof options.range.start === "number") { | ||
let rangeHeader; | ||
if ( | ||
typeof options.range === "object" && | ||
typeof options.range.start === "number" | ||
) { | ||
rangeHeader = "bytes=" + options.range.start + "-"; | ||
@@ -57,7 +62,7 @@ if (typeof options.range.end === "number") { | ||
} | ||
var fetchURL = joinURL(options.remoteURL, filePath), | ||
fetchOptions = { | ||
method: "GET", | ||
headers: options.headers | ||
}; | ||
const fetchURL = joinURL(options.remoteURL, filePath); | ||
const fetchOptions = { | ||
method: "GET", | ||
headers: options.headers | ||
}; | ||
return fetch(fetchURL, fetchOptions) | ||
@@ -64,0 +69,0 @@ .then(responseHandlers.handleResponseCode) |
@@ -1,11 +0,8 @@ | ||
var path = require("path"), | ||
xml2js = require("xml2js"); | ||
"use strict"; | ||
var DAV_KEY_PREFIXES = [ | ||
"", | ||
"d:", | ||
"D:", | ||
"lp1:" | ||
]; | ||
const path = require("path"); | ||
const xml2js = require("xml2js"); | ||
const DAV_KEY_PREFIXES = ["", "d:", "D:", "lp1:"]; | ||
function generateKeysForName(name) { | ||
@@ -18,11 +15,7 @@ return DAV_KEY_PREFIXES.map(function __mapKeyName(prefix) { | ||
function getSingleValue(item) { | ||
return Array.isArray(item) ? | ||
getSingleValue(item[0]) : | ||
item; | ||
return Array.isArray(item) ? getSingleValue(item[0]) : item; | ||
} | ||
function getValueForKey(key, obj) { | ||
var keys, | ||
i, | ||
keyCount; | ||
let keys, i, keyCount; | ||
if (typeof obj === "object") { | ||
@@ -40,3 +33,3 @@ keys = generateKeysForName(key); | ||
function parseXML(xml) { | ||
var parser = new xml2js.Parser({ ignoreAttrs: true }); | ||
const parser = new xml2js.Parser({ ignoreAttrs: true }); | ||
return new Promise(function(resolve, reject) { | ||
@@ -54,10 +47,11 @@ parser.parseString(xml, function __handleParseResult(err, result) { | ||
// Last modified time, raw size, item type and mime | ||
var lastMod = getSingleValue(getValueForKey("getlastmodified", props)), | ||
rawSize = getSingleValue(getValueForKey("getcontentlength", props)) || "0", | ||
resourceType = getSingleValue(getValueForKey("resourcetype", props)), | ||
mimeType = getSingleValue(getValueForKey("getcontenttype", props)), | ||
type = getValueForKey("collection", resourceType) ? | ||
"directory" : | ||
"file"; | ||
var stat = { | ||
const lastMod = getSingleValue(getValueForKey("getlastmodified", props)); | ||
const rawSize = | ||
getSingleValue(getValueForKey("getcontentlength", props)) || "0"; | ||
const resourceType = getSingleValue(getValueForKey("resourcetype", props)); | ||
const mimeType = getSingleValue(getValueForKey("getcontenttype", props)); | ||
const type = getValueForKey("collection", resourceType) | ||
? "directory" | ||
: "file"; | ||
const stat = { | ||
filename: filename, | ||
@@ -70,5 +64,3 @@ basename: path.basename(filename), | ||
if (type === "file") { | ||
stat.mime = mimeType ? | ||
mimeType.split(";")[0] : | ||
""; | ||
stat.mime = mimeType ? mimeType.split(";")[0] : ""; | ||
} | ||
@@ -83,3 +75,3 @@ return stat; | ||
case "-2": | ||
/* falls-through */ | ||
/* falls-through */ | ||
case "-1": | ||
@@ -86,0 +78,0 @@ // -1 is non-computed |
@@ -1,14 +0,17 @@ | ||
var joinURL = require("url-join"); | ||
"use strict"; | ||
var responseHandlers = require("../response.js"), | ||
fetch = require("../request.js").fetch; | ||
const joinURL = require("url-join"); | ||
const responseHandlers = require("../response.js"); | ||
const fetch = require("../request.js").fetch; | ||
function deleteFile(filename, options) { | ||
var fetchURL = joinURL(options.remoteURL, filename), | ||
fetchOptions = { | ||
method: "DELETE", | ||
headers: options.headers | ||
}; | ||
return fetch(fetchURL, fetchOptions) | ||
.then(responseHandlers.handleResponseCode); | ||
const fetchURL = joinURL(options.remoteURL, filename); | ||
const fetchOptions = { | ||
method: "DELETE", | ||
headers: options.headers | ||
}; | ||
return fetch(fetchURL, fetchOptions).then( | ||
responseHandlers.handleResponseCode | ||
); | ||
} | ||
@@ -15,0 +18,0 @@ |
@@ -1,25 +0,27 @@ | ||
var path = require("path"); | ||
"use strict"; | ||
var joinURL = require("url-join"), | ||
deepmerge = require("deepmerge"); | ||
const path = require("path"); | ||
var fetch = require("../request.js").fetch, | ||
responseHandlers = require("../response.js"), | ||
urlTools = require("../url.js"), | ||
davTools = require("./dav.js"); | ||
const joinURL = require("url-join"); | ||
const deepmerge = require("deepmerge"); | ||
var getValueForKey = davTools.getValueForKey, | ||
getSingleValue = davTools.getSingleValue; | ||
const fetch = require("../request.js").fetch; | ||
const responseHandlers = require("../response.js"); | ||
const urlTools = require("../url.js"); | ||
const davTools = require("./dav.js"); | ||
const getValueForKey = davTools.getValueForKey; | ||
const getSingleValue = davTools.getSingleValue; | ||
function getDirectoryContents(remotePath, options) { | ||
var fetchURL = joinURL(options.remoteURL, remotePath), | ||
fetchOptions = { | ||
method: "PROPFIND", | ||
headers: deepmerge( | ||
{ | ||
Depth: 1 | ||
}, | ||
options.headers | ||
) | ||
}; | ||
const fetchURL = joinURL(options.remoteURL, remotePath); | ||
const fetchOptions = { | ||
method: "PROPFIND", | ||
headers: deepmerge( | ||
{ | ||
Depth: 1 | ||
}, | ||
options.headers | ||
) | ||
}; | ||
return fetch(fetchURL, fetchOptions) | ||
@@ -38,30 +40,37 @@ .then(responseHandlers.handleResponseCode) | ||
function getDirectoryFiles(result, serverBasePath, requestPath) { | ||
var remoteTargetPath = path.join(serverBasePath, requestPath); | ||
const remoteTargetPath = path.join(serverBasePath, requestPath); | ||
// Extract the response items (directory contents) | ||
var multiStatus = getValueForKey("multistatus", result), | ||
responseItems = getValueForKey("response", multiStatus); | ||
return responseItems | ||
// Filter out the item pointing to the current directory (not needed) | ||
.filter(function __filterResponseItem(item) { | ||
var href = getSingleValue(getValueForKey("href", item)); | ||
href = urlTools.normaliseHREF(href); | ||
href = urlTools.normalisePath(href); | ||
return (href !== serverBasePath && href !== remoteTargetPath); | ||
}) | ||
// Map all items to a consistent output structure (results) | ||
.map(function __mapResponseItem(item) { | ||
// HREF is the file path (in full) | ||
var href = getSingleValue(getValueForKey("href", item)); | ||
href = urlTools.normaliseHREF(href); | ||
href = decodeURI(href); | ||
href = urlTools.normalisePath(href); | ||
// Each item should contain a stat object | ||
var propStat = getSingleValue(getValueForKey("propstat", item)), | ||
props = getSingleValue(getValueForKey("prop", propStat)); | ||
// Process the true full filename (minus the base server path) | ||
var filename = serverBasePath === "/" ? | ||
href : | ||
urlTools.normalisePath(path.relative(serverBasePath, href)); | ||
return davTools.propsToStat(props, filename); | ||
}); | ||
const multiStatus = getValueForKey("multistatus", result); | ||
const responseItems = getValueForKey("response", multiStatus); | ||
return ( | ||
responseItems | ||
// Filter out the item pointing to the current directory (not needed) | ||
.filter(function __filterResponseItem(item) { | ||
let href = getSingleValue(getValueForKey("href", item)); | ||
href = urlTools.normaliseHREF(href); | ||
href = urlTools.normalisePath(href); | ||
return href !== serverBasePath && href !== remoteTargetPath; | ||
}) | ||
// Map all items to a consistent output structure (results) | ||
.map(function __mapResponseItem(item) { | ||
// HREF is the file path (in full) | ||
let href = getSingleValue(getValueForKey("href", item)); | ||
href = urlTools.normaliseHREF(href); | ||
href = decodeURI(href); | ||
href = urlTools.normalisePath(href); | ||
// Each item should contain a stat object | ||
const propStat = getSingleValue( | ||
getValueForKey("propstat", item) | ||
); | ||
const props = getSingleValue(getValueForKey("prop", propStat)); | ||
// Process the true full filename (minus the base server path) | ||
const filename = | ||
serverBasePath === "/" | ||
? href | ||
: urlTools.normalisePath( | ||
path.relative(serverBasePath, href) | ||
); | ||
return davTools.propsToStat(props, filename); | ||
}) | ||
); | ||
} | ||
@@ -68,0 +77,0 @@ |
@@ -1,28 +0,29 @@ | ||
var joinURL = require("url-join"); | ||
"use strict"; | ||
var responseHandlers = require("../response.js"), | ||
fetch = require("../request.js").fetch; | ||
const joinURL = require("url-join"); | ||
const responseHandlers = require("../response.js"); | ||
const fetch = require("../request.js").fetch; | ||
function getFileContentsBuffer(filePath, options) { | ||
return makeFileRequest(filePath, options) | ||
.then(function(res) { | ||
return res.buffer(); | ||
}); | ||
return makeFileRequest(filePath, options).then(function(res) { | ||
return res.buffer(); | ||
}); | ||
} | ||
function getFileContentsString(filePath, options) { | ||
return makeFileRequest(filePath, options) | ||
.then(function(res) { | ||
return res.text(); | ||
}); | ||
return makeFileRequest(filePath, options).then(function(res) { | ||
return res.text(); | ||
}); | ||
} | ||
function makeFileRequest(filePath, options) { | ||
var fetchURL = joinURL(options.remoteURL, filePath), | ||
fetchOptions = { | ||
method: "GET", | ||
headers: options.headers | ||
}; | ||
return fetch(fetchURL, fetchOptions) | ||
.then(responseHandlers.handleResponseCode); | ||
const fetchURL = joinURL(options.remoteURL, filePath); | ||
const fetchOptions = { | ||
method: "GET", | ||
headers: options.headers | ||
}; | ||
return fetch(fetchURL, fetchOptions).then( | ||
responseHandlers.handleResponseCode | ||
); | ||
} | ||
@@ -29,0 +30,0 @@ |
@@ -1,20 +0,23 @@ | ||
var joinURL = require("url-join"), | ||
deepmerge = require("deepmerge"); | ||
"use strict"; | ||
var responseHandlers = require("../response.js"), | ||
fetch = require("../request.js").fetch; | ||
const joinURL = require("url-join"); | ||
const deepmerge = require("deepmerge"); | ||
const responseHandlers = require("../response.js"); | ||
const fetch = require("../request.js").fetch; | ||
function moveFile(filename, destination, options) { | ||
var fetchURL = joinURL(options.remoteURL, filename), | ||
fetchOptions = { | ||
method: "MOVE", | ||
headers: deepmerge( | ||
{ | ||
Destination: joinURL(options.remoteURL, destination) | ||
}, | ||
options.headers | ||
) | ||
}; | ||
return fetch(fetchURL, fetchOptions) | ||
.then(responseHandlers.handleResponseCode); | ||
const fetchURL = joinURL(options.remoteURL, filename); | ||
const fetchOptions = { | ||
method: "MOVE", | ||
headers: deepmerge( | ||
{ | ||
Destination: joinURL(options.remoteURL, destination) | ||
}, | ||
options.headers | ||
) | ||
}; | ||
return fetch(fetchURL, fetchOptions).then( | ||
responseHandlers.handleResponseCode | ||
); | ||
} | ||
@@ -21,0 +24,0 @@ |
@@ -1,7 +0,9 @@ | ||
var deepmerge = require("deepmerge"), | ||
joinURL = require("url-join"); | ||
"use strict"; | ||
var responseHandlers = require("../response.js"), | ||
fetch = require("../request.js").fetch; | ||
const deepmerge = require("deepmerge"); | ||
const joinURL = require("url-join"); | ||
const responseHandlers = require("../response.js"); | ||
const fetch = require("../request.js").fetch; | ||
function getPutContentsDefaults() { | ||
@@ -17,3 +19,3 @@ return { | ||
function putFileContents(filePath, data, options) { | ||
var putOptions = deepmerge.all([ | ||
const putOptions = deepmerge.all([ | ||
getPutContentsDefaults(), | ||
@@ -26,10 +28,11 @@ { headers: { "Content-Length": data.length } }, | ||
} | ||
var fetchURL = joinURL(options.remoteURL, filePath), | ||
fetchOptions = { | ||
method: "PUT", | ||
headers: putOptions.headers, | ||
body: data | ||
}; | ||
return fetch(fetchURL, fetchOptions) | ||
.then(responseHandlers.handleResponseCode); | ||
const fetchURL = joinURL(options.remoteURL, filePath); | ||
const fetchOptions = { | ||
method: "PUT", | ||
headers: putOptions.headers, | ||
body: data | ||
}; | ||
return fetch(fetchURL, fetchOptions).then( | ||
responseHandlers.handleResponseCode | ||
); | ||
} | ||
@@ -36,0 +39,0 @@ |
@@ -1,21 +0,20 @@ | ||
var deepmerge = require("deepmerge"); | ||
"use strict"; | ||
var responseHandlers = require("../response.js"), | ||
fetch = require("../request.js").fetch, | ||
davTools = require("./dav.js"), | ||
parseXML = require("./dav.js").parseXML; | ||
const deepmerge = require("deepmerge"); | ||
var getValueForKey = davTools.getValueForKey, | ||
getSingleValue = davTools.getSingleValue, | ||
translateDiskSpace = davTools.translateDiskSpace; | ||
const responseHandlers = require("../response.js"); | ||
const fetch = require("../request.js").fetch; | ||
const davTools = require("./dav.js"); | ||
const parseXML = require("./dav.js").parseXML; | ||
const getValueForKey = davTools.getValueForKey; | ||
const getSingleValue = davTools.getSingleValue; | ||
const translateDiskSpace = davTools.translateDiskSpace; | ||
function getQuota(options) { | ||
var fetchURL = options.remoteURL + "/", | ||
fetchOptions = { | ||
method: "PROPFIND", | ||
headers: deepmerge( | ||
{ Depth: 0 }, | ||
options.headers | ||
) | ||
}; | ||
let fetchURL = options.remoteURL + "/"; | ||
const fetchOptions = { | ||
method: "PROPFIND", | ||
headers: deepmerge({ Depth: 0 }, options.headers) | ||
}; | ||
fetchURL = fetchURL.replace(/\/+$/g, "/"); | ||
@@ -32,3 +31,3 @@ return fetch(fetchURL, fetchOptions) | ||
function parseQuota(result) { | ||
var responseItem = null, | ||
let responseItem = null, | ||
multistatus, | ||
@@ -42,3 +41,5 @@ propstat, | ||
responseItem = getSingleValue(getValueForKey("response", multistatus)); | ||
} catch (e) { /* ignore */ } | ||
} catch (e) { | ||
/* ignore */ | ||
} | ||
if (responseItem) { | ||
@@ -48,9 +49,12 @@ propstat = getSingleValue(getValueForKey("propstat", responseItem)); | ||
quotaUsed = getSingleValue(getValueForKey("quota-used-bytes", props)); | ||
quotaAvail = getSingleValue(getValueForKey("quota-available-bytes", props)); | ||
return (typeof quotaUsed !== "undefined" && typeof quotaAvail !== "undefined") ? | ||
{ | ||
used: parseInt(quotaUsed, 10), | ||
available: translateDiskSpace(quotaAvail) | ||
} : | ||
null; | ||
quotaAvail = getSingleValue( | ||
getValueForKey("quota-available-bytes", props) | ||
); | ||
return typeof quotaUsed !== "undefined" && | ||
typeof quotaAvail !== "undefined" | ||
? { | ||
used: parseInt(quotaUsed, 10), | ||
available: translateDiskSpace(quotaAvail) | ||
} | ||
: null; | ||
} | ||
@@ -57,0 +61,0 @@ return null; |
@@ -1,22 +0,21 @@ | ||
var joinURL = require("url-join"), | ||
deepmerge = require("deepmerge"); | ||
"use strict"; | ||
var responseHandlers = require("../response.js"), | ||
fetch = require("../request.js").fetch, | ||
davTools = require("./dav.js"), | ||
parseXML = require("./dav.js").parseXML, | ||
urlTools = require("../url.js"); | ||
const joinURL = require("url-join"); | ||
const deepmerge = require("deepmerge"); | ||
var getValueForKey = davTools.getValueForKey, | ||
getSingleValue = davTools.getSingleValue; | ||
const responseHandlers = require("../response.js"); | ||
const fetch = require("../request.js").fetch; | ||
const davTools = require("./dav.js"); | ||
const parseXML = require("./dav.js").parseXML; | ||
const urlTools = require("../url.js"); | ||
const getValueForKey = davTools.getValueForKey; | ||
const getSingleValue = davTools.getSingleValue; | ||
function getStat(filename, options) { | ||
var fetchURL = joinURL(options.remoteURL, filename), | ||
fetchOptions = { | ||
method: "PROPFIND", | ||
headers: deepmerge( | ||
{ Depth: 0 }, | ||
options.headers | ||
) | ||
}; | ||
const fetchURL = joinURL(options.remoteURL, filename); | ||
const fetchOptions = { | ||
method: "PROPFIND", | ||
headers: deepmerge({ Depth: 0 }, options.headers) | ||
}; | ||
return fetch(fetchURL, fetchOptions) | ||
@@ -34,3 +33,3 @@ .then(responseHandlers.handleResponseCode) | ||
function parseStat(result, filename) { | ||
var responseItem = null, | ||
let responseItem = null, | ||
multistatus; | ||
@@ -40,9 +39,11 @@ try { | ||
responseItem = getSingleValue(getValueForKey("response", multistatus)); | ||
} catch (e) { /* ignore */ } | ||
} catch (e) { | ||
/* ignore */ | ||
} | ||
if (!responseItem) { | ||
throw new Error("Failed getting item stat: bad response"); | ||
} | ||
var propStat = getSingleValue(getValueForKey("propstat", responseItem)), | ||
props = getSingleValue(getValueForKey("prop", propStat)); | ||
var filePath = urlTools.normalisePath(filename); | ||
const propStat = getSingleValue(getValueForKey("propstat", responseItem)); | ||
const props = getSingleValue(getValueForKey("prop", propStat)); | ||
const filePath = urlTools.normalisePath(filename); | ||
return davTools.propsToStat(props, filePath); | ||
@@ -49,0 +50,0 @@ } |
@@ -1,5 +0,7 @@ | ||
var nodeFetch = require("node-fetch"); | ||
"use strict"; | ||
var fetchMethod = nodeFetch; | ||
const nodeFetch = require("node-fetch"); | ||
let fetchMethod = nodeFetch; | ||
function request(url, options) { | ||
@@ -6,0 +8,0 @@ return fetchMethod(url, options); |
@@ -0,6 +1,10 @@ | ||
"use strict"; | ||
function handleResponseCode(response) { | ||
var status = parseInt(response.status, 10), | ||
err; | ||
const status = parseInt(response.status, 10); | ||
let err; | ||
if (status >= 400) { | ||
err = new Error("Invalid response: " + status + " " + response.statusText); | ||
err = new Error( | ||
"Invalid response: " + status + " " + response.statusText | ||
); | ||
err.status = status; | ||
@@ -13,5 +17,3 @@ throw err; | ||
module.exports = { | ||
handleResponseCode: handleResponseCode | ||
}; |
@@ -1,7 +0,7 @@ | ||
var create = require("./index.js"); | ||
var client = create( | ||
"https://storage.perry.cx/remote.php/webdav", | ||
"pez", | ||
"a2IiLV_ouTZIDt8k8PV-jQNL" | ||
); | ||
// var create = require("./index.js"); | ||
// var client = create( | ||
// "https://storage.perry.cx/remote.php/webdav", | ||
// "pez", | ||
// "a2IiLV_ouTZIDt8k8PV-jQNL" | ||
// ); | ||
@@ -30,2 +30,2 @@ // client.getDirectoryContents("/Software").then(function(contents) { | ||
client.stat("/Temp/apps.png").then(stat => console.log(stat)); | ||
// client.stat("/Temp/apps.png").then(stat => console.log(stat)); |
@@ -1,6 +0,8 @@ | ||
var URL = require("url-parse"); | ||
"use strict"; | ||
const URL = require("url-parse"); | ||
function extractURLPath(fullURL) { | ||
var url = new URL(fullURL), | ||
urlPath = url.pathname; | ||
const url = new URL(fullURL); | ||
let urlPath = url.pathname; | ||
if (urlPath.length <= 0) { | ||
@@ -13,3 +15,3 @@ urlPath = "/"; | ||
function normaliseHREF(href) { | ||
var normalisedHref = href.replace(/^https?:\/\/[^\/]+/, ""); | ||
const normalisedHref = href.replace(/^https?:\/\/[^\/]+/, ""); | ||
return normalisedHref; | ||
@@ -19,3 +21,3 @@ } | ||
function normalisePath(pathStr) { | ||
var normalisedPath = pathStr; | ||
let normalisedPath = pathStr; | ||
if (normalisedPath[0] !== "/") { | ||
@@ -22,0 +24,0 @@ normalisedPath = "/" + normalisedPath; |
@@ -1,4 +0,6 @@ | ||
var path = require("path"), | ||
ws = require("webdav-server").v2; | ||
"use strict"; | ||
const path = require("path"); | ||
const ws = require("webdav-server").v2; | ||
function createServer(dir, authType) { | ||
@@ -8,10 +10,11 @@ if (!dir) { | ||
} | ||
var userManager = new ws.SimpleUserManager(); | ||
var user = userManager.addUser("webdav-user", "pa$$w0rd!"); | ||
var auth = (!authType || authType === "basic") ? | ||
new ws.HTTPBasicAuthentication(userManager) : | ||
new ws.HTTPDigestAuthentication(userManager, "test"); | ||
var privilegeManager = new ws.SimplePathPrivilegeManager(); | ||
privilegeManager.setRights(user, "/", [ "all" ]); | ||
var server = new ws.WebDAVServer({ | ||
const userManager = new ws.SimpleUserManager(); | ||
const user = userManager.addUser("webdav-user", "pa$$w0rd!"); | ||
const auth = | ||
!authType || authType === "basic" | ||
? new ws.HTTPBasicAuthentication(userManager) | ||
: new ws.HTTPDigestAuthentication(userManager, "test"); | ||
const privilegeManager = new ws.SimplePathPrivilegeManager(); | ||
privilegeManager.setRights(user, "/", ["all"]); | ||
const server = new ws.WebDAVServer({ | ||
port: 9988, | ||
@@ -22,8 +25,11 @@ httpAuthentication: auth, | ||
return { | ||
start: function start() { | ||
return new Promise(function(resolve) { | ||
server.setFileSystem("/webdav/server", new ws.PhysicalFileSystem(dir), function() { | ||
server.start(resolve); | ||
}); | ||
server.setFileSystem( | ||
"/webdav/server", | ||
new ws.PhysicalFileSystem(dir), | ||
function() { | ||
server.start(resolve); | ||
} | ||
); | ||
}); | ||
@@ -37,5 +43,4 @@ }, | ||
} | ||
}; | ||
}; | ||
} | ||
@@ -49,8 +54,5 @@ createServer.test = { | ||
createServer.webdavClient = function(authType) { | ||
return createServer( | ||
path.resolve(__dirname, "../testContents"), | ||
authType | ||
); | ||
return createServer(path.resolve(__dirname, "../testContents"), authType); | ||
}; | ||
module.exports = createServer; |
@@ -1,6 +0,7 @@ | ||
var path = require("path"), | ||
directoryExists = require("directory-exists").sync; | ||
"use strict"; | ||
const path = require("path"); | ||
const directoryExists = require("directory-exists").sync; | ||
describe("createDirectory", function() { | ||
beforeEach(function() { | ||
@@ -22,3 +23,3 @@ this.client = createWebDAVClient( | ||
it("creates directories", function() { | ||
var newDir = path.resolve(__dirname, "../testContents/sub2"); | ||
const newDir = path.resolve(__dirname, "../testContents/sub2"); | ||
expect(directoryExists(newDir)).to.be.false; | ||
@@ -29,3 +30,2 @@ return this.client.createDirectory("/sub2").then(function() { | ||
}); | ||
}); |
@@ -1,5 +0,7 @@ | ||
var ReadableStream = require("stream").Readable; | ||
"use strict"; | ||
const ReadableStream = require("stream").Readable; | ||
function streamToBuffer(stream) { | ||
var buffs = []; | ||
const buffs = []; | ||
return new Promise(function(resolve) { | ||
@@ -16,3 +18,2 @@ stream.on("data", function(d) { | ||
describe("createReadStream", function() { | ||
beforeEach(function() { | ||
@@ -34,3 +35,3 @@ this.client = createWebDAVClient( | ||
it("streams contents of a remote file", function() { | ||
var stream = this.client.createReadStream("/alrighty.jpg"); | ||
const stream = this.client.createReadStream("/alrighty.jpg"); | ||
expect(stream instanceof ReadableStream).to.be.true; | ||
@@ -43,25 +44,27 @@ return streamToBuffer(stream).then(function(buff) { | ||
it("streams portions (ranges) of a remote file", function() { | ||
var stream1 = this.client.createReadStream("/alrighty.jpg", { range: { start: 0, end: 24999 } }), | ||
stream2 = this.client.createReadStream("/alrighty.jpg", { range: { start: 25000, end: 52129 } }); | ||
return Promise | ||
.all([ | ||
streamToBuffer(stream1), | ||
streamToBuffer(stream2) | ||
]) | ||
.then(function(buffers) { | ||
var part1 = buffers.shift(), | ||
part2 = buffers.shift(); | ||
expect(part1.length).to.equal(25000); | ||
expect(part2.length).to.equal(27130); | ||
}); | ||
const stream1 = this.client.createReadStream("/alrighty.jpg", { | ||
range: { start: 0, end: 24999 } | ||
}); | ||
const stream2 = this.client.createReadStream("/alrighty.jpg", { | ||
range: { start: 25000, end: 52129 } | ||
}); | ||
return Promise.all([ | ||
streamToBuffer(stream1), | ||
streamToBuffer(stream2) | ||
]).then(function(buffers) { | ||
const part1 = buffers.shift(); | ||
const part2 = buffers.shift(); | ||
expect(part1.length).to.equal(25000); | ||
expect(part2.length).to.equal(27130); | ||
}); | ||
}); | ||
it("streams a partial file when only the start is provided", function() { | ||
var stream = this.client.createReadStream("/alrighty.jpg", { range: { start: 25000 } }); | ||
return streamToBuffer(stream) | ||
.then(function(buff) { | ||
expect(buff.length).to.equal(27130); | ||
}); | ||
const stream = this.client.createReadStream("/alrighty.jpg", { | ||
range: { start: 25000 } | ||
}); | ||
return streamToBuffer(stream).then(function(buff) { | ||
expect(buff.length).to.equal(27130); | ||
}); | ||
}); | ||
}); |
@@ -1,8 +0,10 @@ | ||
var path = require("path"), | ||
fs = require("fs"), | ||
PassThrough = require("stream").PassThrough, | ||
waitOn = require("wait-on"); | ||
"use strict"; | ||
var SOURCE_FILENAME = path.resolve(__dirname, "../testContents/alrighty.jpg"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const PassThrough = require("stream").PassThrough; | ||
const waitOn = require("wait-on"); | ||
const SOURCE_FILENAME = path.resolve(__dirname, "../testContents/alrighty.jpg"); | ||
function waitOnFile(filename) { | ||
@@ -12,7 +14,8 @@ return new Promise(function(resolve, reject) { | ||
{ | ||
resources: [ filename ], | ||
resources: [filename], | ||
interval: 50, | ||
timeout: 500, | ||
window: 0 | ||
}, function(err) { | ||
}, | ||
function(err) { | ||
if (err) { | ||
@@ -28,3 +31,2 @@ return reject(err); | ||
describe("createWriteStream", function() { | ||
beforeEach(function() { | ||
@@ -46,5 +48,8 @@ this.client = createWebDAVClient( | ||
it("writes the file to the remote", function() { | ||
var targetFile = path.resolve(__dirname, "../testContents/alrighty2.jpg"); | ||
var writeStream = this.client.createWriteStream("/alrighty2.jpg"), | ||
readStream = fs.createReadStream(SOURCE_FILENAME); | ||
const targetFile = path.resolve( | ||
__dirname, | ||
"../testContents/alrighty2.jpg" | ||
); | ||
const writeStream = this.client.createWriteStream("/alrighty2.jpg"); | ||
const readStream = fs.createReadStream(SOURCE_FILENAME); | ||
expect(writeStream instanceof PassThrough).to.be.true; | ||
@@ -54,4 +59,3 @@ return new Promise(function(resolve, reject) { | ||
// stupid stream needs time to close probably.. | ||
waitOnFile(targetFile) | ||
.then(resolve, reject); | ||
waitOnFile(targetFile).then(resolve, reject); | ||
}); | ||
@@ -62,3 +66,2 @@ writeStream.on("error", reject); | ||
}); | ||
}); |
@@ -1,10 +0,14 @@ | ||
var path = require("path"), | ||
fileExists = require("exists-file").sync, | ||
directoryExists = require("directory-exists").sync; | ||
"use strict"; | ||
var localFilePath = path.resolve(__dirname, "../testContents/text document.txt"), | ||
localDirPath = path.resolve(__dirname, "../testContents/sub1"); | ||
const path = require("path"); | ||
const fileExists = require("exists-file").sync; | ||
const directoryExists = require("directory-exists").sync; | ||
const localFilePath = path.resolve( | ||
__dirname, | ||
"../testContents/text document.txt" | ||
); | ||
const localDirPath = path.resolve(__dirname, "../testContents/sub1"); | ||
describe("deleteFile", function() { | ||
beforeEach(function() { | ||
@@ -27,6 +31,5 @@ this.client = createWebDAVClient( | ||
expect(fileExists(localFilePath)).to.be.true; | ||
return this.client.deleteFile("/text document.txt") | ||
.then(() => { | ||
expect(fileExists(localFilePath)).to.be.false; | ||
}); | ||
return this.client.deleteFile("/text document.txt").then(() => { | ||
expect(fileExists(localFilePath)).to.be.false; | ||
}); | ||
}); | ||
@@ -36,6 +39,5 @@ | ||
expect(fileExists(localFilePath)).to.be.true; | ||
return this.client.deleteFile("/text document.txt") | ||
.then(() => { | ||
expect(fileExists(localFilePath)).to.be.false; | ||
}); | ||
return this.client.deleteFile("/text document.txt").then(() => { | ||
expect(fileExists(localFilePath)).to.be.false; | ||
}); | ||
}); | ||
@@ -45,8 +47,6 @@ | ||
expect(directoryExists(localDirPath)).to.be.true; | ||
return this.client.deleteFile("/sub1") | ||
.then(() => { | ||
expect(directoryExists(localDirPath)).to.be.false; | ||
}); | ||
return this.client.deleteFile("/sub1").then(() => { | ||
expect(directoryExists(localDirPath)).to.be.false; | ||
}); | ||
}); | ||
}); |
@@ -0,3 +1,4 @@ | ||
"use strict"; | ||
describe("getDirectoryContents", function() { | ||
beforeEach(function() { | ||
@@ -27,3 +28,3 @@ this.client = createWebDAVClient( | ||
return this.client.getDirectoryContents("/").then(function(contents) { | ||
var sub1 = contents.find(function(item) { | ||
const sub1 = contents.find(function(item) { | ||
return item.basename === "sub1"; | ||
@@ -38,8 +39,10 @@ }); | ||
it("returns results not including base directory", function() { | ||
return this.client.getDirectoryContents("/sub1").then(function(contents) { | ||
var sub1 = contents.find(function(item) { | ||
return item.basename === "sub1"; | ||
return this.client | ||
.getDirectoryContents("/sub1") | ||
.then(function(contents) { | ||
const sub1 = contents.find(function(item) { | ||
return item.basename === "sub1"; | ||
}); | ||
expect(sub1).to.be.undefined; | ||
}); | ||
expect(sub1).to.be.undefined; | ||
}); | ||
}); | ||
@@ -49,3 +52,3 @@ | ||
return this.client.getDirectoryContents("/").then(function(contents) { | ||
var sub1 = contents.find(function(item) { | ||
const sub1 = contents.find(function(item) { | ||
return item.basename === "alrighty.jpg"; | ||
@@ -60,20 +63,23 @@ }); | ||
it("returns correct file results in sub-directory", function() { | ||
return this.client.getDirectoryContents("/sub1").then(function(contents) { | ||
var sub1 = contents.find(function(item) { | ||
return item.basename === "irrelephant.jpg"; | ||
return this.client | ||
.getDirectoryContents("/sub1") | ||
.then(function(contents) { | ||
const sub1 = contents.find(function(item) { | ||
return item.basename === "irrelephant.jpg"; | ||
}); | ||
expect(sub1.filename).to.equal("/sub1/irrelephant.jpg"); | ||
expect(sub1.size).to.equal(138008); | ||
expect(sub1.type).to.equal("file"); | ||
}); | ||
expect(sub1.filename).to.equal("/sub1/irrelephant.jpg"); | ||
expect(sub1.size).to.equal(138008); | ||
expect(sub1.type).to.equal("file"); | ||
}); | ||
}); | ||
it("returns the contents of a directory with repetitive naming", function() { | ||
return this.client.getDirectoryContents("/webdav/server").then(function(contents) { | ||
expect(contents).to.be.an.array; | ||
expect(contents[0]).to.be.an.object; | ||
expect(contents[0]).to.have.property("basename", "notreal.txt"); | ||
}); | ||
return this.client | ||
.getDirectoryContents("/webdav/server") | ||
.then(function(contents) { | ||
expect(contents).to.be.an.array; | ||
expect(contents[0]).to.be.an.object; | ||
expect(contents[0]).to.have.property("basename", "notreal.txt"); | ||
}); | ||
}); | ||
}); |
@@ -1,11 +0,12 @@ | ||
var path = require("path"), | ||
fs = require("fs"); | ||
"use strict"; | ||
var bufferEquals = require("buffer-equals"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
var SOURCE_BIN = path.resolve(__dirname, "../testContents/alrighty.jpg"), | ||
SOURCE_TXT = path.resolve(__dirname, "../testContents/text document.txt"); | ||
const bufferEquals = require("buffer-equals"); | ||
const SOURCE_BIN = path.resolve(__dirname, "../testContents/alrighty.jpg"); | ||
const SOURCE_TXT = path.resolve(__dirname, "../testContents/text document.txt"); | ||
describe("getFileContents", function() { | ||
beforeEach(function() { | ||
@@ -27,15 +28,18 @@ this.client = createWebDAVClient( | ||
it("reads a remote file into a buffer", function() { | ||
return this.client.getFileContents("/alrighty.jpg").then(function(bufferRemote) { | ||
var bufferLocal = fs.readFileSync(SOURCE_BIN); | ||
expect(bufferEquals(bufferRemote, bufferLocal)).to.be.true; | ||
}); | ||
return this.client | ||
.getFileContents("/alrighty.jpg") | ||
.then(function(bufferRemote) { | ||
const bufferLocal = fs.readFileSync(SOURCE_BIN); | ||
expect(bufferEquals(bufferRemote, bufferLocal)).to.be.true; | ||
}); | ||
}); | ||
it("reads a remote file into a string", function() { | ||
return this.client.getFileContents("/text document.txt", { format: "text" }).then(function(stringRemote) { | ||
var stringLocal = fs.readFileSync(SOURCE_TXT, "utf8"); | ||
expect(stringRemote).to.equal(stringLocal); | ||
}); | ||
return this.client | ||
.getFileContents("/text document.txt", { format: "text" }) | ||
.then(function(stringRemote) { | ||
const stringLocal = fs.readFileSync(SOURCE_TXT, "utf8"); | ||
expect(stringRemote).to.equal(stringLocal); | ||
}); | ||
}); | ||
}); |
@@ -1,14 +0,25 @@ | ||
var fs = require("fs"), | ||
path = require("path"); | ||
"use strict"; | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
function useInvalidQuota() { | ||
returnFakeResponse(fs.readFileSync(path.resolve(__dirname, "../responses/quota-invalid.xml"), "utf8")); | ||
returnFakeResponse( | ||
fs.readFileSync( | ||
path.resolve(__dirname, "../responses/quota-invalid.xml"), | ||
"utf8" | ||
) | ||
); | ||
} | ||
function useValidQuota() { | ||
returnFakeResponse(fs.readFileSync(path.resolve(__dirname, "../responses/quota-valid.xml"), "utf8")); | ||
returnFakeResponse( | ||
fs.readFileSync( | ||
path.resolve(__dirname, "../responses/quota-valid.xml"), | ||
"utf8" | ||
) | ||
); | ||
} | ||
describe("getQuota", function() { | ||
beforeEach(function() { | ||
@@ -49,3 +60,2 @@ // fake client, not actually used when mocking responses | ||
}); | ||
}); |
@@ -0,20 +1,25 @@ | ||
"use strict"; | ||
require("./polyfill.js"); | ||
var path = require("path"); | ||
const path = require("path"); | ||
var createWebDAVClient = require("../../source/index.js"), | ||
baseWebDAVServer = require("../server/index.js"); | ||
const createWebDAVClient = require("../../dist/index.js"); | ||
const baseWebDAVServer = require("../server/index.js"); | ||
var createWebDAVServer = baseWebDAVServer.webdavClient; | ||
const createWebDAVServer = baseWebDAVServer.webdavClient; | ||
createWebDAVServer.test = baseWebDAVServer.test; | ||
var expect = require("chai").expect, | ||
sinon = require("sinon"), | ||
rimraf = require("rimraf").sync, | ||
copyDir = require("copy-dir").sync; | ||
const expect = require("chai").expect; | ||
const sinon = require("sinon"); | ||
const rimraf = require("rimraf").sync; | ||
const copyDir = require("copy-dir").sync; | ||
function clean() { | ||
rimraf(path.resolve(__dirname, "../testContents")); | ||
copyDir(path.resolve(__dirname, "../serverContents"), path.resolve(__dirname, "../testContents")); | ||
copyDir( | ||
path.resolve(__dirname, "../serverContents"), | ||
path.resolve(__dirname, "../testContents") | ||
); | ||
} | ||
@@ -21,0 +26,0 @@ |
@@ -1,7 +0,8 @@ | ||
var path = require("path"), | ||
fileExists = require("exists-file").sync, | ||
directoryExists = require("directory-exists").sync; | ||
"use strict"; | ||
const path = require("path"); | ||
const fileExists = require("exists-file").sync; | ||
const directoryExists = require("directory-exists").sync; | ||
describe("moveFile", function() { | ||
beforeEach(function() { | ||
@@ -23,10 +24,18 @@ this.client = createWebDAVClient( | ||
it("moves files from one directory to another", function() { | ||
return this.client.moveFile("/alrighty.jpg", "/sub1/alrighty.jpg") | ||
return this.client | ||
.moveFile("/alrighty.jpg", "/sub1/alrighty.jpg") | ||
.then(function() { | ||
expect(fileExists( | ||
path.resolve(__dirname, "../testContents/alrighty.jpg") | ||
)).to.be.false; | ||
expect(fileExists( | ||
path.resolve(__dirname, "../testContents/sub1/alrighty.jpg") | ||
)).to.be.true; | ||
expect( | ||
fileExists( | ||
path.resolve(__dirname, "../testContents/alrighty.jpg") | ||
) | ||
).to.be.false; | ||
expect( | ||
fileExists( | ||
path.resolve( | ||
__dirname, | ||
"../testContents/sub1/alrighty.jpg" | ||
) | ||
) | ||
).to.be.true; | ||
}); | ||
@@ -36,25 +45,32 @@ }); | ||
it("moves directories from one directory to another", function() { | ||
return this.client.moveFile("/webdav", "/sub1/webdav") | ||
.then(function() { | ||
expect(directoryExists( | ||
return this.client.moveFile("/webdav", "/sub1/webdav").then(function() { | ||
expect( | ||
directoryExists( | ||
path.resolve(__dirname, "../testContents/webdav") | ||
)).to.be.false; | ||
expect(directoryExists( | ||
) | ||
).to.be.false; | ||
expect( | ||
directoryExists( | ||
path.resolve(__dirname, "../testContents/sub1/webdav") | ||
)).to.be.true; | ||
}); | ||
) | ||
).to.be.true; | ||
}); | ||
}); | ||
it("moves files from one name to another", function() { | ||
return this.client.moveFile("/alrighty.jpg", "/renamed.jpg") | ||
return this.client | ||
.moveFile("/alrighty.jpg", "/renamed.jpg") | ||
.then(function() { | ||
expect(fileExists( | ||
path.resolve(__dirname, "../testContents/alrighty.jpg") | ||
)).to.be.false; | ||
expect(fileExists( | ||
path.resolve(__dirname, "../testContents/renamed.jpg") | ||
)).to.be.true; | ||
expect( | ||
fileExists( | ||
path.resolve(__dirname, "../testContents/alrighty.jpg") | ||
) | ||
).to.be.false; | ||
expect( | ||
fileExists( | ||
path.resolve(__dirname, "../testContents/renamed.jpg") | ||
) | ||
).to.be.true; | ||
}); | ||
}); | ||
}); |
@@ -0,6 +1,7 @@ | ||
"use strict"; | ||
/* eslint-disable */ | ||
// https://tc39.github.io/ecma262/#sec-array.prototype.find | ||
if (!Array.prototype.find) { | ||
Object.defineProperty(Array.prototype, 'find', { | ||
Object.defineProperty(Array.prototype, "find", { | ||
value: function (predicate) { | ||
@@ -12,17 +13,17 @@ // 1. Let O be ? ToObject(this value). | ||
var o = Object(this); | ||
const o = Object(this); | ||
// 2. Let len be ? ToLength(? Get(O, "length")). | ||
var len = o.length >>> 0; | ||
const len = o.length >>> 0; | ||
// 3. If IsCallable(predicate) is false, throw a TypeError exception. | ||
if (typeof predicate !== 'function') { | ||
throw new TypeError('predicate must be a function'); | ||
if (typeof predicate !== "function") { | ||
throw new TypeError("predicate must be a function"); | ||
} | ||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined. | ||
var thisArg = arguments[1]; | ||
const thisArg = arguments[1]; | ||
// 5. Let k be 0. | ||
var k = 0; | ||
let k = 0; | ||
@@ -35,3 +36,3 @@ // 6. Repeat, while k < len | ||
// d. If testResult is true, return kValue. | ||
var kValue = o[k]; | ||
const kValue = o[k]; | ||
if (predicate.call(thisArg, kValue, k, o)) { | ||
@@ -38,0 +39,0 @@ return kValue; |
@@ -1,12 +0,13 @@ | ||
var path = require("path"), | ||
fs = require("fs"); | ||
"use strict"; | ||
var bufferEquals = require("buffer-equals"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
var SOURCE_BIN = path.resolve(__dirname, "../testContents/alrighty.jpg"), | ||
TARGET_BIN = path.resolve(__dirname, "../testContents/sub1/alrighty.jpg"), | ||
TARGET_TXT = path.resolve(__dirname, "../testContents/newFile.txt"); | ||
const bufferEquals = require("buffer-equals"); | ||
const SOURCE_BIN = path.resolve(__dirname, "../testContents/alrighty.jpg"); | ||
const TARGET_BIN = path.resolve(__dirname, "../testContents/sub1/alrighty.jpg"); | ||
const TARGET_TXT = path.resolve(__dirname, "../testContents/newFile.txt"); | ||
describe("getFileContents", function() { | ||
beforeEach(function() { | ||
@@ -28,6 +29,7 @@ this.client = createWebDAVClient( | ||
it("writes binary files", function() { | ||
var imgBin = fs.readFileSync(SOURCE_BIN); | ||
return this.client.putFileContents("/sub1/alrighty.jpg", imgBin) | ||
const imgBin = fs.readFileSync(SOURCE_BIN); | ||
return this.client | ||
.putFileContents("/sub1/alrighty.jpg", imgBin) | ||
.then(function() { | ||
var written = fs.readFileSync(TARGET_BIN); | ||
const written = fs.readFileSync(TARGET_BIN); | ||
expect(bufferEquals(written, imgBin)).to.be.true; | ||
@@ -38,10 +40,10 @@ }); | ||
it("writes text files", function() { | ||
var text = "this is\nsome text\ncontent\t...\n"; | ||
return this.client.putFileContents("/newFile.txt", text) | ||
const text = "this is\nsome text\ncontent\t...\n"; | ||
return this.client | ||
.putFileContents("/newFile.txt", text) | ||
.then(function() { | ||
var written = fs.readFileSync(TARGET_TXT, "utf8"); | ||
const written = fs.readFileSync(TARGET_TXT, "utf8"); | ||
expect(written).to.equal(text); | ||
}); | ||
}); | ||
}); |
@@ -0,3 +1,4 @@ | ||
"use strict"; | ||
describe("stat", function() { | ||
beforeEach(function() { | ||
@@ -19,38 +20,34 @@ this.client = createWebDAVClient( | ||
it("correctly stats files", function() { | ||
return this.client.stat("/alrighty.jpg") | ||
.then(function(stat) { | ||
expect(stat).to.be.an.object; | ||
expect(stat).to.have.property("filename", "/alrighty.jpg"); | ||
expect(stat).to.have.property("basename", "alrighty.jpg"); | ||
expect(stat).to.have.property("lastmod").that.is.a.string; | ||
expect(stat).to.have.property("type", "file"); | ||
expect(stat).to.have.property("size", 52130); | ||
expect(stat).to.have.property("mime", "image/jpeg"); | ||
}); | ||
return this.client.stat("/alrighty.jpg").then(function(stat) { | ||
expect(stat).to.be.an.object; | ||
expect(stat).to.have.property("filename", "/alrighty.jpg"); | ||
expect(stat).to.have.property("basename", "alrighty.jpg"); | ||
expect(stat).to.have.property("lastmod").that.is.a.string; | ||
expect(stat).to.have.property("type", "file"); | ||
expect(stat).to.have.property("size", 52130); | ||
expect(stat).to.have.property("mime", "image/jpeg"); | ||
}); | ||
}); | ||
it("correctly stats directories", function() { | ||
return this.client.stat("/webdav/server") | ||
.then(function(stat) { | ||
expect(stat).to.be.an.object; | ||
expect(stat).to.have.property("filename", "/webdav/server"); | ||
expect(stat).to.have.property("basename", "server"); | ||
expect(stat).to.have.property("lastmod").that.is.a.string; | ||
expect(stat).to.have.property("type", "directory"); | ||
expect(stat).to.have.property("size", 0); | ||
}); | ||
return this.client.stat("/webdav/server").then(function(stat) { | ||
expect(stat).to.be.an.object; | ||
expect(stat).to.have.property("filename", "/webdav/server"); | ||
expect(stat).to.have.property("basename", "server"); | ||
expect(stat).to.have.property("lastmod").that.is.a.string; | ||
expect(stat).to.have.property("type", "directory"); | ||
expect(stat).to.have.property("size", 0); | ||
}); | ||
}); | ||
it("stats the root", function() { | ||
return this.client.stat("/") | ||
.then(function(stat) { | ||
expect(stat).to.be.an.object; | ||
expect(stat).to.have.property("filename", "/"); | ||
expect(stat).to.have.property("basename", ""); | ||
expect(stat).to.have.property("lastmod").that.is.a.string; | ||
expect(stat).to.have.property("type", "directory"); | ||
expect(stat).to.have.property("size", 0); | ||
}); | ||
return this.client.stat("/").then(function(stat) { | ||
expect(stat).to.be.an.object; | ||
expect(stat).to.have.property("filename", "/"); | ||
expect(stat).to.have.property("basename", ""); | ||
expect(stat).to.have.property("lastmod").that.is.a.string; | ||
expect(stat).to.have.property("type", "directory"); | ||
expect(stat).to.have.property("size", 0); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
482371
67
2002
18
20