Skip to content

Commit 3cc6de7

Browse files
committed
fix(files_trashbin): check if there is enough space before restoring
Signed-off-by: Kent Delante <kent.delante@proton.me>
1 parent 0827645 commit 3cc6de7

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

apps/files_trashbin/src/files_actions/restoreAction.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55
import { getCurrentUser } from '@nextcloud/auth'
6+
import { showError } from '@nextcloud/dialogs'
67
import { emit } from '@nextcloud/event-bus'
78
import { Permission, Node, View, FileAction } from '@nextcloud/files'
89
import { t } from '@nextcloud/l10n'
910
import { encodePath } from '@nextcloud/paths'
10-
import { generateRemoteUrl } from '@nextcloud/router'
11+
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
1112
import axios from '@nextcloud/axios'
1213
import svgHistory from '@mdi/svg/svg/history.svg?raw'
1314

1415
import { TRASHBIN_VIEW_ID } from '../files_views/trashbinView.ts'
16+
import { client, rootPath } from '../services/client.ts'
1517
import logger from '../../../files/src/logger.ts'
1618

1719
export const restoreAction = new FileAction({
@@ -38,6 +40,18 @@ export const restoreAction = new FileAction({
3840

3941
async exec(node: Node) {
4042
try {
43+
const stats = await axios.request({
44+
method: 'GET',
45+
url: generateUrl('/apps/files/api/v1/stats'),
46+
})
47+
48+
const free = stats.data.data.free
49+
const { size } = await client.stat(encodePath(`${rootPath}/${node.basename}`))
50+
if (size > free) {
51+
showError(t('files', 'Not enough free space'))
52+
return false
53+
}
54+
4155
const destination = generateRemoteUrl(encodePath(`dav/trashbin/${getCurrentUser()!.uid}/restore/${node.basename}`))
4256
await axios.request({
4357
method: 'MOVE',

dist/files_trashbin-init.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files_trashbin-init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)