summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Preview/Generator.php56
-rw-r--r--lib/private/Settings/Manager.php3
-rw-r--r--lib/private/Share20/DefaultShareProvider.php6
-rw-r--r--lib/private/legacy/image.php19
4 files changed, 69 insertions, 15 deletions
diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php
index 402732ecda9..448a7a57580 100644
--- a/lib/private/Preview/Generator.php
+++ b/lib/private/Preview/Generator.php
@@ -128,9 +128,13 @@ class Generator {
// Try to get a cached preview. Else generate (and store) one
try {
- $file = $this->getCachedPreview($previewFolder, $width, $height, $crop);
- } catch (NotFoundException $e) {
- $file = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight);
+ try {
+ $file = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType());
+ } catch (NotFoundException $e) {
+ $file = $this->generatePreview($previewFolder, $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight);
+ }
+ } catch (\InvalidArgumentException $e) {
+ throw new NotFoundException();
}
return $file;
@@ -164,8 +168,8 @@ class Generator {
continue;
}
- $maxWidth = (int)$this->config->getSystemValue('preview_max_x', 2048);
- $maxHeight = (int)$this->config->getSystemValue('preview_max_y', 2048);
+ $maxWidth = (int)$this->config->getSystemValue('preview_max_x', 4096);
+ $maxHeight = (int)$this->config->getSystemValue('preview_max_y', 4096);
$preview = $this->helper->getThumbnail($provider, $file, $maxWidth, $maxHeight);
@@ -173,7 +177,15 @@ class Generator {
continue;
}
- $path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.png';
+ // Try to get the extention.
+ try {
+ $ext = $this->getExtention($preview->dataMimeType());
+ } catch (\InvalidArgumentException $e) {
+ // Just continue to the next iteration if this preview doesn't have a valid mimetype
+ continue;
+ }
+
+ $path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.' . $ext;
try {
$file = $previewFolder->newFile($path);
$file->putContent($preview->data());
@@ -201,14 +213,17 @@ class Generator {
* @param int $width
* @param int $height
* @param bool $crop
+ * @param string $mimeType
* @return string
*/
- private function generatePath($width, $height, $crop) {
+ private function generatePath($width, $height, $crop, $mimeType) {
$path = (string)$width . '-' . (string)$height;
if ($crop) {
$path .= '-crop';
}
- $path .= '.png';
+
+ $ext = $this->getExtention($mimeType);
+ $path .= '.' . $ext;
return $path;
}
@@ -340,7 +355,7 @@ class Generator {
}
- $path = $this->generatePath($width, $height, $crop);
+ $path = $this->generatePath($width, $height, $crop, $preview->dataMimeType());
try {
$file = $previewFolder->newFile($path);
$file->putContent($preview->data());
@@ -356,12 +371,13 @@ class Generator {
* @param int $width
* @param int $height
* @param bool $crop
+ * @param string $mimeType
* @return ISimpleFile
*
* @throws NotFoundException
*/
- private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, $crop) {
- $path = $this->generatePath($width, $height, $crop);
+ private function getCachedPreview(ISimpleFolder $previewFolder, $width, $height, $crop, $mimeType) {
+ $path = $this->generatePath($width, $height, $crop, $mimeType);
return $previewFolder->getFile($path);
}
@@ -381,4 +397,22 @@ class Generator {
return $folder;
}
+
+ /**
+ * @param string $mimeType
+ * @return null|string
+ * @throws \InvalidArgumentException
+ */
+ private function getExtention($mimeType) {
+ switch ($mimeType) {
+ case 'image/png':
+ return 'png';
+ case 'image/jpeg':
+ return 'jpg';
+ case 'image/gif':
+ return 'gif';
+ default:
+ throw new \InvalidArgumentException('Not a valid mimetype');
+ }
+ }
}
diff --git a/lib/private/Settings/Manager.php b/lib/private/Settings/Manager.php
index cd0af5e7bb2..efeedbe6fcc 100644
--- a/lib/private/Settings/Manager.php
+++ b/lib/private/Settings/Manager.php
@@ -47,6 +47,7 @@ use OCP\Lock\ILockingProvider;
use OCP\Settings\ISettings;
use OCP\Settings\IManager;
use OCP\Settings\ISection;
+use OCP\Util;
class Manager implements IManager {
/** @var ILogger */
@@ -344,7 +345,7 @@ class Manager implements IManager {
try {
return \OC::$server->query($className);
} catch (QueryException $e) {
- $this->log->logException($e);
+ $this->log->logException($e, ['level' => Util::INFO]);
throw $e;
}
}
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php
index 844b36b2994..b9ab7a46873 100644
--- a/lib/private/Share20/DefaultShareProvider.php
+++ b/lib/private/Share20/DefaultShareProvider.php
@@ -452,9 +452,9 @@ class DefaultShareProvider implements IShareProvider {
'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
'parent' => $qb->createNamedParameter($share->getId()),
- 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'),
- 'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
- 'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
+ 'item_type' => $qb->createNamedParameter($share->getNodeType()),
+ 'item_source' => $qb->createNamedParameter($share->getNodeId()),
+ 'file_source' => $qb->createNamedParameter($share->getNodeId()),
'file_target' => $qb->createNamedParameter($share->getTarget()),
'permissions' => $qb->createNamedParameter($share->getPermissions()),
'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php
index a7d702ac032..a0159b927f9 100644
--- a/lib/private/legacy/image.php
+++ b/lib/private/legacy/image.php
@@ -305,6 +305,25 @@ class OC_Image implements \OCP\IImage {
}
/**
+ * @return string Returns the mimetype of the data. Returns the empty string
+ * if the data is not valid.
+ */
+ public function dataMimeType() {
+ if (!$this->valid()) {
+ return '';
+ }
+
+ switch ($this->mimeType) {
+ case 'image/png':
+ case 'image/jpeg':
+ case 'image/gif':
+ return $this->mimeType;
+ default:
+ return 'image/png';
+ }
+ }
+
+ /**
* @return null|string Returns the raw image data.
*/
public function data() {