1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00
joplin/ReactNativeClient/lib/file-api.js

93 lines
2.2 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-29 20:03:16 +02:00
if (!('context' in options)) options.context = null;
2017-06-29 20:03:16 +02:00
this.logger().debug('list ' + this.baseDir_);
return this.driver_.list(this.baseDir_, options).then((result) => {
if (!options.includeHidden) {
let temp = [];
2017-06-29 20:03:16 +02:00
for (let i = 0; i < result.items.length; i++) {
if (!isHidden(result.items[i].path)) temp.push(result.items[i]);
}
2017-06-29 20:03:16 +02:00
result.items = temp;
}
2017-06-29 20:03:16 +02:00
return result;
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-07-06 23:30:45 +02:00
get(path, options = null) {
if (!options) options = {};
2017-07-02 14:02:07 +02:00
if (!options.encoding) options.encoding = 'utf8';
this.logger().debug('get ' + this.fullPath_(path));
2017-07-02 14:02:07 +02:00
return this.driver_.get(this.fullPath_(path), options);
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 };