Skip to content

Commit

Permalink
missing import + reindent fixing https://github.com/CarnetApp/CarnetN…
Browse files Browse the repository at this point in the history
  • Loading branch information
PhieF committed Feb 19, 2024
1 parent f3f41c4 commit 9ff1fb3
Showing 1 changed file with 98 additions and 101 deletions.
199 changes: 98 additions & 101 deletions src/browsers/file-browser.js
Original file line number Diff line number Diff line change
@@ -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
exports.FileBrowser = FileBrowser;

0 comments on commit 9ff1fb3

Please sign in to comment.