Passed
Push — master ( 969f89...211926 )
by Morris
11:49
created
apps/files_sharing/lib/Controller/PublicPreviewController.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -40,141 +40,141 @@
 block discarded – undo
40 40
 
41 41
 class PublicPreviewController extends PublicShareController {
42 42
 
43
-	/** @var ShareManager */
44
-	private $shareManager;
45
-
46
-	/** @var IPreview */
47
-	private $previewManager;
48
-
49
-	/** @var IShare */
50
-	private $share;
51
-
52
-	public function __construct(string $appName,
53
-								IRequest $request,
54
-								ShareManager $shareManger,
55
-								ISession $session,
56
-								IPreview $previewManager) {
57
-		parent::__construct($appName, $request, $session);
58
-
59
-		$this->shareManager = $shareManger;
60
-		$this->previewManager = $previewManager;
61
-	}
62
-
63
-	protected function getPasswordHash(): string {
64
-		return $this->share->getPassword();
65
-	}
66
-
67
-	public function isValidToken(): bool {
68
-		try {
69
-			$this->share = $this->shareManager->getShareByToken($this->getToken());
70
-			return true;
71
-		} catch (ShareNotFound $e) {
72
-			return false;
73
-		}
74
-	}
75
-
76
-	protected function isPasswordProtected(): bool {
77
-		return $this->share->getPassword() !== null;
78
-	}
79
-
80
-
81
-	/**
82
-	 * @PublicPage
83
-	 * @NoCSRFRequired
84
-	 *
85
-	 * @param string $file
86
-	 * @param int $x
87
-	 * @param int $y
88
-	 * @param bool $a
89
-	 * @return DataResponse|FileDisplayResponse
90
-	 */
91
-	public function getPreview(
92
-		string $token,
93
-		string $file = '',
94
-		int $x = 32,
95
-		int $y = 32,
96
-		$a = false
97
-	) {
98
-
99
-		if ($token === '' || $x === 0 || $y === 0) {
100
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
101
-		}
102
-
103
-		try {
104
-			$share = $this->shareManager->getShareByToken($token);
105
-		} catch (ShareNotFound $e) {
106
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
107
-		}
108
-
109
-		if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
110
-			return new DataResponse([], Http::STATUS_FORBIDDEN);
111
-		}
112
-
113
-		try {
114
-			$node = $share->getNode();
115
-			if ($node instanceof Folder) {
116
-				$file = $node->get($file);
117
-			} else {
118
-				$file = $node;
119
-			}
120
-
121
-			$f = $this->previewManager->getPreview($file, $x, $y, !$a);
122
-			$response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
123
-			$response->cacheFor(3600 * 24);
124
-			return $response;
125
-		} catch (NotFoundException $e) {
126
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
127
-		} catch (\InvalidArgumentException $e) {
128
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
129
-		}
130
-	}
131
-
132
-	/**
133
-	 * @PublicPage
134
-	 * @NoCSRFRequired
135
-	 * @NoSameSiteCookieRequired
136
-	 *
137
-	 * @param $token
138
-	 * @return DataResponse|FileDisplayResponse
139
-	 */
140
-	public function directLink($token) {
141
-		// No token no image
142
-		if ($token === '') {
143
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
144
-		}
145
-
146
-		// No share no image
147
-		try {
148
-			$share = $this->shareManager->getShareByToken($token);
149
-		} catch (ShareNotFound $e) {
150
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
151
-		}
152
-
153
-		// No permissions no image
154
-		if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
155
-			return new DataResponse([], Http::STATUS_FORBIDDEN);
156
-		}
157
-
158
-		// Password protected shares have no direct link!
159
-		if ($share->getPassword() !== null) {
160
-			return new DataResponse([], Http::STATUS_FORBIDDEN);
161
-		}
162
-
163
-		try {
164
-			$node = $share->getNode();
165
-			if ($node instanceof Folder) {
166
-				// Direct link only works for single files
167
-				return new DataResponse([], Http::STATUS_BAD_REQUEST);
168
-			}
169
-
170
-			$f = $this->previewManager->getPreview($node, -1, -1, false);
171
-			$response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
172
-			$response->cacheFor(3600 * 24);
173
-			return $response;
174
-		} catch (NotFoundException $e) {
175
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
176
-		} catch (\InvalidArgumentException $e) {
177
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
178
-		}
179
-	}
43
+    /** @var ShareManager */
44
+    private $shareManager;
45
+
46
+    /** @var IPreview */
47
+    private $previewManager;
48
+
49
+    /** @var IShare */
50
+    private $share;
51
+
52
+    public function __construct(string $appName,
53
+                                IRequest $request,
54
+                                ShareManager $shareManger,
55
+                                ISession $session,
56
+                                IPreview $previewManager) {
57
+        parent::__construct($appName, $request, $session);
58
+
59
+        $this->shareManager = $shareManger;
60
+        $this->previewManager = $previewManager;
61
+    }
62
+
63
+    protected function getPasswordHash(): string {
64
+        return $this->share->getPassword();
65
+    }
66
+
67
+    public function isValidToken(): bool {
68
+        try {
69
+            $this->share = $this->shareManager->getShareByToken($this->getToken());
70
+            return true;
71
+        } catch (ShareNotFound $e) {
72
+            return false;
73
+        }
74
+    }
75
+
76
+    protected function isPasswordProtected(): bool {
77
+        return $this->share->getPassword() !== null;
78
+    }
79
+
80
+
81
+    /**
82
+     * @PublicPage
83
+     * @NoCSRFRequired
84
+     *
85
+     * @param string $file
86
+     * @param int $x
87
+     * @param int $y
88
+     * @param bool $a
89
+     * @return DataResponse|FileDisplayResponse
90
+     */
91
+    public function getPreview(
92
+        string $token,
93
+        string $file = '',
94
+        int $x = 32,
95
+        int $y = 32,
96
+        $a = false
97
+    ) {
98
+
99
+        if ($token === '' || $x === 0 || $y === 0) {
100
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
101
+        }
102
+
103
+        try {
104
+            $share = $this->shareManager->getShareByToken($token);
105
+        } catch (ShareNotFound $e) {
106
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
107
+        }
108
+
109
+        if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
110
+            return new DataResponse([], Http::STATUS_FORBIDDEN);
111
+        }
112
+
113
+        try {
114
+            $node = $share->getNode();
115
+            if ($node instanceof Folder) {
116
+                $file = $node->get($file);
117
+            } else {
118
+                $file = $node;
119
+            }
120
+
121
+            $f = $this->previewManager->getPreview($file, $x, $y, !$a);
122
+            $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
123
+            $response->cacheFor(3600 * 24);
124
+            return $response;
125
+        } catch (NotFoundException $e) {
126
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
127
+        } catch (\InvalidArgumentException $e) {
128
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
129
+        }
130
+    }
131
+
132
+    /**
133
+     * @PublicPage
134
+     * @NoCSRFRequired
135
+     * @NoSameSiteCookieRequired
136
+     *
137
+     * @param $token
138
+     * @return DataResponse|FileDisplayResponse
139
+     */
140
+    public function directLink($token) {
141
+        // No token no image
142
+        if ($token === '') {
143
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
144
+        }
145
+
146
+        // No share no image
147
+        try {
148
+            $share = $this->shareManager->getShareByToken($token);
149
+        } catch (ShareNotFound $e) {
150
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
151
+        }
152
+
153
+        // No permissions no image
154
+        if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
155
+            return new DataResponse([], Http::STATUS_FORBIDDEN);
156
+        }
157
+
158
+        // Password protected shares have no direct link!
159
+        if ($share->getPassword() !== null) {
160
+            return new DataResponse([], Http::STATUS_FORBIDDEN);
161
+        }
162
+
163
+        try {
164
+            $node = $share->getNode();
165
+            if ($node instanceof Folder) {
166
+                // Direct link only works for single files
167
+                return new DataResponse([], Http::STATUS_BAD_REQUEST);
168
+            }
169
+
170
+            $f = $this->previewManager->getPreview($node, -1, -1, false);
171
+            $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
172
+            $response->cacheFor(3600 * 24);
173
+            return $response;
174
+        } catch (NotFoundException $e) {
175
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
176
+        } catch (\InvalidArgumentException $e) {
177
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
178
+        }
179
+    }
180 180
 }
Please login to merge, or discard this patch.