Use svg mimeicons for empty text files
This commit is contained in:
parent
2946a63f6b
commit
4a9b0d5465
7 changed files with 75 additions and 7 deletions
|
@ -31,7 +31,7 @@ class Helper
|
|||
/**
|
||||
* Determine icon for a given file
|
||||
*
|
||||
* @param \OC\Files\FileInfo $file file info
|
||||
* @param \OCP\Files\FileInfo $file file info
|
||||
* @return string icon URL
|
||||
*/
|
||||
public static function determineIcon($file) {
|
||||
|
@ -111,7 +111,7 @@ class Helper
|
|||
$entry['mtime'] = $i['mtime'] * 1000;
|
||||
// only pick out the needed attributes
|
||||
$entry['icon'] = \OCA\Files\Helper::determineIcon($i);
|
||||
if (\OC::$server->getPreviewManager()->isMimeSupported($i['mimetype'])) {
|
||||
if (\OC::$server->getPreviewManager()->isAvailable($i)) {
|
||||
$entry['isPreviewAvailable'] = true;
|
||||
}
|
||||
$entry['name'] = $i->getName();
|
||||
|
|
|
@ -34,7 +34,8 @@ if ($maxX === 0 || $maxY === 0) {
|
|||
|
||||
try {
|
||||
$preview = new \OC\Preview(\OC_User::getUser(), 'files');
|
||||
if (!$always and !$preview->isMimeSupported(\OC\Files\Filesystem::getMimeType($file))) {
|
||||
$info = \OC\Files\Filesystem::getFileInfo($file);
|
||||
if (!$always and !$preview->isAvailable($info)) {
|
||||
\OC_Response::setStatus(404);
|
||||
} else {
|
||||
$preview->setFile($file);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
namespace OC;
|
||||
|
||||
use OC\Files\Filesystem;
|
||||
use OC\Preview\Provider;
|
||||
|
||||
require_once 'preview/image.php';
|
||||
|
@ -725,6 +726,35 @@ class Preview {
|
|||
$preview->deleteAllPreviews();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a preview can be generated for a file
|
||||
*
|
||||
* @param \OC\Files\FileInfo $file
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAvailable($file) {
|
||||
if (!\OC_Config::getValue('enable_previews', true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//check if there are preview backends
|
||||
if (empty(self::$providers)) {
|
||||
self::initProviders();
|
||||
}
|
||||
|
||||
//remove last element because it has the mimetype *
|
||||
$providers = array_slice(self::$providers, 0, -1);
|
||||
foreach ($providers as $supportedMimeType => $provider) {
|
||||
/**
|
||||
* @var \OC\Preview\Provider $provider
|
||||
*/
|
||||
if (preg_match($supportedMimeType, $file->getMimetype())) {
|
||||
return $provider->isAvailable($file);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $mimeType
|
||||
* @return bool
|
||||
|
|
|
@ -10,6 +10,16 @@ abstract class Provider {
|
|||
|
||||
abstract public function getMimeType();
|
||||
|
||||
/**
|
||||
* Check if a preview can be generated for $path
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function isAvailable($path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* get thumbnail for file at path $path
|
||||
* @param string $path Path of file
|
||||
|
|
|
@ -13,6 +13,16 @@ class TXT extends Provider {
|
|||
return '/text\/plain/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a preview can be generated for $path
|
||||
*
|
||||
* @param \OC\Files\FileInfo $file
|
||||
* @return bool
|
||||
*/
|
||||
public function isAvailable($file) {
|
||||
return $file->getSize() > 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param int $maxX
|
||||
|
|
|
@ -14,25 +14,35 @@ use OCP\IPreview;
|
|||
class PreviewManager implements IPreview {
|
||||
/**
|
||||
* return a preview of a file
|
||||
*
|
||||
* @param string $file The path to the file where you want a thumbnail from
|
||||
* @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
|
||||
* @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
|
||||
* @param boolean $scaleUp Scale smaller images up to the thumbnail size or not. Might look ugly
|
||||
* @return \OCP\Image
|
||||
*/
|
||||
function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false)
|
||||
{
|
||||
function createPreview($file, $maxX = 100, $maxY = 75, $scaleUp = false) {
|
||||
$preview = new \OC\Preview('', '/', $file, $maxX, $maxY, $scaleUp);
|
||||
return $preview->getPreview();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the passed mime type is supported
|
||||
*
|
||||
* @param string $mimeType
|
||||
* @return boolean
|
||||
*/
|
||||
function isMimeSupported($mimeType = '*')
|
||||
{
|
||||
function isMimeSupported($mimeType = '*') {
|
||||
return \OC\Preview::isMimeSupported($mimeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a preview can be generated for a file
|
||||
*
|
||||
* @param \OC\Files\FileInfo $file
|
||||
* @return bool
|
||||
*/
|
||||
function isAvailable($file) {
|
||||
return \OC\Preview::isAvailable($file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,4 +57,11 @@ interface IPreview
|
|||
*/
|
||||
function isMimeSupported($mimeType = '*');
|
||||
|
||||
/**
|
||||
* Check if a preview can be generated for a file
|
||||
*
|
||||
* @param \OCP\Files\FileInfo $file
|
||||
* @return bool
|
||||
*/
|
||||
function isAvailable($file);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue