Completed
Push — master ( a1c2a2...10fa17 )
by
unknown
29:06
created
apps/dav/lib/Upload/UploadHome.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -18,109 +18,109 @@
 block discarded – undo
18 18
 use Sabre\DAV\ICollection;
19 19
 
20 20
 class UploadHome implements ICollection {
21
-	private string $uid;
22
-	private ?Folder $uploadFolder = null;
23
-
24
-	public function __construct(
25
-		private readonly array $principalInfo,
26
-		private readonly CleanupService $cleanupService,
27
-		private readonly IRootFolder $rootFolder,
28
-		private readonly IUserSession $userSession,
29
-		private readonly \OCP\Share\IManager $shareManager,
30
-	) {
31
-		[$prefix, $name] = \Sabre\Uri\split($principalInfo['uri']);
32
-		if ($prefix === 'principals/shares') {
33
-			$this->uid = $this->shareManager->getShareByToken($name)->getShareOwner();
34
-		} else {
35
-			$user = $this->userSession->getUser();
36
-			if (!$user) {
37
-				throw new Forbidden('Not logged in');
38
-			}
39
-
40
-			$this->uid = $user->getUID();
41
-		}
42
-	}
43
-
44
-	public function createFile($name, $data = null) {
45
-		throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
46
-	}
47
-
48
-	public function createDirectory($name) {
49
-		$this->impl()->createDirectory($name);
50
-
51
-		// Add a cleanup job
52
-		$this->cleanupService->addJob($this->uid, $name);
53
-	}
54
-
55
-	public function getChild($name): UploadFolder {
56
-		return new UploadFolder(
57
-			$this->impl()->getChild($name),
58
-			$this->cleanupService,
59
-			$this->getStorage(),
60
-			$this->uid,
61
-		);
62
-	}
63
-
64
-	public function getChildren(): array {
65
-		return array_map(function ($node) {
66
-			return new UploadFolder(
67
-				$node,
68
-				$this->cleanupService,
69
-				$this->getStorage(),
70
-				$this->uid,
71
-			);
72
-		}, $this->impl()->getChildren());
73
-	}
74
-
75
-	public function childExists($name): bool {
76
-		try {
77
-			$this->getChild($name);
78
-			return true;
79
-		} catch (NotFound $e) {
80
-			return false;
81
-		}
82
-	}
83
-
84
-	public function delete() {
85
-		$this->impl()->delete();
86
-	}
87
-
88
-	public function getName() {
89
-		[,$name] = \Sabre\Uri\split($this->principalInfo['uri']);
90
-		return $name;
91
-	}
92
-
93
-	public function setName($name) {
94
-		throw new Forbidden('Permission denied to rename this folder');
95
-	}
96
-
97
-	public function getLastModified() {
98
-		return $this->impl()->getLastModified();
99
-	}
100
-
101
-	private function getUploadFolder(): Folder {
102
-		if ($this->uploadFolder === null) {
103
-			$path = '/' . $this->uid . '/uploads';
104
-			try {
105
-				$folder = $this->rootFolder->get($path);
106
-				if (!$folder instanceof Folder) {
107
-					throw new \Exception('Upload folder is a file');
108
-				}
109
-				$this->uploadFolder = $folder;
110
-			} catch (NotFoundException $e) {
111
-				$this->uploadFolder = $this->rootFolder->newFolder($path);
112
-			}
113
-		}
114
-		return $this->uploadFolder;
115
-	}
116
-
117
-	private function impl(): Directory {
118
-		$folder = $this->getUploadFolder();
119
-		$view = new View($folder->getPath());
120
-		return new Directory($view, $folder);
121
-	}
122
-
123
-	private function getStorage() {
124
-		return $this->getUploadFolder()->getStorage();
125
-	}
21
+    private string $uid;
22
+    private ?Folder $uploadFolder = null;
23
+
24
+    public function __construct(
25
+        private readonly array $principalInfo,
26
+        private readonly CleanupService $cleanupService,
27
+        private readonly IRootFolder $rootFolder,
28
+        private readonly IUserSession $userSession,
29
+        private readonly \OCP\Share\IManager $shareManager,
30
+    ) {
31
+        [$prefix, $name] = \Sabre\Uri\split($principalInfo['uri']);
32
+        if ($prefix === 'principals/shares') {
33
+            $this->uid = $this->shareManager->getShareByToken($name)->getShareOwner();
34
+        } else {
35
+            $user = $this->userSession->getUser();
36
+            if (!$user) {
37
+                throw new Forbidden('Not logged in');
38
+            }
39
+
40
+            $this->uid = $user->getUID();
41
+        }
42
+    }
43
+
44
+    public function createFile($name, $data = null) {
45
+        throw new Forbidden('Permission denied to create file (filename ' . $name . ')');
46
+    }
47
+
48
+    public function createDirectory($name) {
49
+        $this->impl()->createDirectory($name);
50
+
51
+        // Add a cleanup job
52
+        $this->cleanupService->addJob($this->uid, $name);
53
+    }
54
+
55
+    public function getChild($name): UploadFolder {
56
+        return new UploadFolder(
57
+            $this->impl()->getChild($name),
58
+            $this->cleanupService,
59
+            $this->getStorage(),
60
+            $this->uid,
61
+        );
62
+    }
63
+
64
+    public function getChildren(): array {
65
+        return array_map(function ($node) {
66
+            return new UploadFolder(
67
+                $node,
68
+                $this->cleanupService,
69
+                $this->getStorage(),
70
+                $this->uid,
71
+            );
72
+        }, $this->impl()->getChildren());
73
+    }
74
+
75
+    public function childExists($name): bool {
76
+        try {
77
+            $this->getChild($name);
78
+            return true;
79
+        } catch (NotFound $e) {
80
+            return false;
81
+        }
82
+    }
83
+
84
+    public function delete() {
85
+        $this->impl()->delete();
86
+    }
87
+
88
+    public function getName() {
89
+        [,$name] = \Sabre\Uri\split($this->principalInfo['uri']);
90
+        return $name;
91
+    }
92
+
93
+    public function setName($name) {
94
+        throw new Forbidden('Permission denied to rename this folder');
95
+    }
96
+
97
+    public function getLastModified() {
98
+        return $this->impl()->getLastModified();
99
+    }
100
+
101
+    private function getUploadFolder(): Folder {
102
+        if ($this->uploadFolder === null) {
103
+            $path = '/' . $this->uid . '/uploads';
104
+            try {
105
+                $folder = $this->rootFolder->get($path);
106
+                if (!$folder instanceof Folder) {
107
+                    throw new \Exception('Upload folder is a file');
108
+                }
109
+                $this->uploadFolder = $folder;
110
+            } catch (NotFoundException $e) {
111
+                $this->uploadFolder = $this->rootFolder->newFolder($path);
112
+            }
113
+        }
114
+        return $this->uploadFolder;
115
+    }
116
+
117
+    private function impl(): Directory {
118
+        $folder = $this->getUploadFolder();
119
+        $view = new View($folder->getPath());
120
+        return new Directory($view, $folder);
121
+    }
122
+
123
+    private function getStorage() {
124
+        return $this->getUploadFolder()->getStorage();
125
+    }
126 126
 }
Please login to merge, or discard this patch.