Better detection of mimetypes while uploading a zip on a mac
This commit is contained in:
parent
24d90a4bb1
commit
d08240e364
|
@ -23,12 +23,13 @@ namespace OCA\WorkflowEngine\Check;
|
||||||
|
|
||||||
|
|
||||||
use OCP\Files\IMimeTypeDetector;
|
use OCP\Files\IMimeTypeDetector;
|
||||||
|
use OCP\Files\Storage\IStorage;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
class FileMimeType extends AbstractStringCheck {
|
class FileMimeType extends AbstractStringCheck {
|
||||||
|
|
||||||
/** @var string */
|
/** @var array */
|
||||||
protected $mimeType;
|
protected $mimeType;
|
||||||
|
|
||||||
/** @var IRequest */
|
/** @var IRequest */
|
||||||
|
@ -37,6 +38,12 @@ class FileMimeType extends AbstractStringCheck {
|
||||||
/** @var IMimeTypeDetector */
|
/** @var IMimeTypeDetector */
|
||||||
protected $mimeTypeDetector;
|
protected $mimeTypeDetector;
|
||||||
|
|
||||||
|
/** @var IStorage */
|
||||||
|
protected $storage;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
protected $path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param IL10N $l
|
* @param IL10N $l
|
||||||
* @param IRequest $request
|
* @param IRequest $request
|
||||||
|
@ -48,27 +55,58 @@ class FileMimeType extends AbstractStringCheck {
|
||||||
$this->mimeTypeDetector = $mimeTypeDetector;
|
$this->mimeTypeDetector = $mimeTypeDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getActualValue() {
|
protected function getActualValue() {
|
||||||
if ($this->mimeType !== null) {
|
if ($this->mimeType[$this->storage->getId()][$this->path] !== null) {
|
||||||
return $this->mimeType;
|
return $this->mimeType[$this->storage->getId()][$this->path];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->mimeType = '';
|
$this->mimeType[$this->storage->getId()][$this->path] = '';
|
||||||
if ($this->isWebDAVRequest()) {
|
if ($this->isWebDAVRequest()) {
|
||||||
if ($this->request->getMethod() === 'PUT') {
|
if ($this->request->getMethod() === 'PUT') {
|
||||||
$path = $this->request->getPathInfo();
|
$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'])) {
|
|
||||||
$files = $this->request->getUploadedFile('files');
|
|
||||||
if (isset($files['type'][0])) {
|
|
||||||
$this->mimeType = $files['type'][0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->mimeType;
|
|
||||||
|
if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
|
||||||
|
$files = $this->request->getUploadedFile('files');
|
||||||
|
if (isset($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[$this->storage->getId()][$this->path];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue