From 9ff1fb329213a3b7aca939d897fafb2b6bf9e2bb Mon Sep 17 00:00:00 2001 From: Alexandre Roux D'Anzi Date: Mon, 19 Feb 2024 09:30:55 +0100 Subject: [PATCH] missing import + reindent fixing https://github.com/CarnetApp/CarnetNextcloud/issues/215 --- src/browsers/file-browser.js | 199 +++++++++++++++++------------------ 1 file changed, 98 insertions(+), 101 deletions(-) diff --git a/src/browsers/file-browser.js b/src/browsers/file-browser.js index 7424957..1865bfc 100644 --- a/src/browsers/file-browser.js +++ b/src/browsers/file-browser.js @@ -1,117 +1,114 @@ -const RecentDBManager = require("../recent/recent_db_manager").RecentDBManager -const RequestBuilder = require("../requests/request_builder").RequestBuilder - +const RecentDBManager = require("../recent/recent_db_manager").RecentDBManager; +const RequestBuilder = require("../requests/request_builder").RequestBuilder; +const KeywordsDBManager = + require("../keywords/keywords_db_manager").KeywordsDBManager; var FileBrowser = function (path) { - this.path = path; -} + this.path = path; +}; FileBrowser.prototype.createFolder = function (name, callback) { - fs.mkdir(pathTool.join(this.path, name), function (e) { - callback(); - }); - -} + fs.mkdir(pathTool.join(this.path, name), function (e) { + callback(); + }); +}; FileBrowser.prototype.list = function (callback) { - - - if (this.path == "recentdb://") { - console.log("getting recent") - var db = RecentDBManager.getInstance() - return db.getFlatenDB(function (err, flaten, pin, metadata) { - if (err) - return callback(true) - console.log(JSON.stringify(flaten)) - var files = []; - for (let filePath of pin) { - var filename = filePath; - filePath = filePath - file = new File(filePath, true, filename); - file.isPinned = true; - files.push(file) - } - for (let filePath of flaten) { - if (pin.indexOf(filePath) != -1) - continue; - var filename = filePath; - filePath = filePath - file = new File(filePath, true, filename); - files.push(file) - } - callback(false, files, true, metadata) - }) - } else if (this.path.startsWith("keyword://")) { - console.log("getting keyword") - var keywordsDBManager = new KeywordsDBManager() - var filebrowser = this; - return keywordsDBManager.getFlatenDB(function (error, data) { - var files = []; - console.log("keyword " + filebrowser.path.substring("keyword://".length)) - for (let filePath of data[filebrowser.path.substring("keyword://".length)]) { - var filename = filePath; - console.log("file " + filePath) - - filePath = filePath - file = new File(filePath, true, filename); - files.push(file) - } - callback(false, files, true) - }) - } else { - var fbrowser = this; - return RequestBuilder.sRequestBuilder.get(this.path.startsWith("search://") ? "/notes/getSearchCache" : "/browser/list?path=" + encodeURIComponent(this.path), function (error, data) { - if (error) { - callback(error); - return; - } - var files = []; - var dirs_in = []; - var files_in = []; - var endOfSearch = !fbrowser.path.startsWith("search://"); - for (let node of data['files']) { - console.log(node); - if (node == "end_of_search") { - endOfSearch = true; - continue; - } - - if (node.path == "quickdoc") - continue; - file = new File(node.path, !node.isDir, node.name); - if (!node.isDir) - files_in.push(file) - else { - dirs_in.push(file) - } - } - files = files.concat(dirs_in) - files = files.concat(files_in) - callback(false, files, endOfSearch, data['metadata']) - - }); - - } -} + if (this.path == "recentdb://") { + console.log("getting recent"); + var db = RecentDBManager.getInstance(); + return db.getFlatenDB(function (err, flaten, pin, metadata) { + if (err) return callback(true); + console.log(JSON.stringify(flaten)); + var files = []; + for (let filePath of pin) { + var filename = filePath; + filePath = filePath; + file = new File(filePath, true, filename); + file.isPinned = true; + files.push(file); + } + for (let filePath of flaten) { + if (pin.indexOf(filePath) != -1) continue; + var filename = filePath; + filePath = filePath; + file = new File(filePath, true, filename); + files.push(file); + } + callback(false, files, true, metadata); + }); + } else if (this.path.startsWith("keyword://")) { + console.log("getting keyword"); + var keywordsDBManager = new KeywordsDBManager(); + var filebrowser = this; + return keywordsDBManager.getFlatenDB(function (error, data) { + var files = []; + console.log("keyword " + filebrowser.path.substring("keyword://".length)); + for (let filePath of data[ + filebrowser.path.substring("keyword://".length) + ]) { + var filename = filePath; + console.log("file " + filePath); + + filePath = filePath; + file = new File(filePath, true, filename); + files.push(file); + } + callback(false, files, true); + }); + } else { + var fbrowser = this; + return RequestBuilder.sRequestBuilder.get( + this.path.startsWith("search://") + ? "/notes/getSearchCache" + : "/browser/list?path=" + encodeURIComponent(this.path), + function (error, data) { + if (error) { + callback(error); + return; + } + var files = []; + var dirs_in = []; + var files_in = []; + var endOfSearch = !fbrowser.path.startsWith("search://"); + for (let node of data["files"]) { + console.log(node); + if (node == "end_of_search") { + endOfSearch = true; + continue; + } + + if (node.path == "quickdoc") continue; + file = new File(node.path, !node.isDir, node.name); + if (!node.isDir) files_in.push(file); + else { + dirs_in.push(file); + } + } + files = files.concat(dirs_in); + files = files.concat(files_in); + callback(false, files, endOfSearch, data["metadata"]); + } + ); + } +}; var File = function (path, isFile, name, extension) { - this.path = path; - this.isFile = isFile; - this.name = name; - this.extension = extension; - -} + this.path = path; + this.isFile = isFile; + this.name = name; + this.extension = extension; +}; File.prototype.getName = function () { - return getFilenameFromPath(this.path); -} + return getFilenameFromPath(this.path); +}; function getFilenameFromPath(path) { - return path.replace(/^.*[\\\/]/, ''); + return path.replace(/^.*[\\\/]/, ""); } function stripExtensionFromName(name) { - return name.replace(/\.[^/.]+$/, "") + return name.replace(/\.[^/.]+$/, ""); } - -exports.FileBrowser = FileBrowser \ No newline at end of file +exports.FileBrowser = FileBrowser;