Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/files_trashbin/lib/Sabre/TrashbinPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public function propFind(PropFind $propFind, INode $node) {
return $node->getDeletedBy()?->getDisplayName();
});

// Pass the real filename as the DAV display name
$propFind->handle(FilesPlugin::DISPLAYNAME_PROPERTYNAME, function () use ($node) {
return $node->getFilename();
});
Comment on lines +77 to +80
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe deprecate nc:trashbin-filename then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do so, but wanted not to do this here as a bit unrelated. can do so in another PR.


$propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) {
return $node->getSize();
});
Expand Down
23 changes: 3 additions & 20 deletions apps/files_trashbin/src/services/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { createClient } from 'webdav'
import { generateRemoteUrl } from '@nextcloud/router'
import { getCurrentUser, getRequestToken, onRequestTokenUpdate } from '@nextcloud/auth'
import { getCurrentUser } from '@nextcloud/auth'
import { davGetClient } from '@nextcloud/files'

// init webdav client
export const rootPath = `/trashbin/${getCurrentUser()?.uid}/trash`
export const rootUrl = generateRemoteUrl('dav' + rootPath)
const client = createClient(rootUrl)

// set CSRF token header
const setHeaders = (token: string | null) => {
client.setHeaders({
// Add this so the server knows it is an request from the browser
'X-Requested-With': 'XMLHttpRequest',
// Inject user auth
requesttoken: token ?? '',
})
}

// refresh headers when request token changes
onRequestTokenUpdate(setHeaders)
setHeaders(getRequestToken())

export default client
export const client = davGetClient()
59 changes: 14 additions & 45 deletions apps/files_trashbin/src/services/trashbin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
import type { FileStat, ResponseDataDetailed } from 'webdav'
import type { ContentsWithRoot } from '@nextcloud/files'

import { File, Folder, davParsePermissions, getDavNameSpaces, getDavProperties } from '@nextcloud/files'
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'

import client, { rootPath } from './client'
import { File, Folder, davResultToNode, getDavNameSpaces, getDavProperties } from '@nextcloud/files'
import { client, rootPath } from './client'
import { generateUrl } from '@nextcloud/router'

const data = `<?xml version="1.0"?>
<d:propfind ${getDavNameSpaces()}>
<d:prop>
<nc:trashbin-filename />
<nc:trashbin-deletion-time />
<nc:trashbin-original-location />
<nc:trashbin-title />
Expand All @@ -24,52 +21,24 @@ const data = `<?xml version="1.0"?>
</d:prop>
</d:propfind>`

const resultToNode = function(node: FileStat): File | Folder {
const permissions = davParsePermissions(node.props?.permissions)
const owner = getCurrentUser()?.uid as string
const previewUrl = generateUrl('/apps/files_trashbin/preview?fileId={fileid}&x=32&y=32', node.props)

const nodeData = {
id: node.props?.fileid as number || 0,
source: generateRemoteUrl('dav' + rootPath + node.filename),
// do not show the mtime column
// mtime: new Date(node.lastmod),
mime: node.mime as string,
size: node.props?.size as number || 0,
permissions,
owner,
root: rootPath,
attributes: {
...node,
...node.props,
// Override displayed name on the list
displayName: node.props?.['trashbin-filename'],
previewUrl,
},
}

delete nodeData.attributes.props

return node.type === 'file'
? new File(nodeData)
: new Folder(nodeData)
const resultToNode = (stat: FileStat): File | Folder => {
const node = davResultToNode(stat, rootPath)
node.attributes.previewUrl = generateUrl('/apps/files_trashbin/preview?fileId={fileid}&x=32&y=32', { fileid: node.fileid })
return node
}

export const getContents = async (path = '/'): Promise<ContentsWithRoot> => {
// TODO: use only one request when webdav-client supports it
// @see https://github.com/perry-mitchell/webdav-client/pull/334
const rootResponse = await client.stat(path, {
details: true,
data,
}) as ResponseDataDetailed<FileStat>

const contentsResponse = await client.getDirectoryContents(path, {
const contentsResponse = await client.getDirectoryContents(`${rootPath}${path}`, {
details: true,
data,
includeSelf: true,
}) as ResponseDataDetailed<FileStat[]>

const contents = contentsResponse.data.map(resultToNode)
const [folder] = contents.splice(contents.findIndex((node) => node.dirname === path), 1)

return {
folder: resultToNode(rootResponse.data) as Folder,
contents: contentsResponse.data.map(resultToNode),
folder: folder as Folder,
contents,
}
}
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_trashbin-init.js

Large diffs are not rendered by default.

115 changes: 0 additions & 115 deletions dist/files_trashbin-init.js.license
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: BSD-3-Clause
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: (MPL-2.0 OR Apache-2.0)
SPDX-FileCopyrightText: string_decoder developers
SPDX-FileCopyrightText: readable-stream developers
SPDX-FileCopyrightText: qs developers
SPDX-FileCopyrightText: jden <[email protected]>
SPDX-FileCopyrightText: inherits developers
SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: defunctzombie
SPDX-FileCopyrightText: assert developers
SPDX-FileCopyrightText: Tobias Koppers @sokra
SPDX-FileCopyrightText: Titus Wormer <[email protected]> (https://wooorm.com)
Expand All @@ -21,43 +16,29 @@ SPDX-FileCopyrightText: Raynos <[email protected]>
SPDX-FileCopyrightText: Perry Mitchell <[email protected]>
SPDX-FileCopyrightText: Paul Vorbach <[email protected]> (http://paul.vorba.ch)
SPDX-FileCopyrightText: Paul Vorbach <[email protected]> (http://vorb.de)
SPDX-FileCopyrightText: Olivier Scherrer <[email protected]>
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Nathan Rajlich <[email protected]> (http://n8.io/)
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Mathias Bynens
SPDX-FileCopyrightText: Julian Gruber
SPDX-FileCopyrightText: Joyent
SPDX-FileCopyrightText: José F. Romaniello <[email protected]> (http://joseoncode.com)
SPDX-FileCopyrightText: Jordan Harband <[email protected]>
SPDX-FileCopyrightText: Jordan Harband
SPDX-FileCopyrightText: Jonas Schade <[email protected]>
SPDX-FileCopyrightText: John-David Dalton <[email protected]> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <[email protected]>
SPDX-FileCopyrightText: John Hiesey
SPDX-FileCopyrightText: James Halliday
SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
SPDX-FileCopyrightText: Iskren Ivov Chernev <[email protected]> (https://github.com/ichernev)
SPDX-FileCopyrightText: Isaac Z. Schlueter <[email protected]> (http://blog.izs.me)
SPDX-FileCopyrightText: Irakli Gozalishvili <[email protected]> (http://jeditoolkit.com)
SPDX-FileCopyrightText: Hypercontext
SPDX-FileCopyrightText: Guillaume Chau <[email protected]>
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Eugene Sharygin <[email protected]>
SPDX-FileCopyrightText: Eric Norris (https://github.com/ericnorris)
SPDX-FileCopyrightText: Dylan Piercey <[email protected]>
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <[email protected]> (https://cure53.de/)
SPDX-FileCopyrightText: Denis Pushkarev
SPDX-FileCopyrightText: David Clark
SPDX-FileCopyrightText: Christoph Wurst
SPDX-FileCopyrightText: Ben Drucker
SPDX-FileCopyrightText: Arnout Kazemier
SPDX-FileCopyrightText: Anthony Fu <https://github.com/antfu>
SPDX-FileCopyrightText: Andris Reinman
SPDX-FileCopyrightText: Amit Gupta (https://solothought.com)
SPDX-FileCopyrightText: Amit Gupta (https://amitkumargupta.work/)
SPDX-FileCopyrightText: Alkemics


Expand Down Expand Up @@ -125,27 +106,9 @@ This file is generated from multiple sources. Included packages:
- axios
- version: 1.7.3
- license: MIT
- balanced-match
- version: 1.0.2
- license: MIT
- base-64
- version: 1.0.0
- license: MIT
- base64-js
- version: 1.5.1
- license: MIT
- brace-expansion
- version: 2.0.1
- license: MIT
- buffer
- version: 5.7.1
- license: MIT
- builtin-status-codes
- version: 3.0.0
- license: MIT
- byte-length
- version: 1.0.2
- license: MIT
- call-bind
- version: 1.0.7
- license: MIT
Expand Down Expand Up @@ -185,12 +148,6 @@ This file is generated from multiple sources. Included packages:
- escape-html
- version: 1.0.3
- license: MIT
- events
- version: 3.3.0
- license: MIT
- fast-xml-parser
- version: 4.4.1
- license: MIT
- floating-vue
- version: 1.0.0-beta.19
- license: MIT
Expand Down Expand Up @@ -224,12 +181,6 @@ This file is generated from multiple sources. Included packages:
- hasown
- version: 2.0.2
- license: MIT
- hot-patcher
- version: 2.0.1
- license: MIT
- https-browserify
- version: 1.0.0
- license: MIT
- ieee754
- version: 1.2.1
- license: BSD-3-Clause
Expand All @@ -254,9 +205,6 @@ This file is generated from multiple sources. Included packages:
- is-typed-array
- version: 1.1.13
- license: MIT
- layerr
- version: 3.0.0
- license: MIT
- linkify-string
- version: 4.1.3
- license: MIT
Expand All @@ -269,18 +217,12 @@ This file is generated from multiple sources. Included packages:
- moment
- version: 2.30.1
- license: MIT
- nested-property
- version: 4.0.0
- license: MIT
- node-gettext
- version: 3.0.0
- license: MIT
- buffer
- version: 6.0.3
- license: MIT
- object-inspect
- version: 1.13.2
- license: MIT
- object-is
- version: 1.1.6
- license: MIT
Expand All @@ -290,9 +232,6 @@ This file is generated from multiple sources. Included packages:
- object.assign
- version: 4.1.5
- license: MIT
- path-posix
- version: 1.0.0
- license: ISC
- inherits
- version: 2.0.3
- license: ISC
Expand All @@ -308,45 +247,12 @@ This file is generated from multiple sources. Included packages:
- process
- version: 0.11.10
- license: MIT
- punycode
- version: 1.4.1
- license: MIT
- querystringify
- version: 2.2.0
- license: MIT
- requires-port
- version: 1.0.0
- license: MIT
- safe-buffer
- version: 5.2.1
- license: MIT
- set-function-length
- version: 1.2.2
- license: MIT
- side-channel
- version: 1.0.6
- license: MIT
- readable-stream
- version: 3.6.2
- license: MIT
- stream-browserify
- version: 3.0.0
- license: MIT
- readable-stream
- version: 3.6.2
- license: MIT
- stream-http
- version: 3.2.0
- license: MIT
- string_decoder
- version: 1.3.0
- license: MIT
- striptags
- version: 3.2.0
- license: MIT
- strnum
- version: 1.0.5
- license: MIT
- style-loader
- version: 3.3.4
- license: MIT
Expand All @@ -368,30 +274,12 @@ This file is generated from multiple sources. Included packages:
- unist-util-visit
- version: 5.0.0
- license: MIT
- url-join
- version: 5.0.0
- license: MIT
- url-parse
- version: 1.5.10
- license: MIT
- qs
- version: 6.13.0
- license: BSD-3-Clause
- url
- version: 0.11.4
- license: MIT
- util-deprecate
- version: 1.0.2
- license: MIT
- util
- version: 0.12.5
- license: MIT
- vue
- version: 2.7.16
- license: MIT
- minimatch
- version: 10.0.1
- license: ISC
- webdav
- version: 5.7.0
- license: MIT
Expand All @@ -401,9 +289,6 @@ This file is generated from multiple sources. Included packages:
- which-typed-array
- version: 1.1.15
- license: MIT
- xtend
- version: 4.0.2
- license: MIT
- nextcloud
- version: 1.0.0
- license: AGPL-3.0-or-later
2 changes: 1 addition & 1 deletion dist/files_trashbin-init.js.map

Large diffs are not rendered by default.