Passed
Push — master ( f7152c...d013ff )
by Roeland
11:16 queued 10s
created
apps/files_trashbin/lib/Controller/PreviewController.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -39,92 +39,92 @@
 block discarded – undo
39 39
 use OCP\IUserSession;
40 40
 
41 41
 class PreviewController extends Controller {
42
-	/** @var IRootFolder */
43
-	private $rootFolder;
44
-
45
-	/** @var ITrashManager */
46
-	private $trashManager;
47
-
48
-	/** @var IUserSession */
49
-	private $userSession;
50
-
51
-	/** @var IMimeTypeDetector */
52
-	private $mimeTypeDetector;
53
-
54
-	/** @var IPreview */
55
-	private $previewManager;
56
-
57
-	/** @var ITimeFactory */
58
-	private $time;
59
-
60
-	public function __construct(
61
-		string $appName,
62
-		IRequest $request,
63
-		IRootFolder $rootFolder,
64
-		ITrashManager $trashManager,
65
-		IUserSession $userSession,
66
-		IMimeTypeDetector $mimeTypeDetector,
67
-		IPreview $previewManager,
68
-		ITimeFactory $time
69
-	) {
70
-		parent::__construct($appName, $request);
71
-
72
-		$this->trashManager = $trashManager;
73
-		$this->rootFolder = $rootFolder;
74
-		$this->userSession = $userSession;
75
-		$this->mimeTypeDetector = $mimeTypeDetector;
76
-		$this->previewManager = $previewManager;
77
-		$this->time = $time;
78
-	}
79
-
80
-	/**
81
-	 * @NoAdminRequired
82
-	 * @NoCSRFRequired
83
-	 *
84
-	 * @return DataResponse|Http\FileDisplayResponse
85
-	 */
86
-	public function getPreview(
87
-		int $fileId,
88
-		int $x = 128,
89
-		int $y = 128
90
-	) {
91
-
92
-		if ($x === 0 || $y === 0) {
93
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
94
-		}
95
-
96
-		try {
97
-			$file = $this->trashManager->getTrashNodeById($this->userSession->getUser(), $fileId);
98
-			if ($file === null) {
99
-				return new DataResponse([], Http::STATUS_NOT_FOUND);
100
-			}
101
-			if ($file instanceof Folder) {
102
-				return new DataResponse([], Http::STATUS_BAD_REQUEST);
103
-			}
104
-
105
-			$pathParts = pathinfo($file->getName());
106
-			$extension = $pathParts['extension'] ?? '';
107
-			$fileName = $pathParts['filename'];
108
-			/*
42
+    /** @var IRootFolder */
43
+    private $rootFolder;
44
+
45
+    /** @var ITrashManager */
46
+    private $trashManager;
47
+
48
+    /** @var IUserSession */
49
+    private $userSession;
50
+
51
+    /** @var IMimeTypeDetector */
52
+    private $mimeTypeDetector;
53
+
54
+    /** @var IPreview */
55
+    private $previewManager;
56
+
57
+    /** @var ITimeFactory */
58
+    private $time;
59
+
60
+    public function __construct(
61
+        string $appName,
62
+        IRequest $request,
63
+        IRootFolder $rootFolder,
64
+        ITrashManager $trashManager,
65
+        IUserSession $userSession,
66
+        IMimeTypeDetector $mimeTypeDetector,
67
+        IPreview $previewManager,
68
+        ITimeFactory $time
69
+    ) {
70
+        parent::__construct($appName, $request);
71
+
72
+        $this->trashManager = $trashManager;
73
+        $this->rootFolder = $rootFolder;
74
+        $this->userSession = $userSession;
75
+        $this->mimeTypeDetector = $mimeTypeDetector;
76
+        $this->previewManager = $previewManager;
77
+        $this->time = $time;
78
+    }
79
+
80
+    /**
81
+     * @NoAdminRequired
82
+     * @NoCSRFRequired
83
+     *
84
+     * @return DataResponse|Http\FileDisplayResponse
85
+     */
86
+    public function getPreview(
87
+        int $fileId,
88
+        int $x = 128,
89
+        int $y = 128
90
+    ) {
91
+
92
+        if ($x === 0 || $y === 0) {
93
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
94
+        }
95
+
96
+        try {
97
+            $file = $this->trashManager->getTrashNodeById($this->userSession->getUser(), $fileId);
98
+            if ($file === null) {
99
+                return new DataResponse([], Http::STATUS_NOT_FOUND);
100
+            }
101
+            if ($file instanceof Folder) {
102
+                return new DataResponse([], Http::STATUS_BAD_REQUEST);
103
+            }
104
+
105
+            $pathParts = pathinfo($file->getName());
106
+            $extension = $pathParts['extension'] ?? '';
107
+            $fileName = $pathParts['filename'];
108
+            /*
109 109
 			 * Files in the root of the trashbin are timetamped.
110 110
 			 * So we have to strip that in order to properly detect the mimetype of the file.
111 111
 			 */
112
-			if (preg_match('/d\d+/', $extension)) {
113
-				$mimeType = $this->mimeTypeDetector->detectPath($fileName);
114
-			} else {
115
-				$mimeType = $this->mimeTypeDetector->detectPath($file->getName());
116
-			}
117
-
118
-			$f = $this->previewManager->getPreview($file, $x, $y, true, IPreview::MODE_FILL, $mimeType);
119
-			$response = new Http\FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
120
-
121
-			// Cache previews for 24H
122
-			$response->cacheFor(3600 * 24);
123
-			return $response;
124
-		} catch (NotFoundException $e) {
125
-			return new DataResponse([], Http::STATUS_NOT_FOUND);
126
-		} catch (\InvalidArgumentException $e) {
127
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
128
-		}
129
-	}
112
+            if (preg_match('/d\d+/', $extension)) {
113
+                $mimeType = $this->mimeTypeDetector->detectPath($fileName);
114
+            } else {
115
+                $mimeType = $this->mimeTypeDetector->detectPath($file->getName());
116
+            }
117
+
118
+            $f = $this->previewManager->getPreview($file, $x, $y, true, IPreview::MODE_FILL, $mimeType);
119
+            $response = new Http\FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
120
+
121
+            // Cache previews for 24H
122
+            $response->cacheFor(3600 * 24);
123
+            return $response;
124
+        } catch (NotFoundException $e) {
125
+            return new DataResponse([], Http::STATUS_NOT_FOUND);
126
+        } catch (\InvalidArgumentException $e) {
127
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
128
+        }
129
+    }
130 130
 }
Please login to merge, or discard this patch.