Skip to content

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

Web api implementation

Borislav Sapundzhievf70ae9867a74
diff --git a/data/index.html b/data/index.html
index d046b4838..6edc6230a 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, minimum-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: http: https: ; img-src 'self' file: data: ; media-src 'self' file: data: ; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval'">
+ <meta http-equiv="Content-Security-Policy" content="default-src file: gap: http: ; frame-src 'self' file: gap: http: https: ; img-src 'self' file: data: ; media-src 'self' file: data: ; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval'">
<title>TagSpaces</title>
<style type="text/css">
#loadingLogo {
diff --git a/data/js/extension.manager.js b/data/js/extension.manager.js
index 28b929df4..3ef50378c 100644
--- a/data/js/extension.manager.js
+++ b/data/js/extension.manager.js
@@ -7,6 +7,9 @@ define(function(require, exports, module) {
function getExtFolderPath() {
var extPath = "ext";
+ if(isWeb) {
+ return extPath;
+ }
if (isCordova) {
return location.href.replace(/index.html/gi, extPath);
}
diff --git a/data/js/options.ui.js b/data/js/options.ui.js
index 54ae47356..81288cb86 100644
--- a/data/js/options.ui.js
+++ b/data/js/options.ui.js
@@ -39,7 +39,7 @@ define(function(require, exports, module) {
row4Remove.remove();
});
})));
- if (isChrome || isFirefox) {
+ if (isChrome) {
generateSelectOptions(perspectiveControl.find('select'), TSCORE.Config.getPerspectiveExtensions(), perspectiveId, "ns.dialogs:choosePerspective");
} else {
generateSelectOptions(perspectiveControl.find('select'), getExtensionsByType("perspective"), perspectiveId, "ns.dialogs:choosePerspective");
@@ -79,7 +79,7 @@ define(function(require, exports, module) {
var editors = getExtensionsByType("editor");
viewers = viewers.concat(editors);
- if (isChrome || isFirefox) {
+ if (isChrome) {
generateSelectOptions(fileTypeControl.find('.ftviewer'), TSCORE.Config.getViewerExtensions(), viewerId, "ns.dialogs:chooseFileViewer");
generateSelectOptions(fileTypeControl.find('.fteditor'), TSCORE.Config.getEditorExtensions(), editorId, "ns.dialogs:chooseFileEditor");
} else {
diff --git a/data/web/web.api.js b/data/web/web.api.js
index 285785bc6..72772f20e 100644
--- a/data/web/web.api.js
+++ b/data/web/web.api.js
@@ -65,56 +65,8 @@ 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);
- if (!checkStatusCode(status)) {
- if (readyCallback) {
- readyCallback(anotatedDirList);
- } else {
- //TSPOSTIO.errorOpeningPath();
- }
- TSCORE.hideLoadingAnimation();
- if (!readyCallback) {
- TSCORE.showAlertDialog("Listing " + dirPath + " failed.");
- }
- TSCORE.hideLoadingAnimation();
- console.warn("Listing directory " + dirPath + " failed " + status);
- return;
- }
- 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)
- });
- }
- }
+ listDirectoryPromise(dirPath).then(function(anotatedDirList) {
if (readyCallback) {
readyCallback(anotatedDirList);
} else {
@@ -122,10 +74,71 @@ define(function(require, exports, module) {
}
TSCORE.hideLoadingAnimation();
},
- 1 //1 , davClient.INFINITY
- );
+ function(error) {
+ if (readyCallback) {
+ readyCallback(anotatedDirList);
+ } else {
+ //TSPOSTIO.errorOpeningPath();
+ }
+ TSCORE.hideLoadingAnimation();
+ if (!readyCallback) {
+ TSCORE.showAlertDialog("Listing " + dirPath + " failed.");
+ }
+ TSCORE.hideLoadingAnimation();
+ console.warn("Listing directory " + dirPath + " failed " + status);
+ }
+ );
}
+ function listDirectoryPromise(dirPath) {
+ console.log("Listing directory: " + dirPath);
+ return new Promise(function(resolve, reject) {
+ var anotatedDirList = [];
+ dirPath = encodeURI(dirPath + "/");
+ davClient.propfind(
+ dirPath, //encodeURI(dirPath),
+ function(status, data) {
+ console.log("Dirlist Status: " + status);
+ if (!checkStatusCode(status)) {
+ reject("Listing directory " + dirPath + " failed " + status);
+ console.warn("Listing directory " + dirPath + " failed " + status);
+ return;
+ }
+ 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)
+ });
+ }
+ }
+ resolve(anotatedDirList);
+ },
+ 1 //1 , davClient.INFINITY
+ );
+ });
+ };
+
var getDirectoryMetaInformation = function(dirPath, readyCallback) {
listDirectory(dirPath, function(anotatedDirList) {
TSCORE.metaFileList = anotatedDirList;
@@ -417,21 +430,29 @@ define(function(require, exports, module) {
};
var getFileContent = function(filePath, result, error) {
+ getFileContentPromise(filePath).then(result, error);
+ };
+ function getFileContentPromise(filePath, type) {
+
console.log("getFileContent file: " + filePath);
-
- var ajax = davClient.getAjax("GET", filePath);
- ajax.onreadystatechange = null;
- ajax.onload = function() {
- if (ajax.response.byteLength !== null) {
- result(ajax.response);
- } else {
- error(ajax.responseText);
- }
- };
- ajax.responseType = "arraybuffer";
- ajax.send();
- };
+ return new Promise(function(resolve, reject) {
+ var ajax = davClient.getAjax("GET", filePath);
+ ajax.onreadystatechange = null;
+ ajax.responseType = type || "arraybuffer";
+ ajax.onerror = reject;
+
+ ajax.onload = function() {
+ var response = ajax.response || ajax.responseText;
+ if (response) {
+ resolve(response);
+ } else {
+ reject("getFileContentPromise ajax error");
+ }
+ };
+ ajax.send();
+ });
+ }
exports.focusWindow = focusWindow;
exports.createDirectory = createDirectory;
@@ -455,4 +476,6 @@ define(function(require, exports, module) {
exports.checkNewVersion = checkNewVersion;
exports.getFileProperties = getFileProperties;
exports.getFileContent = getFileContent;
+ exports.listDirectoryPromise = listDirectoryPromise;
+ exports.getFileContentPromise = getFileContentPromise;
});