77 */
88namespace OCA \DAV \Upload ;
99
10- use OC \Files \Filesystem ;
1110use OC \Files \View ;
1211use OCA \DAV \Connector \Sabre \Directory ;
1312use Sabre \DAV \Exception \Forbidden ;
1413use Sabre \DAV \ICollection ;
1514
1615class UploadHome implements ICollection {
16+ private ?Folder $ uploadFolder = null ;
17+
1718 public function __construct (
18- private array $ principalInfo ,
19- private CleanupService $ cleanupService ,
19+ private readonly array $ principalInfo ,
20+ private readonly CleanupService $ cleanupService ,
21+ private readonly IRootFolder $ rootFolder ,
22+ private readonly IUserSession $ userSession ,
2023 ) {
2124 }
2225
@@ -62,13 +65,24 @@ public function getLastModified() {
6265 return $ this ->impl ()->getLastModified ();
6366 }
6467
65- /**
66- * @return Directory
67- */
68- private function impl () {
69- $ view = $ this ->getView ();
70- $ rootInfo = $ view ->getFileInfo ('' );
71- return new Directory ($ view , $ rootInfo );
68+ private function getUploadFolder (): Folder {
69+ if ($ this ->uploadFolder === null ) {
70+ $ user = $ this ->userSession ->getUser ();
71+ if (!$ user ) {
72+ throw new Forbidden ('Not logged in ' );
73+ }
74+ $ path = '/ ' . $ user ->getUID () . '/uploads ' ;
75+ try {
76+ $ folder = $ this ->rootFolder ->get ($ path );
77+ if (!$ folder instanceof Folder) {
78+ throw new \Exception ('Upload folder is a file ' );
79+ }
80+ $ this ->uploadFolder = $ folder ;
81+ } catch (NotFoundException $ e ) {
82+ $ this ->uploadFolder = $ this ->rootFolder ->newFolder ($ path );
83+ }
84+ }
85+ return $ this ->uploadFolder ;
7286 }
7387
7488 private function getView () {
@@ -82,8 +96,6 @@ private function getView() {
8296 }
8397
8498 private function getStorage () {
85- $ view = $ this ->getView ();
86- $ storage = $ view ->getFileInfo ('' )->getStorage ();
87- return $ storage ;
99+ return $ this ->getUploadFolder ()->getStorage ();
88100 }
89101}
0 commit comments