-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
missing import + reindent fixing https://github.com/CarnetApp/CarnetN…
- Loading branch information
Showing
1 changed file
with
98 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |