Skip to content

Commit d6a5fba

Browse files
committed
fix(files_trashbin): set real filename on trashbin download
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent 3c99b64 commit d6a5fba

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

apps/files_trashbin/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ To prevent a user from running out of disk space, the Deleted files app will not
4242
<collection>OCA\Files_Trashbin\Sabre\RootCollection</collection>
4343
</collections>
4444
<plugins>
45-
<plugin>OCA\Files_Trashbin\Sabre\PropfindPlugin</plugin>
45+
<plugin>OCA\Files_Trashbin\Sabre\TrashbinPlugin</plugin>
4646
</plugins>
4747
</sabre>
4848

apps/files_trashbin/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
'OCA\\Files_Trashbin\\Sabre\\AbstractTrashFile' => $baseDir . '/../lib/Sabre/AbstractTrashFile.php',
2828
'OCA\\Files_Trashbin\\Sabre\\AbstractTrashFolder' => $baseDir . '/../lib/Sabre/AbstractTrashFolder.php',
2929
'OCA\\Files_Trashbin\\Sabre\\ITrash' => $baseDir . '/../lib/Sabre/ITrash.php',
30-
'OCA\\Files_Trashbin\\Sabre\\PropfindPlugin' => $baseDir . '/../lib/Sabre/PropfindPlugin.php',
3130
'OCA\\Files_Trashbin\\Sabre\\RestoreFolder' => $baseDir . '/../lib/Sabre/RestoreFolder.php',
3231
'OCA\\Files_Trashbin\\Sabre\\RootCollection' => $baseDir . '/../lib/Sabre/RootCollection.php',
3332
'OCA\\Files_Trashbin\\Sabre\\TrashFile' => $baseDir . '/../lib/Sabre/TrashFile.php',
@@ -36,6 +35,7 @@
3635
'OCA\\Files_Trashbin\\Sabre\\TrashFolderFolder' => $baseDir . '/../lib/Sabre/TrashFolderFolder.php',
3736
'OCA\\Files_Trashbin\\Sabre\\TrashHome' => $baseDir . '/../lib/Sabre/TrashHome.php',
3837
'OCA\\Files_Trashbin\\Sabre\\TrashRoot' => $baseDir . '/../lib/Sabre/TrashRoot.php',
38+
'OCA\\Files_Trashbin\\Sabre\\TrashbinPlugin' => $baseDir . '/../lib/Sabre/TrashbinPlugin.php',
3939
'OCA\\Files_Trashbin\\Storage' => $baseDir . '/../lib/Storage.php',
4040
'OCA\\Files_Trashbin\\Trash\\BackendNotFoundException' => $baseDir . '/../lib/Trash/BackendNotFoundException.php',
4141
'OCA\\Files_Trashbin\\Trash\\ITrashBackend' => $baseDir . '/../lib/Trash/ITrashBackend.php',

apps/files_trashbin/composer/composer/autoload_static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class ComposerStaticInitFiles_Trashbin
4242
'OCA\\Files_Trashbin\\Sabre\\AbstractTrashFile' => __DIR__ . '/..' . '/../lib/Sabre/AbstractTrashFile.php',
4343
'OCA\\Files_Trashbin\\Sabre\\AbstractTrashFolder' => __DIR__ . '/..' . '/../lib/Sabre/AbstractTrashFolder.php',
4444
'OCA\\Files_Trashbin\\Sabre\\ITrash' => __DIR__ . '/..' . '/../lib/Sabre/ITrash.php',
45-
'OCA\\Files_Trashbin\\Sabre\\PropfindPlugin' => __DIR__ . '/..' . '/../lib/Sabre/PropfindPlugin.php',
4645
'OCA\\Files_Trashbin\\Sabre\\RestoreFolder' => __DIR__ . '/..' . '/../lib/Sabre/RestoreFolder.php',
4746
'OCA\\Files_Trashbin\\Sabre\\RootCollection' => __DIR__ . '/..' . '/../lib/Sabre/RootCollection.php',
4847
'OCA\\Files_Trashbin\\Sabre\\TrashFile' => __DIR__ . '/..' . '/../lib/Sabre/TrashFile.php',
@@ -51,6 +50,7 @@ class ComposerStaticInitFiles_Trashbin
5150
'OCA\\Files_Trashbin\\Sabre\\TrashFolderFolder' => __DIR__ . '/..' . '/../lib/Sabre/TrashFolderFolder.php',
5251
'OCA\\Files_Trashbin\\Sabre\\TrashHome' => __DIR__ . '/..' . '/../lib/Sabre/TrashHome.php',
5352
'OCA\\Files_Trashbin\\Sabre\\TrashRoot' => __DIR__ . '/..' . '/../lib/Sabre/TrashRoot.php',
53+
'OCA\\Files_Trashbin\\Sabre\\TrashbinPlugin' => __DIR__ . '/..' . '/../lib/Sabre/TrashbinPlugin.php',
5454
'OCA\\Files_Trashbin\\Storage' => __DIR__ . '/..' . '/../lib/Storage.php',
5555
'OCA\\Files_Trashbin\\Trash\\BackendNotFoundException' => __DIR__ . '/..' . '/../lib/Trash/BackendNotFoundException.php',
5656
'OCA\\Files_Trashbin\\Trash\\ITrashBackend' => __DIR__ . '/..' . '/../lib/Trash/ITrashBackend.php',

apps/files_trashbin/composer/composer/installed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => '__root__',
44
'pretty_version' => 'dev-master',
55
'version' => 'dev-master',
6-
'reference' => 'd51429a47232bbf46a2be832ecfa711f102da802',
6+
'reference' => '3c99b642938e7810ccd05813cda96643a8ee5da5',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../',
99
'aliases' => array(),
@@ -13,7 +13,7 @@
1313
'__root__' => array(
1414
'pretty_version' => 'dev-master',
1515
'version' => 'dev-master',
16-
'reference' => 'd51429a47232bbf46a2be832ecfa711f102da802',
16+
'reference' => '3c99b642938e7810ccd05813cda96643a8ee5da5',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../',
1919
'aliases' => array(),

apps/files_trashbin/lib/Sabre/PropfindPlugin.php renamed to apps/files_trashbin/lib/Sabre/TrashbinPlugin.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@
2727
*/
2828
namespace OCA\Files_Trashbin\Sabre;
2929

30-
use OCA\DAV\Connector\Sabre\FilesPlugin;
3130
use OCP\IPreview;
3231
use Sabre\DAV\INode;
33-
use Sabre\DAV\PropFind;
3432
use Sabre\DAV\Server;
33+
use Sabre\DAV\PropFind;
3534
use Sabre\DAV\ServerPlugin;
35+
use Sabre\HTTP\RequestInterface;
36+
use Sabre\HTTP\ResponseInterface;
37+
use OCA\DAV\Connector\Sabre\FilesPlugin;
3638

37-
class PropfindPlugin extends ServerPlugin {
39+
class TrashbinPlugin extends ServerPlugin {
3840
public const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename';
3941
public const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location';
4042
public const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time';
@@ -56,6 +58,7 @@ public function initialize(Server $server) {
5658
$this->server = $server;
5759

5860
$this->server->on('propFind', [$this, 'propFind']);
61+
$this->server->on('afterMethod:GET', [$this,'httpGet']);
5962
}
6063

6164

@@ -110,4 +113,18 @@ public function propFind(PropFind $propFind, INode $node) {
110113
return '';
111114
});
112115
}
116+
117+
/**
118+
* Set real filename on trashbin \download
119+
*
120+
* @param RequestInterface $request
121+
* @param ResponseInterface $response
122+
*/
123+
public function httpGet(RequestInterface $request, ResponseInterface $response) {
124+
$path = $request->getPath();
125+
$node = $this->server->tree->getNodeForPath($path);
126+
if ($node instanceof ITrash) {
127+
$response->addHeader('Content-Disposition', 'attachment; filename="' . $node->getFilename() . '"');
128+
}
129+
}
113130
}

0 commit comments

Comments
 (0)