1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Handle delta api for filesystem

This commit is contained in:
Laurent Cozic
2017-07-18 23:14:20 +01:00
parent 0c30c1b70b
commit 7aa21174f6
16 changed files with 185 additions and 106 deletions

View File

@@ -1,6 +1,7 @@
import fs from 'fs-extra';
import { promiseChain } from 'lib/promise-utils.js';
import moment from 'moment';
import { BaseItem } from 'lib/models/base-item.js';
import { time } from 'lib/time-utils.js';
class FileApiDriverLocal {
@@ -20,6 +21,10 @@ class FileApiDriverLocal {
return output;
}
supportsDelta() {
return false;
}
stat(path) {
return new Promise((resolve, reject) => {
fs.stat(path, (error, s) => {
@@ -68,6 +73,49 @@ class FileApiDriverLocal {
});
}
async delta(path, options) {
try {
let items = await fs.readdir(path);
let output = [];
for (let i = 0; i < items.length; i++) {
let stat = await this.stat(path + '/' + items[i]);
if (!stat) continue; // Has been deleted between the readdir() call and now
stat.path = items[i];
output.push(stat);
}
if (!Array.isArray(options.itemIds)) throw new Error('Delta API not supported - local IDs must be provided');
let deletedItems = [];
for (let i = 0; i < options.itemIds.length; i++) {
const itemId = options.itemIds[i];
let found = false;
for (let j = 0; j < output.length; j++) {
const item = output[j];
if (BaseItem.pathToId(item.path) == itemId) {
found = true;
break;
}
}
if (!found) {
deletedItems.push({
path: BaseItem.systemPath(itemId),
isDeleted: true,
});
}
}
return {
hasMore: false,
context: null,
items: output,
};
} catch(error) {
throw this.fsErrorToJsError_(error);
}
}
async list(path, options) {
try {
let items = await fs.readdir(path);