summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-09-02 13:37:23 +0200
committerJoas Schilling <coding@schilljs.com>2016-09-05 09:48:22 +0200
commitd08240e364b7dffe7f0e5dc8874069724371265b (patch)
treefe33ffe6068580d10f1364c7524cfa12ba31dee5
parent24d90a4bb19e8f4bf6644e6ab034153d5f57f25d (diff)
downloadnextcloud-server-d08240e364b7dffe7f0e5dc8874069724371265b.tar.gz
nextcloud-server-d08240e364b7dffe7f0e5dc8874069724371265b.zip
Better detection of mimetypes while uploading a zip on a mac
-rw-r--r--apps/workflowengine/lib/Check/FileMimeType.php54
1 files changed, 46 insertions, 8 deletions
diff --git a/apps/workflowengine/lib/Check/FileMimeType.php b/apps/workflowengine/lib/Check/FileMimeType.php
index 1de9a70a17d..43c856a7c98 100644
--- a/apps/workflowengine/lib/Check/FileMimeType.php
+++ b/apps/workflowengine/lib/Check/FileMimeType.php
@@ -23,12 +23,13 @@ namespace OCA\WorkflowEngine\Check;
use OCP\Files\IMimeTypeDetector;
+use OCP\Files\Storage\IStorage;
use OCP\IL10N;
use OCP\IRequest;
class FileMimeType extends AbstractStringCheck {
- /** @var string */
+ /** @var array */
protected $mimeType;
/** @var IRequest */
@@ -37,6 +38,12 @@ class FileMimeType extends AbstractStringCheck {
/** @var IMimeTypeDetector */
protected $mimeTypeDetector;
+ /** @var IStorage */
+ protected $storage;
+
+ /** @var string */
+ protected $path;
+
/**
* @param IL10N $l
* @param IRequest $request
@@ -49,26 +56,57 @@ class FileMimeType extends AbstractStringCheck {
}
/**
+ * @param IStorage $storage
+ * @param string $path
+ */
+ public function setFileInfo(IStorage $storage, $path) {
+ $this->storage = $storage;
+ $this->path = $path;
+ if (!isset($this->mimeType[$this->storage->getId()][$this->path])
+ || $this->mimeType[$this->storage->getId()][$this->path] === '') {
+ $this->mimeType[$this->storage->getId()][$this->path] = null;
+ }
+ }
+
+ /**
* @return string
*/
protected function getActualValue() {
- if ($this->mimeType !== null) {
- return $this->mimeType;
+ if ($this->mimeType[$this->storage->getId()][$this->path] !== null) {
+ return $this->mimeType[$this->storage->getId()][$this->path];
}
- $this->mimeType = '';
+ $this->mimeType[$this->storage->getId()][$this->path] = '';
if ($this->isWebDAVRequest()) {
if ($this->request->getMethod() === 'PUT') {
$path = $this->request->getPathInfo();
- $this->mimeType = $this->mimeTypeDetector->detectPath($path);
+ $this->mimeType[$this->storage->getId()][$this->path] = $this->mimeTypeDetector->detectPath($path);
+ return $this->mimeType[$this->storage->getId()][$this->path];
}
- } else if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
+ }
+
+ if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
$files = $this->request->getUploadedFile('files');
if (isset($files['type'][0])) {
- $this->mimeType = $files['type'][0];
+ $mimeType = $files['type'][0];
+ if ($this->mimeType === 'application/octet-stream') {
+ // Maybe not...
+ $mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]);
+ if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
+ $mimeType = $mimeTypeTest;
+ } else {
+ $mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]);
+ if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
+ $mimeType = $mimeTypeTest;
+ }
+ }
+ }
+ $this->mimeType[$this->storage->getId()][$this->path] = $mimeType;
+ return $mimeType;
}
}
- return $this->mimeType;
+
+ return $this->mimeType[$this->storage->getId()][$this->path];
}
/**