Skip non-supported mimes

pull/1/head
Victor Dubiniuk 9 years ago
parent 9aa4275508
commit e24b01bdd6

@ -12,6 +12,8 @@
namespace OCA\Documents\Db;
use OCA\Documents\Filter;
/**
* Session management
*
@ -47,6 +49,10 @@ class Session extends \OCA\Documents\Db {
$genesis = new \OCA\Documents\Genesis($file);
list($ownerView, $path) = $file->getOwnerViewAndPath();
$mimetype = $ownerView->getMimeType($path);
if (!Filter::isSupportedMimetype($mimetype)){
throw new \Exception( $path . ' is ' . $mimetype . ' and is not supported by Documents app');
}
$oldSession = new Session();
$oldSession->loadBy('file_id', $file->getFileId());

@ -13,9 +13,9 @@
namespace OCA\Documents;
class Filter {
protected static $filters = array();
protected static $filters = array();
public static function add($mimetype, $class){
public static function add($mimetype, $class){
self::$filters[$mimetype] = $class;
}
@ -36,9 +36,9 @@ namespace OCA\Documents;
}
return $data;
}
}
public static function write($content, $mimetype){
public static function write($content, $mimetype){
$data = array(
'mimetype' => $mimetype,
'content' => $content
@ -55,11 +55,20 @@ namespace OCA\Documents;
}
return $data;
}
}
public static function getAll(){
public static function getAll(){
return array_keys(self::$filters);
}
}
}
/**
* Checks if mimetype is supported by the app
* @param string $mimetype - checked mimetype
* @return bool
*/
public static function isSupportedMimetype($mimetype){
return in_array($mimetype, Storage::getSupportedMimetypes());
}
}

@ -97,7 +97,7 @@ class Storage {
return $documents;
}
protected static function getSupportedMimetypes(){
public static function getSupportedMimetypes(){
return array_merge(
array(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR),
Filter::getAll()

Loading…
Cancel
Save