Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Added webdav error handling

Borislav Sapundzhiev19e7db8cf23b
diff --git a/.gitignore b/.gitignore
index f6010d379..dd2b271bc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,4 +22,5 @@ data/node-webkit/nw.pak
data/node-webkit/debug.log
*.DS_Store
data/package.json
-bower_components
\ No newline at end of file
+bower_components
+/data/Content/
diff --git a/data/index.html b/data/index.html
index ef7c44067..c8656add5 100644
--- a/data/index.html
+++ b/data/index.html
@@ -5,7 +5,7 @@
source code is governed by a AGPL3 license that can be found in the LICENSE file. -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
- <meta http-equiv="Content-Security-Policy" content="default-src file: gap: ; frame-src 'self' file: gap: ; img-src 'self' data: ; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval'">
+ <meta http-equiv="Content-Security-Policy" content="default-src file: gap: http: https: ; frame-src 'self' file: gap: http: https: ; img-src 'self' data: ; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval'">
<title>TagSpaces</title>
<style type="text/css">
#loadingLogo {
diff --git a/data/web/web.api.js b/data/web/web.api.js
index c7771a86f..ada9310c2 100644
--- a/data/web/web.api.js
+++ b/data/web/web.api.js
@@ -27,54 +27,60 @@ define(function(require, exports, module) {
function listDirectory(dirPath, readyCallback) {
console.log("Listing directory: " + dirPath);
-
+ var anotatedDirList = [];
dirPath = encodeURI(dirPath + "/");
-
- davClient.propfind(
- dirPath, //encodeURI(dirPath),
- function(status, data) {
- console.log("Dirlist Status: " + status);
- //console.log("Dirlist Content: "+JSON.stringify(data._responses));
- var anotatedDirList = [],
- dirList = data._responses,
- fileName,
- isDir,
- filesize,
- lmdt;
-
- for (var entry in dirList) {
- var path = dirList[entry].href;
- if (dirPath.toLowerCase() !== path.toLowerCase()) {
- isDir = false;
- filesize = undefined;
- lmdt = undefined;
- //console.log(dirList[entry]._namespaces["DAV:"]);
- if (typeof dirList[entry]._namespaces["DAV:"].getcontentlength === 'undefined' ||
- dirList[entry]._namespaces["DAV:"].getcontentlength._xmlvalue.length === 0
- ) {
- isDir = true;
- } else {
- filesize = dirList[entry]._namespaces["DAV:"].getcontentlength;
- lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;
+ try {
+ davClient.propfind(
+ dirPath, //encodeURI(dirPath),
+ function(status, data) {
+ console.log("Dirlist Status: " + status);
+ //console.log("Dirlist Content: "+JSON.stringify(data._responses));
+ var dirList = data._responses,
+ fileName, isDir, filesize, lmdt;
+
+ for (var entry in dirList) {
+ var path = dirList[entry].href;
+ if (dirPath.toLowerCase() !== path.toLowerCase()) {
+ isDir = false;
+ filesize = undefined;
+ lmdt = undefined;
+ //console.log(dirList[entry]._namespaces["DAV:"]);
+ if (typeof dirList[entry]._namespaces["DAV:"].getcontentlength === 'undefined' ||
+ dirList[entry]._namespaces["DAV:"].getcontentlength._xmlvalue.length === 0
+ ) {
+ isDir = true;
+ } else {
+ filesize = dirList[entry]._namespaces["DAV:"].getcontentlength;
+ lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;
+ }
+ fileName = getNameForPath(path);
+ anotatedDirList.push({
+ "name": fileName,
+ "isFile": !isDir,
+ "size": filesize,
+ "lmdt": lmdt,
+ "path": decodeURI(path)
+ });
}
- fileName = getNameForPath(path);
- anotatedDirList.push({
- "name": fileName,
- "isFile": !isDir,
- "size": filesize,
- "lmdt": lmdt,
- "path": decodeURI(path)
- });
}
- }
- if (readyCallback) {
- readyCallback(anotatedDirList);
- } else {
- TSPOSTIO.listDirectory(anotatedDirList);
- }
- },
- 1 //1 , davClient.INFINITY
- );
+ if (readyCallback) {
+ readyCallback(anotatedDirList);
+ } else {
+ TSPOSTIO.listDirectory(anotatedDirList);
+ }
+ },
+ 1 //1 , davClient.INFINITY
+ );
+ } catch (ex) {
+ if (readyCallback) {
+ readyCallback(anotatedDirList);
+ } else {
+ TSPOSTIO.errorOpeningPath();
+ }
+ TSCORE.hideLoadingAnimation();
+ TSCORE.showAlertDialog("Listing " + dirPath + " failed.");
+ console.error("Listing directory " + dirPath + " failed " + ex);
+ }
}
var getDirectoryMetaInformation = function(dirPath, readyCallback) {
@@ -115,143 +121,206 @@ define(function(require, exports, module) {
var createDirectory = function(dirPath, silentMode) {
console.log("Creating directory: " + dirPath);
- davClient.mkcol(
- encodeURI(dirPath),
- function(status, data, headers) {
- console.log("Directory Creation Status/Content/Headers: " + status + " / " + data + " / " + headers);
- if (silentMode !== true) {
- TSPOSTIO.createDirectory(dirPath);
+ try {
+ davClient.mkcol(
+ encodeURI(dirPath),
+ function(status, data, headers) {
+ console.log("Directory Creation Status/Content/Headers: " + status + " / " + data + " / " + headers);
+ if (silentMode !== true) {
+ TSPOSTIO.createDirectory(dirPath);
+ }
}
- }
- );
+ );
+ } catch (ex) {
+ console.error("createDirectory " + dirPath + " failed " + ex);
+ }
};
var copyFile = function(filePath, newFilePath) {
console.log("Copying file: " + filePath + " to " + newFilePath);
- davClient.copy(
- encodeURI(filePath),
- function(status, data, headers) {
- console.log("Copy File Status/Content/Headers: " + status + " / " + data + " / " + headers);
- TSPOSTIO.copyFile(filePath, newFilePath);
- },
- encodeURI(newFilePath),
- davClient.FAIL_ON_OVERWRITE
- );
+
+ if (filePath.toLowerCase() === newFilePath.toLowerCase()) {
+ TSCORE.hideWaitingDialog();
+ TSCORE.showAlertDialog($.i18n.t("ns.common:fileTheSame"), $.i18n.t("ns.common:fileNotCopyied"));
+ return false;
+ }
+
+ try {
+ davClient.copy(
+ encodeURI(filePath),
+ function(status, data, headers) {
+ console.log("Copy File Status/Content/Headers: " + status + " / " + data + " / " + headers);
+ TSPOSTIO.copyFile(filePath, newFilePath);
+ },
+ encodeURI(newFilePath),
+ davClient.FAIL_ON_OVERWRITE
+ );
+ } catch (ex) {
+ TSCORE.hideWaitingDialog();
+ TSCORE.showAlertDialog($.i18n.t("ns.common:fileCopyFailed", {fileName:newFilePath}));
+ console.error("copyFile " + filePath + " failed " + ex);
+ }
};
var renameFile = function(filePath, newFilePath) {
console.log("Renaming file: " + filePath + " to " + newFilePath);
- davClient.move(
- encodeURI(filePath),
- function(status, data, headers) {
- console.log("Rename File Status/Content/Headers: " + status + " / " + data + " / " + headers);
- TSPOSTIO.renameFile(filePath, newFilePath);
- },
- encodeURI(newFilePath),
- davClient.FAIL_ON_OVERWRITE
- );
+
+ if (filePath === newFilePath) {
+ TSCORE.hideWaitingDialog();
+ TSCORE.showAlertDialog($.i18n.t("ns.common:fileTheSame"), $.i18n.t("ns.common:fileNotMoved"));
+ return false;
+ }
+
+ try {
+ davClient.move(
+ encodeURI(filePath),
+ function(status, data, headers) {
+ console.log("Rename File Status/Content/Headers: " + status + " / " + data + " / " + headers);
+ TSPOSTIO.renameFile(filePath, newFilePath);
+ },
+ encodeURI(newFilePath),
+ davClient.FAIL_ON_OVERWRITE
+ );
+ } catch (ex) {
+ TSCORE.showAlertDialog("Renaming: " + filePath + " failed.");
+ console.error("renameFile " + filePath + " failed " + ex);
+ }
};
var renameDirectory = function(dirPath, newDirName) {
var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + encodeURIComponent(newDirName);
console.log("Renaming directory: " + dirPath + " to " + newDirPath);
- davClient.move(
- encodeURI(dirPath),
- function(status, data, headers) {
- console.log("Rename Directory Status/Content/Headers: " + status + " / " + data + " / " + headers);
- TSPOSTIO.renameDirectory(dirPath, newDirPath);
- },
- encodeURI(newDirPath),
- davClient.FAIL_ON_OVERWRITE
- );
+ try {
+ davClient.move(
+ encodeURI(dirPath),
+ function(status, data, headers) {
+ console.log("Rename Directory Status/Content/Headers: " + status + " / " + data + " / " + headers);
+ TSPOSTIO.renameDirectory(dirPath, newDirPath);
+ },
+ encodeURI(newDirPath),
+ davClient.FAIL_ON_OVERWRITE
+ );
+ } catch (ex) {
+ TSCORE.hideWaitingDialog();
+ TSCORE.showAlertDialog($.i18n.t("ns.common:pathIsNotDirectory", {dirName:dirPath}),
+ $.i18n.t("ns.common:directoryRenameFailed"));
+ console.error("renameDirectory: " + dirPath + " failed " + ex);
+ }
};
var loadTextFile = function(filePath) {
console.log("Loading file: " + filePath);
- davClient.get(
- encodeURI(filePath),
- function(status, data, headers) {
- console.log("Loading File Status/Content/Headers: " + status + " / " + data + " / " + headers);
- TSPOSTIO.loadTextFile(data);
- }
- //,customHeaders
- );
- //TODO Perform file locking and unlocking
+ try {
+ davClient.get(
+ encodeURI(filePath),
+ function(status, data, headers) {
+ console.log("Loading File Status/Content/Headers: " + status + " / " + data + " / " + headers);
+ TSPOSTIO.loadTextFile(data);
+ }
+ //,customHeaders
+ );
+ //TODO Perform file locking and unlocking
+ } catch (ex) {
+ console.error("Loading file " + filePath + " failed " + ex.toString());
+ TSCORE.showAlertDialog("Loading " + filePath + " failed.");
+ }
};
var saveTextFile = function(filePath, content, overWrite, silentMode) {
console.log("Saving file: " + filePath); //+" content: "+content);
var isNewFile = false; // = !pathUtils.existsSync(filePath);
- davClient.propfind(encodeURI(filePath), function(status, data) {
- console.log("Check file exists: Status / Content: " + status + " / " + data);
- if (parseInt(status) === 404) {
- isNewFile = true;
- }
- davClient.put(
- encodeURI(filePath),
- function(status, data, headers) {
- console.log("Creating File Status/Content/Headers: " + status + " / " + data + " / " + headers);
- if (silentMode !== true) {
- TSPOSTIO.saveTextFile(filePath, isNewFile);
- }
- },
- content,
- 'application/octet-stream'
- );
- }, 1);
- };
-
- var saveBinaryFile = function(filePath, content, overWrite, silentMode) {
- console.log("Saving binary file: " + filePath); //+" content: "+content);
- var isNewFile = false;
- davClient.propfind(encodeURI(filePath), function(status, data) {
- console.log("Check file exists: Status / Content: " + status + " / " + data);
- if (parseInt(status) === 404) {
- isNewFile = true;
- }
- if (isNewFile || overWrite === true) {
+ try {
+ davClient.propfind(encodeURI(filePath), function(status, data) {
+ console.log("Check file exists: Status / Content: " + status + " / " + data);
+ if (parseInt(status) === 404) {
+ isNewFile = true;
+ }
davClient.put(
encodeURI(filePath),
function(status, data, headers) {
console.log("Creating File Status/Content/Headers: " + status + " / " + data + " / " + headers);
if (silentMode !== true) {
- TSPOSTIO.saveBinaryFile(filePath, isNewFile);
+ TSPOSTIO.saveTextFile(filePath, isNewFile);
}
},
content,
'application/octet-stream'
);
- } else {
- TSCORE.showAlertDialog("File Already Exists.");
- }
- }, 1);
+ }, 1);
+ } catch (ex) {
+ TSCORE.showAlertDialog("Save file " + filePath + " failed.");
+ console.error("saveBinaryFile: " + filePath + " failed " + ex.toString());
+ }
+ };
+
+ var saveBinaryFile = function(filePath, content, overWrite, silentMode) {
+ console.log("Saving binary file: " + filePath); //+" content: "+content);
+ var isNewFile = false;
+ try {
+ davClient.propfind(encodeURI(filePath), function(status, data) {
+ console.log("Check file exists: Status / Content: " + status + " / " + data);
+ if (parseInt(status) === 404) {
+ isNewFile = true;
+ }
+ if (isNewFile || overWrite === true) {
+ davClient.put(
+ encodeURI(filePath),
+ function(status, data, headers) {
+ console.log("Creating File Status/Content/Headers: " + status + " / " + data + " / " + headers);
+ if (silentMode !== true) {
+ TSPOSTIO.saveBinaryFile(filePath, isNewFile);
+ }
+ },
+ content,
+ 'application/octet-stream'
+ );
+ } else {
+ TSCORE.showAlertDialog("File Already Exists.");
+ }
+ }, 1);
+ } catch (ex) {
+ TSCORE.showAlertDialog("Save file " + filePath + " failed.");
+ console.error("saveBinaryFile: " + filePath + " failed " + ex.toString());
+ }
};
var deleteElement = function(path) {
console.log("Deleting: " + path);
- davClient.remove(
- encodeURI(path),
- function(status, data, headers) {
- console.log("Directory/File Deletion Status/Content/Headers: " + status + " / " + data + " / " + headers);
- if (status === 204) {
- TSPOSTIO.deleteElement(path);
- } else {
- TSCORE.showAlertDialog("Deletion of the file failed");
+ try {
+ davClient.remove(
+ encodeURI(path),
+ function(status, data, headers) {
+ console.log("Directory/File Deletion Status/Content/Headers: " + status + " / " + data + " / " + headers);
+ if (status === 204) {
+ TSPOSTIO.deleteElement(path);
+ } else {
+ TSCORE.showAlertDialog("Deletion of the file " + path + " failed");
+ }
}
- }
- );
+ );
+ } catch (ex) {
+ TSCORE.hideLoadingAnimation();
+ TSCORE.showAlertDialog("Deleting file " + path + " failed.");
+ console.error("Deleting file " + path + " failed " + ex.toString());
+ }
};
var deleteDirectory = function(path) {
console.log("Deleting directory: " + path);
- davClient.remove(
- encodeURI(path),
- function(status, data, headers) {
- console.log("Directory/File Deletion Status/Content/Headers: " + status + " / " + data + " / " + headers);
- TSPOSTIO.deleteDirectory(path);
- }
- );
+ try {
+ davClient.remove(
+ encodeURI(path),
+ function(status, data, headers) {
+ console.log("Directory/File Deletion Status/Content/Headers: " + status + " / " + data + " / " + headers);
+ TSPOSTIO.deleteDirectory(path);
+ }
+ );
+ } catch (ex) {
+ TSCORE.hideLoadingAnimation();
+ TSCORE.showAlertDialog("Deleting directory " + path + " failed.");
+ console.error("deleteDirectory " + path + " failed " + ex.toString());
+ }
};
var checkAccessFileURLAllowed = function() {
@@ -283,16 +352,23 @@ define(function(require, exports, module) {
};
var getFileProperties = function(filePath) {
- davClient.propfind(encodeURI(filePath), function(status, data) {
- console.log("Properties Status / Content: " + status + " / " + JSON.stringify(data._responses));
- var fileProperties = {};
- for (var entry in data._responses) {
- fileProperties.path = filePath;
- fileProperties.size = data._responses[entry]._namespaces["DAV:"].getcontentlength;
- fileProperties.lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;
- }
- TSPOSTIO.getFileProperties(fileProperties);
- }, 1);
+ try {
+ davClient.propfind(encodeURI(filePath), function(status, data) {
+ console.log("Properties Status / Content: " + status + " / " + JSON.stringify(data._responses));
+ var fileProperties = {};
+ for (var entry in data._responses) {
+ fileProperties.path = filePath;
+ fileProperties.size = data._responses[entry]._namespaces["DAV:"].getcontentlength;
+ fileProperties.lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;
+ }
+ TSPOSTIO.getFileProperties(fileProperties);
+ }, 1);
+ } catch (ex) {
+ TSCORE.hideLoadingAnimation();
+ TSCORE.closeFileViewer();
+ TSCORE.showAlertDialog("File " + filePath + " get properties failed");
+ console.error("getFileProperties " + filePath + " failed " + ex.toString());
+ }
};
// Bring the TagSpaces window on top of the windows