summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2023-03-28 13:47:52 +0200
committerJohn Molakvoæ <skjnldsv@protonmail.com>2023-04-06 14:49:32 +0200
commit60b74e3d6d626a7f7599acbeaadb650cbf56cc6c (patch)
treeaa449108c8996f352d5b8a5529a8d208a8ab6934 /apps/files_trashbin
parent4942747ff85dc8671ff7a6a42cd07a886d361b07 (diff)
downloadnextcloud-server-60b74e3d6d626a7f7599acbeaadb650cbf56cc6c.tar.gz
nextcloud-server-60b74e3d6d626a7f7599acbeaadb650cbf56cc6c.zip
feat(files): batch actions
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/src/actions/restoreAction.ts42
1 files changed, 26 insertions, 16 deletions
diff --git a/apps/files_trashbin/src/actions/restoreAction.ts b/apps/files_trashbin/src/actions/restoreAction.ts
index 201fffe6a53..fe896f6b618 100644
--- a/apps/files_trashbin/src/actions/restoreAction.ts
+++ b/apps/files_trashbin/src/actions/restoreAction.ts
@@ -19,13 +19,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+import { emit } from '@nextcloud/event-bus'
+import { generateRemoteUrl } from '@nextcloud/router'
+import { getCurrentUser } from '@nextcloud/auth'
import { registerFileAction, Permission, FileAction, Node } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import History from '@mdi/svg/svg/history.svg?raw'
-import { generateRemoteUrl } from '@nextcloud/router'
-import { getCurrentUser } from '@nextcloud/auth'
-import { emit } from '@nextcloud/event-bus'
registerFileAction(new FileAction({
id: 'restore',
@@ -33,6 +33,7 @@ registerFileAction(new FileAction({
return t('files_trashbin', 'Restore')
},
iconSvgInline: () => History,
+
enabled(nodes: Node[], view) {
// Only available in the trashbin view
if (view.id !== 'trashbin') {
@@ -44,22 +45,31 @@ registerFileAction(new FileAction({
.map(node => node.permissions)
.every(permission => (permission & Permission.READ) !== 0)
},
+
async exec(node: Node) {
- // No try...catch here, let the files app handle the error
- const destination = generateRemoteUrl(`dav/trashbin/${getCurrentUser()?.uid}/restore/${node.basename}`)
- await axios({
- method: 'MOVE',
- url: node.source,
- headers: {
- destination,
- },
- })
+ try {
+ const destination = generateRemoteUrl(`dav/trashbin/${getCurrentUser()?.uid}/restore/${node.basename}`)
+ await axios({
+ method: 'MOVE',
+ url: node.source,
+ headers: {
+ destination,
+ },
+ })
- // Let's pretend the file is deleted since
- // we don't know the restored location
- emit('files:file:deleted', node)
- return true
+ // Let's pretend the file is deleted since
+ // we don't know the restored location
+ emit('files:file:deleted', node)
+ return true
+ } catch (error) {
+ console.error(error)
+ return false
+ }
+ },
+ async execBatch(nodes: Node[], view) {
+ return Promise.all(nodes.map(node => this.exec(node, view)))
},
+
order: 1,
inline: () => true,
}))