Skip to content

Commit

Permalink
Feature/#1058 unhide (#94)
Browse files Browse the repository at this point in the history
* Hide action to not hiden files, unhide action to hidden files
Unhide action implemented
Change UI of hidden files +-

* Fixing mistake

* The perfect solution would be:
- After hide or unhide action - reload view similiar when we toggle the show_hiden files option on config.

Another solution would be:
- After hide or unhide action - reload if we are with show_hiden folder file config on.

What I could do:
- After hide, I don't reload the screen, assuming that we are with the show_hiden folder config off
- After unhide action - I reload the screen, assuming that we are with the show_hiden folder config on

* Update lib/Sabre/PostPlugin.php

Co-authored-by: Henry Bergström <henrybergstrom@protonmail.com>

---------

Co-authored-by: Henry Bergström <henrybergstrom@protonmail.com>
  • Loading branch information
JoaoSRaposo and frozenbanana authored Dec 9, 2024
1 parent 88547cd commit c872dd1
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 8 deletions.
19 changes: 19 additions & 0 deletions lib/Sabre/PostPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)

return false;
}
else if ($action === 'unhide') {
$path = $request->getPath();
$node = $this->server->tree->getNodeForPath($path);
if (($node instanceof \OCA\DAV\Connector\Sabre\File)) {
$storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId();
$filename = $node->getFileInfo()->getinternalPath();
}
if (($node instanceof \OCA\DAV\Connector\Sabre\Directory)) {
$storageid = $node->getFileInfo()->getStorage()->getCache()->getNumericStorageId();
$filename = $node->getFileInfo()->getinternalPath();
}

$this->EthswarmService->setVisiblity($filename, $storageid, 1);

$response->setStatus(200);
$response->setHeader('Content-Length', '0');

return false;
}
// No Hejbit-action, allow other plugins to handle the request
else if ($action === null) {
return true;
Expand Down
123 changes: 115 additions & 8 deletions src/fileactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Batch option const queue = new PQueue({ concurrency: 5 });
import { emit,subscribe } from '@nextcloud/event-bus';
import { FileAction, registerDavProperty, registerFileAction, FileType } from "@nextcloud/files";
import HideSource from "@material-design-icons/svg/filled/hide_source.svg";
import UnhideSource from "@material-design-icons/svg/filled/settings_backup_restore.svg";
import SwarmSvg from "../img/swarm-logo.svg";
import HejBitSvg from "../img/hejbit-logo.svg";
import axios from '@nextcloud/axios';
Expand Down Expand Up @@ -278,19 +279,22 @@ const actionDataHideFile ={
if (files.length !== 1) // We don't support batch actions
return false;
const attrs = files[0].attributes["ethswarm-node"];
const hidden = files[0].attributes.hidden;

if (attrs === undefined)
return false;
else if (attrs === "")
return false;
if (hidden)
return false;

return attrs;
},
async exec(node, view, dir) {
let message = '';
if (node.type === FileType.File) {
message = t('files_external_ethswarm', 'The file will be set to hide on the folder view. The file will continue to exist on the Swarm network.');
}else if (node.type === FileType.Folder) {
} else if (node.type === FileType.Folder) {
message = t('files_external_ethswarm', 'The folder will be set to hide on the folder view. All the files inside the folder will continue to exist on the Swarm network.');
}
alert(message);
Expand All @@ -303,19 +307,21 @@ const actionDataHideFile ={
}
});

// Let's delete even if it's moved to the trashbin
// since it has been removed from the current view
// and changing the view will trigger a reload anyway.
emit('files:node:deleted', node);
return true;
// The right event is emit('files:node:updated', node);
// it triggers the file:list:update, but unfortunately that doesn't
// a reevaluation of the enable funtion of the fileactions.
// To improve UX we should reload only if show_hidden is true
emit('files:node:deleted', node);
// window.location.reload();
return true;

}
catch (error) {
console.log('Error while deleting a file', { error, source: node.source, node });
console.log('Error while hidding a file', { error, source: node.source, node });
// TODO: update to this? logger.error('Error while deleting a file', { error, source: node.source, node });
return false;
}
}, /* TODO: Batch option
async execBatch(nodes, view, dir) {
// Map each node to a promise that resolves with the result of exec(node)
const promises = nodes.map(node => {
// Create a promise that resolves with the result of exec(node)
Expand All @@ -339,6 +345,107 @@ const AddHideAction = new FileAction(actionDataHideFile);

registerFileAction(AddHideAction);



const actionDataUnhideFile ={
id: 'unhideFile',
displayName(nodes, view) {
/**
* If we're only selecting files, use proper wording
*/
if (isAllFiles(nodes)) {
if (nodes.length === 1) {
return t('files_external_ethswarm', 'Unhide');
}
return t('files_external_ethswarm', 'Unhide');
}
/**
* If we're only selecting folders, use proper wording
*/
if (isAllFolders(nodes)) {
if (nodes.length === 1) {
return t('files_external_ethswarm', 'Unhide');
}
return t('files_external_ethswarm', 'Unhide');
}
return t('files_external_ethswarm', 'Unhide');
},
iconSvgInline: (nodes) => {
return Buffer.from(UnhideSource.split(",")[1], 'base64');
},
inline(file, view) {
return true;
},

enabled(files, view) {
if (files.length !== 1) // We don't support batch actions
return false;
const attrs = files[0].attributes["ethswarm-node"];
const hidden = files[0].attributes.hidden;

if (attrs === undefined)
return false;
else if (attrs === "")
return false;
if (!hidden)
return false;

return attrs;
},
async exec(node, view, dir) {
try {
await axios({
method: 'post',
url: node.encodedSource,
headers: {
'Hejbit-Action': 'unhide'
}
});


// the right event is emit('files:node:updated', node);
// it triggers the file:list:update, but unfortunately that doesn't
// a reevaluation of the enable funtion of the fileactions
emit('files:node:deleted', node);
window.location.reload();


return true;
}
catch (error) {
console.log('Error while unhidding a file', { error, source: node.source, node });
// TODO: update to this? logger.error('Error while deleting a file', { error, source: node.source, node });
return false;
}
}, /* TODO: Batch option
async execBatch(nodes, view, dir) {
// Map each node to a promise that resolves with the result of exec(node)
const promises = nodes.map(node => {
// Create a promise that resolves with the result of exec(node)
const promise = new Promise(resolve => {
queue.add(async () => {
const result = await this.exec(node, view, dir);
resolve(result !== null ? result : false);
});
});
return promise;
});
return Promise.all(promises);
}, */

execBatch(nodes, view) {
return Promise.all(nodes.map(node => this.exec(node, view)));
},
order: 150,
};

const AddUnhideAction = new FileAction(actionDataUnhideFile);

registerFileAction(AddUnhideAction);




let previousPathHasSwarm = false;

subscribe('files:list:updated', (data) => {
Expand Down

0 comments on commit c872dd1

Please sign in to comment.