Skip to content

Commit

Permalink
Refactor OC\Server::getMimeTypeDetector
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Summers <[email protected]>
  • Loading branch information
summersab committed Aug 30, 2023
1 parent 9d1547f commit 3479b1c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
8 changes: 5 additions & 3 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OCP\Files\IMimeTypeDetector;
use Psr\Log\LoggerInterface;

$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
Expand Down Expand Up @@ -163,11 +165,11 @@
);

$application->add(new OC\Core\Command\Maintenance\DataFingerprint(\OC::$server->getConfig(), new \OC\AppFramework\Utility\TimeFactory()));
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader()));
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector()));
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->get(IMimeTypeDetector::class), \OC::$server->getMimeTypeLoader()));
$application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->get(IMimeTypeDetector::class)));
$application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->get(IMimeTypeDetector::class), \OC::$server->getMemCacheFactory()));

$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->query(\OC\Installer::class)));
$application->add(new OC\Core\Command\Maintenance\Repair(
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\FileInfo;
use OCP\Files\GenericFileException;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\NotFoundException;
use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload;
Expand Down Expand Up @@ -436,7 +437,7 @@ public function touch($path, $mtime = null) {
//create a empty file, need to have at least on char to make it
// work with all object storage implementations
$this->file_put_contents($path, ' ');
$mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
$mimeType = \OC::$server->get(IMimeTypeDetector::class)->detectPath($path);
$stat = [
'etag' => $this->getETag($path),
'mimetype' => $mimeType,
Expand Down Expand Up @@ -501,7 +502,7 @@ public function writeStream(string $path, $stream, int $size = null): int {
$stat['mtime'] = $mTime;
$stat['storage_mtime'] = $mTime;

$mimetypeDetector = \OC::$server->getMimeTypeDetector();
$mimetypeDetector = \OC::$server->get(IMimeTypeDetector::class);
$mimetype = $mimetypeDetector->detectPath($path);

$stat['mimetype'] = $mimetype;
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use OCP\Files\FileNameTooLongException;
use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidDirectoryException;
use OCP\Files\InvalidPathException;
Expand Down Expand Up @@ -254,7 +255,7 @@ public function getMimeType($path) {
if ($this->is_dir($path)) {
return 'httpd/unix-directory';
} elseif ($this->file_exists($path)) {
return \OC::$server->getMimeTypeDetector()->detectPath($path);
return \OC::$server->get(IMimeTypeDetector::class)->detectPath($path);
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function __construct($params) {
$this->eventLogger = \OC::$server->get(IEventLogger::class);
// This timeout value will be used for the download and upload of files
$this->timeout = \OC::$server->get(IConfig::class)->getSystemValueInt('davstorage.request_timeout', 30);
$this->mimeTypeDetector = \OC::$server->getMimeTypeDetector();
$this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class);
}

protected function init() {
Expand Down
5 changes: 3 additions & 2 deletions lib/private/legacy/OC_Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OC\Files\View;
use OC\Streamer;
use OCP\Lock\ILockingProvider;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Events\BeforeZipCreatedEvent;
use OCP\Files\Events\BeforeDirectFileDownloadEvent;
use OCP\EventDispatcher\IEventDispatcher;
Expand Down Expand Up @@ -80,7 +81,7 @@ private static function sendHeaders($filename, $name, array $rangeArray): void {
header('Expires: 0');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
$fileSize = \OC\Files\Filesystem::filesize($filename);
$type = \OC::$server->getMimeTypeDetector()->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
$type = \OC::$server->get(IMimeTypeDetector::class)->getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename));
if ($fileSize > -1) {
if (!empty($rangeArray)) {
http_response_code(206);
Expand Down Expand Up @@ -361,7 +362,7 @@ private static function getSingleFile($view, $dir, $name, $params) {
// we have to check it before body contents
$view->readfilePart($filename, $rangeArray[0]['size'], $rangeArray[0]['size']);

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

foreach ($rangeArray as $range) {
echo "\r\n--".self::getBoundary()."\r\n".
Expand Down
5 changes: 4 additions & 1 deletion lib/private/legacy/template/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OCP\Files\IMimeTypeDetector;

function p($string) {
print(\OCP\Util::sanitizeHTML($string));
}
Expand Down Expand Up @@ -255,7 +258,7 @@ function image_path($app, $image) {
* @return string link to the image
*/
function mimetype_icon($mimetype) {
return \OC::$server->getMimeTypeDetector()->mimeTypeIcon($mimetype);
return \OC::$server->get(IMimeTypeDetector::class)->mimeTypeIcon($mimetype);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/public/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

namespace OCP;

use OCP\Files\IMimeTypeDetector;

/**
* This class provides access to the internal filesystem abstraction layer. Use
* this class exclusively if you want to access files
Expand All @@ -61,7 +63,7 @@ public static function rmdirr($dir) {
* @deprecated 14.0.0
*/
public static function getMimeType($path) {
return \OC::$server->getMimeTypeDetector()->detect($path);
return \OC::$server->get(IMimeTypeDetector::class)->detect($path);
}

/**
Expand Down

0 comments on commit 3479b1c

Please sign in to comment.