Commit 9e97bef9 authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #21268 from owncloud/cleanup-OC_Helper-getFileNameMimeType

Use proper public API for OC_Helper::getFileNameMimeType
parents 551e553b ecdf88e4
......@@ -64,9 +64,10 @@ class Local {
if ($shares === false) {
return new \OC_OCS_Result(null, 404, 'could not get shares');
} else {
$mimetypeDetector = \OC::$server->getMimeTypeDetector();
foreach ($shares as &$share) {
if ($share['item_type'] === 'file' && isset($share['path'])) {
$share['mimetype'] = \OC_Helper::getFileNameMimeType($share['path']);
$share['mimetype'] = $mimetypeDetector->detectPath($share['path']);
if (\OC::$server->getPreviewManager()->isMimeSupported($share['mimetype'])) {
$share['isPreviewAvailable'] = true;
}
......@@ -227,9 +228,10 @@ class Local {
private static function getFilesSharedWithMe() {
try {
$shares = \OCP\Share::getItemsSharedWith('file');
$mimetypeDetector = \OC::$server->getMimeTypeDetector();
foreach ($shares as &$share) {
if ($share['item_type'] === 'file') {
$share['mimetype'] = \OC_Helper::getFileNameMimeType($share['file_target']);
$share['mimetype'] = $mimetypeDetector->detectPath($share['file_target']);
if (\OC::$server->getPreviewManager()->isMimeSupported($share['mimetype'])) {
$share['isPreviewAvailable'] = true;
}
......
......@@ -62,7 +62,7 @@ try{
$fileName = substr($fileName, 0, $i);
}
}
$mimetype = \OC_Helper::getFileNameMimeType($fileName);
$mimetype = \OC::$server->getMimeTypeDetector()->detectPath($fileName);
}
$preview->setMimetype($mimetype);
$preview->setMaxX($maxX);
......
......@@ -87,7 +87,7 @@ class Helper
$i = array(
'name' => $id,
'mtime' => $timestamp,
'mimetype' => $view->is_dir($dir . '/' . $entryName) ? 'httpd/unix-directory' : \OC_Helper::getFileNameMimeType($id),
'mimetype' => $view->is_dir($dir . '/' . $entryName) ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($id),
'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file',
'directory' => ($dir === '/') ? '' : $dir,
'size' => $size,
......
......@@ -48,7 +48,7 @@ if($maxX === 0 || $maxY === 0) {
try {
list($user, $file) = \OCA\Files_Versions\Storage::getUidAndFilename($file);
$preview = new \OC\Preview($user, 'files_versions', $file.'.v'.$version);
$mimetype = \OC_Helper::getFileNameMimeType($file);
$mimetype = \OC::$server->getMimeTypeDetector()->detectPath($file);
$preview->setMimetype($mimetype);
$preview->setMaxX($maxX);
$preview->setMaxY($maxY);
......
......@@ -329,7 +329,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
$stat['mtime'] = $mtime;
$this->getCache()->update($stat['fileid'], $stat);
} else {
$mimeType = \OC_Helper::getFileNameMimeType($path);
$mimeType = \OC::$server->getMimeTypeDetector()->detectPath($path);
// create new file
$stat = array(
'etag' => $this->getETag($path),
......
......@@ -225,7 +225,7 @@ abstract class Common implements Storage {
if ($this->is_dir($path)) {
return 'httpd/unix-directory';
} elseif ($this->file_exists($path)) {
return \OC_Helper::getFileNameMimeType($path);
return \OC::$server->getMimeTypeDetector()->detectPath($path);
} else {
return false;
}
......
......@@ -335,14 +335,6 @@ class OC_Helper {
return !file_exists($dir);
}
/**
* @return \OC\Files\Type\Detection
* @deprecated 8.2.0 use \OC::$server->getMimeTypeDetector()
*/
static public function getMimetypeDetector() {
return \OC::$server->getMimeTypeDetector();
}
/**
* @return \OC\Files\Type\TemplateManager
*/
......
......@@ -83,15 +83,6 @@ class Test_Helper extends \Test\TestCase {
$this->assertEquals($result, $expected);
}
function testGetFileNameMimeType() {
$this->assertEquals('text/plain', OC_Helper::getFileNameMimeType('foo.txt'));
$this->assertEquals('image/png', OC_Helper::getFileNameMimeType('foo.png'));
$this->assertEquals('image/png', OC_Helper::getFileNameMimeType('foo.bar.png'));
$this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType('.png'));
$this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType('foo'));
$this->assertEquals('application/octet-stream', OC_Helper::getFileNameMimeType(''));
}
function testGetStringMimeType() {
if (\OC_Util::runningOnWindows()) {
$this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows');
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment