feat: bridge permanent trash deletion to plugins
This commit is contained in:
@@ -380,6 +380,12 @@ export function createPluginAPI(pluginId) {
|
||||
return App.RestoreVaultTrash(pluginId, trashId, options || {});
|
||||
});
|
||||
},
|
||||
deleteTrash: function(trashId) {
|
||||
assertActive('files.deleteTrash(' + trashId + ')');
|
||||
return callBackendErrorString(pluginId, 'files.deleteTrash(' + trashId + ')', function() {
|
||||
return App.DeleteVaultTrash(pluginId, trashId);
|
||||
});
|
||||
},
|
||||
openExternal: function(relativePath) {
|
||||
assertActive('files.openExternal(' + relativePath + ')');
|
||||
return callBackendErrorString(pluginId, 'files.openExternal(' + relativePath + ')', function() {
|
||||
|
||||
@@ -2608,13 +2608,15 @@
|
||||
if (!vaultFiles[norm.path]) return Promise.resolve([{}, 'not-found: ' + norm.path]);
|
||||
var trashId = 'mock-' + Date.now() + '-' + Math.random().toString(16).slice(2);
|
||||
var trashPath = '.verstak/trash/files/' + trashId + '/' + baseName(norm.path);
|
||||
var originalType = vaultFiles[norm.path].type || 'file';
|
||||
var originalNode = vaultFiles[norm.path];
|
||||
var originalType = originalNode.type || 'file';
|
||||
var originalSize = originalType === 'file' ? String(originalNode.content || '').length : 0;
|
||||
var moving = Object.keys(vaultFiles).filter(function (path) { return path === norm.path || path.indexOf(norm.path + '/') === 0; });
|
||||
trashPayloads[trashId] = moving.map(function (path) {
|
||||
return { suffix: path.slice(norm.path.length), entry: Object.assign({}, vaultFiles[path]) };
|
||||
});
|
||||
moving.forEach(function (path) { delete vaultFiles[path]; });
|
||||
var entry = { originalPath: norm.path, trashPath: trashPath, trashId: trashId, deletedAt: new Date().toISOString(), originalType: originalType, basename: baseName(norm.path) };
|
||||
var entry = { originalPath: norm.path, trashPath: trashPath, trashId: trashId, deletedAt: new Date().toISOString(), originalType: originalType, basename: baseName(norm.path), size: originalSize };
|
||||
trashEntries.unshift(entry);
|
||||
return Promise.resolve([entry, '']);
|
||||
},
|
||||
@@ -2646,6 +2648,15 @@
|
||||
trashEntries = trashEntries.filter(function (item) { return item.trashId !== trashId; });
|
||||
return Promise.resolve([target.path, '']);
|
||||
},
|
||||
DeleteVaultTrash: function (pluginId, trashId) {
|
||||
var err = requirePluginPermission(pluginId, 'files.delete');
|
||||
if (err) return Promise.resolve(err);
|
||||
var entry = trashEntries.find(function (item) { return item.trashId === trashId; });
|
||||
if (!entry) return Promise.resolve('not-found: trash entry ' + trashId);
|
||||
delete trashPayloads[trashId];
|
||||
trashEntries = trashEntries.filter(function (item) { return item.trashId !== trashId; });
|
||||
return Promise.resolve('');
|
||||
},
|
||||
OpenVaultPathExternal: function (pluginId, relativePath) {
|
||||
var err = requirePluginPermission(pluginId, 'files.openExternal');
|
||||
if (err) return Promise.resolve(err);
|
||||
|
||||
Reference in New Issue
Block a user