From 2d61ee3c13cda96c0cd4401b78bd27a586c374a9 Mon Sep 17 00:00:00 2001
From: Joas Schilling <coding@schilljs.com>
Date: Fri, 2 Sep 2016 13:38:27 +0200
Subject: [PATCH] Make mimetype also work for READ and DELETE operations

---
 apps/workflowengine/js/filemimetypeplugin.js  | Bin 2455 -> 2446 bytes
 .../workflowengine/lib/Check/FileMimeType.php |  39 ++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/apps/workflowengine/js/filemimetypeplugin.js b/apps/workflowengine/js/filemimetypeplugin.js
index 33cbbd7fd7e27428022f02f7cdf5329576bd3437..9fc9e3452f414af6cbefdd042da3a504879b2150 100644
GIT binary patch
delta 12
TcmbO(+$X#ton><Yi#jU+94`a9

delta 22
dcmeAZo-Vv0orP0DqqHC=KQTpfb2^JUD*#b*2Cx7C

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,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
 	 */
-- 
GitLab