Make mimetype also work for READ and DELETE operations
This commit is contained in:
parent
d3a1fbd9eb
commit
5996983e28
|
@ -27,7 +27,7 @@
|
|||
getCheck: function() {
|
||||
return {
|
||||
'class': 'OCA\\WorkflowEngine\\Check\\FileMimeType',
|
||||
'name': t('workflowengine', 'File mime type (upload)'),
|
||||
'name': t('workflowengine', 'File mime type'),
|
||||
'operators': [
|
||||
{'operator': 'is', 'name': t('workflowengine', 'is')},
|
||||
{'operator': '!is', 'name': t('workflowengine', 'is not')},
|
||||
|
|
|
@ -106,9 +106,48 @@ class FileMimeType extends AbstractStringCheck {
|
|||
}
|
||||
}
|
||||
|
||||
$this->mimeType[$this->storage->getId()][$this->path] = $this->storage->getMimeType($this->path);
|
||||
if ($this->mimeType[$this->storage->getId()][$this->path] === 'application/octet-stream') {
|
||||
$this->mimeType[$this->storage->getId()][$this->path] = $this->detectMimetypeFromPath();
|
||||
}
|
||||
|
||||
return $this->mimeType[$this->storage->getId()][$this->path];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function detectMimetypeFromPath() {
|
||||
$mimeType = $this->mimeTypeDetector->detectPath($this->path);
|
||||
if ($mimeType !== 'application/octet-stream' && $mimeType !== false) {
|
||||
return $mimeType;
|
||||
}
|
||||
|
||||
if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local')
|
||||
|| $this->storage->instanceOfStorage('\OC\Files\Storage\Home')
|
||||
|| $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) {
|
||||
$localFile = $this->storage->getLocalFile($this->path);
|
||||
if ($localFile !== false) {
|
||||
$mimeType = $this->mimeTypeDetector->detect($localFile);
|
||||
if ($mimeType !== false) {
|
||||
return $mimeType;
|
||||
}
|
||||
}
|
||||
|
||||
return 'application/octet-stream';
|
||||
} else {
|
||||
$handle = $this->storage->fopen($this->path, 'r');
|
||||
$data = fread($handle, 8024);
|
||||
fclose($handle);
|
||||
$mimeType = $this->mimeTypeDetector->detectString($data);
|
||||
if ($mimeType !== false) {
|
||||
return $mimeType;
|
||||
}
|
||||
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue