Skip to content

Commit 3479b1c

Browse files
committed
Refactor OC\Server::getMimeTypeDetector
Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com>
1 parent 9d1547f commit 3479b1c

File tree

7 files changed

+21
-11
lines changed

7 files changed

+21
-11
lines changed

core/register_command.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
* along with this program. If not, see <http://www.gnu.org/licenses/>
4949
*
5050
*/
51+
52+
use OCP\Files\IMimeTypeDetector;
5153
use Psr\Log\LoggerInterface;
5254

5355
$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
@@ -163,11 +165,11 @@
163165
);
164166

165167
$application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory()));
166-
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader()));
167-
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector()));
168+
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->get(IMimeTypeDetector::class), \OC::$server->getMimeTypeLoader()));
169+
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->get(IMimeTypeDetector::class)));
168170
$application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
169171
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
170-
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
172+
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->get(IMimeTypeDetector::class), \OC::$server->getMemCacheFactory()));
171173

172174
$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class)));
173175
$application->add(new OC\Core\Command\Maintenance\Repair(

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OCP\Files\Cache\ICacheEntry;
4343
use OCP\Files\FileInfo;
4444
use OCP\Files\GenericFileException;
45+
use OCP\Files\IMimeTypeDetector;
4546
use OCP\Files\NotFoundException;
4647
use OCP\Files\ObjectStore\IObjectStore;
4748
use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload;
@@ -436,7 +437,7 @@ public function touch($path, $mtime = null) {
436437
//create a empty file, need to have at least on char to make it
437438
// work with all object storage implementations
438439
$this->file_put_contents($path, ' ');
439-
$mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
440+
$mimeType = \OC::$server->get(IMimeTypeDetector::class)->detectPath($path);
440441
$stat = [
441442
'etag' => $this->getETag($path),
442443
'mimetype' => $mimeType,
@@ -501,7 +502,7 @@ public function writeStream(string $path, $stream, int $size = null): int {
501502
$stat['mtime'] = $mTime;
502503
$stat['storage_mtime'] = $mTime;
503504

504-
$mimetypeDetector = \OC::$server->getMimeTypeDetector();
505+
$mimetypeDetector = \OC::$server->get(IMimeTypeDetector::class);
505506
$mimetype = $mimetypeDetector->detectPath($path);
506507

507508
$stat['mimetype'] = $mimetype;

lib/private/Files/Storage/Common.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
use OCP\Files\FileNameTooLongException;
5555
use OCP\Files\ForbiddenException;
5656
use OCP\Files\GenericFileException;
57+
use OCP\Files\IMimeTypeDetector;
5758
use OCP\Files\InvalidCharacterInPathException;
5859
use OCP\Files\InvalidDirectoryException;
5960
use OCP\Files\InvalidPathException;
@@ -254,7 +255,7 @@ public function getMimeType($path) {
254255
if ($this->is_dir($path)) {
255256
return 'httpd/unix-directory';
256257
} elseif ($this->file_exists($path)) {
257-
return \OC::$server->getMimeTypeDetector()->detectPath($path);
258+
return \OC::$server->get(IMimeTypeDetector::class)->detectPath($path);
258259
} else {
259260
return false;
260261
}

lib/private/Files/Storage/DAV.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function __construct($params) {
154154
$this->eventLogger = \OC::$server->get(IEventLogger::class);
155155
// This timeout value will be used for the download and upload of files
156156
$this->timeout = \OC::$server->get(IConfig::class)->getSystemValueInt('davstorage.request_timeout', 30);
157-
$this->mimeTypeDetector = \OC::$server->getMimeTypeDetector();
157+
$this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class);
158158
}
159159

160160
protected function init() {

lib/private/legacy/OC_Files.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OC\Files\View;
4545
use OC\Streamer;
4646
use OCP\Lock\ILockingProvider;
47+
use OCP\Files\IMimeTypeDetector;
4748
use OCP\Files\Events\BeforeZipCreatedEvent;
4849
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
4950
use OCP\EventDispatcher\IEventDispatcher;
@@ -80,7 +81,7 @@ private static function sendHeaders($filename, $name, array $rangeArray): void {
8081
header('Expires: 0');
8182
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
8283
$fileSize = \OC\Files\Filesystem::filesize($filename);
83-
$type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
84+
$type = \OC::$server->get(IMimeTypeDetector::class)->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
8485
if ($fileSize > -1) {
8586
if (!empty($rangeArray)) {
8687
http_response_code(206);
@@ -361,7 +362,7 @@ private static function getSingleFile($view, $dir, $name, $params) {
361362
// we have to check it before body contents
362363
$view->readfilePart($filename, $rangeArray[0]['size'], $rangeArray[0]['size']);
363364

364-
$type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
365+
$type = \OC::$server->get(IMimeTypeDetector::class)->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
365366

366367
foreach ($rangeArray as $range) {
367368
echo "\r\n--".self::getBoundary()."\r\n".

lib/private/legacy/template/functions.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
* along with this program. If not, see <http://www.gnu.org/licenses/>
3535
*
3636
*/
37+
38+
use OCP\Files\IMimeTypeDetector;
39+
3740
function p($string) {
3841
print(\OCP\Util::sanitizeHTML($string));
3942
}
@@ -255,7 +258,7 @@ function image_path($app, $image) {
255258
* @return string link to the image
256259
*/
257260
function mimetype_icon($mimetype) {
258-
return \OC::$server->getMimeTypeDetector()->mimeTypeIcon($mimetype);
261+
return \OC::$server->get(IMimeTypeDetector::class)->mimeTypeIcon($mimetype);
259262
}
260263

261264
/**

lib/public/Files.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
namespace OCP;
3737

38+
use OCP\Files\IMimeTypeDetector;
39+
3840
/**
3941
* This class provides access to the internal filesystem abstraction layer. Use
4042
* this class exclusively if you want to access files
@@ -61,7 +63,7 @@ public static function rmdirr($dir) {
6163
* @deprecated 14.0.0
6264
*/
6365
public static function getMimeType($path) {
64-
return \OC::$server->getMimeTypeDetector()->detect($path);
66+
return \OC::$server->get(IMimeTypeDetector::class)->detect($path);
6567
}
6668

6769
/**

0 commit comments

Comments
 (0)