summaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-09-02 13:38:27 +0200
committerJoas Schilling <coding@schilljs.com>2016-09-05 09:48:23 +0200
commit2d61ee3c13cda96c0cd4401b78bd27a586c374a9 (patch)
treed0abddcf54813db6202dc73c1e7d1f9295bcc07f /apps/workflowengine/lib
parentd08240e364b7dffe7f0e5dc8874069724371265b (diff)
downloadnextcloud-server-2d61ee3c13cda96c0cd4401b78bd27a586c374a9.tar.gz
nextcloud-server-2d61ee3c13cda96c0cd4401b78bd27a586c374a9.zip
Make mimetype also work for READ and DELETE operations
Diffstat (limited to 'apps/workflowengine/lib')
-rw-r--r--apps/workflowengine/lib/Check/FileMimeType.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/apps/workflowengine/lib/Check/FileMimeType.php b/apps/workflowengine/lib/Check/FileMimeType.php
index 43c856a7c98..4a985840e60 100644
--- a/apps/workflowengine/lib/Check/FileMimeType.php
+++ b/apps/workflowengine/lib/Check/FileMimeType.php
@@ -106,10 +106,49 @@ 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
*/
protected function isWebDAVRequest() {