1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/lib/file-api.js

89 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-06-24 20:06:28 +02:00
import { isHidden } from 'lib/path-utils.js';
import { Logger } from 'lib/logger.js';
2017-06-11 23:11:14 +02:00
class FileApi {
constructor(baseDir, driver) {
this.baseDir_ = baseDir;
this.driver_ = driver;
2017-06-23 23:32:24 +02:00
this.logger_ = new Logger();
2017-06-11 23:11:14 +02:00
}
2017-06-23 23:32:24 +02:00
setLogger(l) {
this.logger_ = l;
}
logger() {
return this.logger_;
2017-06-22 23:52:27 +02:00
}
2017-06-13 22:12:08 +02:00
fullPath_(path) {
let output = this.baseDir_;
if (path != '') output += '/' + path;
return output;
}
// DRIVER MUST RETURN PATHS RELATIVE TO `path`
list(path = '', options = null) {
if (!options) options = {};
if (!('includeHidden' in options)) options.includeHidden = false;
2017-06-23 23:32:24 +02:00
this.logger().debug('list');
2017-06-18 01:49:52 +02:00
return this.driver_.list(this.baseDir_).then((items) => {
if (!options.includeHidden) {
let temp = [];
for (let i = 0; i < items.length; i++) {
if (!isHidden(items[i].path)) temp.push(items[i]);
}
items = temp;
}
return items;
2017-06-11 23:11:14 +02:00
});
}
2017-06-27 21:48:01 +02:00
setTimestamp(path, timestampMs) {
this.logger().debug('setTimestamp ' + this.fullPath_(path));
2017-06-27 21:48:01 +02:00
return this.driver_.setTimestamp(this.fullPath_(path), timestampMs);
2017-06-12 23:56:27 +02:00
}
mkdir(path) {
this.logger().debug('mkdir ' + this.fullPath_(path));
return this.driver_.mkdir(this.fullPath_(path));
}
2017-06-11 23:11:14 +02:00
2017-06-15 01:14:15 +02:00
stat(path) {
this.logger().debug('stat ' + this.fullPath_(path));
2017-06-15 01:14:15 +02:00
return this.driver_.stat(this.fullPath_(path)).then((output) => {
if (!output) return output;
output.path = path;
return output;
});
}
2017-06-11 23:11:14 +02:00
get(path) {
this.logger().debug('get ' + this.fullPath_(path));
2017-06-13 22:12:08 +02:00
return this.driver_.get(this.fullPath_(path));
2017-06-11 23:11:14 +02:00
}
put(path, content) {
this.logger().debug('put ' + this.fullPath_(path));
2017-06-13 22:12:08 +02:00
return this.driver_.put(this.fullPath_(path), content);
2017-06-11 23:11:14 +02:00
}
delete(path) {
this.logger().debug('delete ' + this.fullPath_(path));
2017-06-13 22:12:08 +02:00
return this.driver_.delete(this.fullPath_(path));
2017-06-11 23:11:14 +02:00
}
move(oldPath, newPath) {
this.logger().debug('move ' + this.fullPath_(oldPath) + ' => ' + this.fullPath_(newPath));
return this.driver_.move(this.fullPath_(oldPath), this.fullPath_(newPath));
}
2017-06-11 23:11:14 +02:00
2017-06-13 22:58:17 +02:00
format() {
return this.driver_.format();
}
2017-06-11 23:11:14 +02:00
}
export { FileApi };