use OCP\Files\File;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
+use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
continue;
}
- $path = strval($preview->width()) . '-' . strval($preview->height()) . '-max.png';
- $file = $previewFolder->newFile($path);
- $file->putContent($preview->data());
+ $path = (string)$preview->width() . '-' . (string)$preview->height() . '-max.png';
+ try {
+ $file = $previewFolder->newFile($path);
+ $file->putContent($preview->data());
+ } catch (NotPermittedException $e) {
+ throw new NotFoundException();
+ }
return $file;
}
* @return string
*/
private function generatePath($width, $height, $crop) {
- $path = strval($width) . '-' . strval($height);
+ $path = (string)$width . '-' . (string)$height;
if ($crop) {
$path .= '-crop';
}
/*
* Scale to the nearest power of two
*/
- $pow2height = pow(2, ceil(log($height) / log(2)));
- $pow2width = pow(2, ceil(log($width) / log(2)));
+ $pow2height = 2 ** ceil(log($height) / log(2));
+ $pow2width = 2 ** ceil(log($width) / log(2));
$ratioH = $height / $pow2height;
$ratioW = $width / $pow2width;
if ($ratioH < $ratioW) {
$width = $pow2width;
- $height = $height / $ratioW;
+ $height /= $ratioW;
} else {
$height = $pow2height;
- $width = $width / $ratioH;
+ $width /= $ratioH;
}
}
if ($height > $maxHeight) {
$ratio = $height / $maxHeight;
$height = $maxHeight;
- $width = $width / $ratio;
+ $width /= $ratio;
}
if ($width > $maxWidth) {
$ratio = $width / $maxWidth;
$width = $maxWidth;
- $height = $height / $ratio;
+ $height /= $ratio;
}
return [(int)round($width), (int)round($height)];
}
$path = $this->generatePath($width, $height, $crop);
- $file = $previewFolder->newFile($path);
- $file->putContent($preview->data());
+ try {
+ $file = $previewFolder->newFile($path);
+ $file->putContent($preview->data());
+ } catch (NotPermittedException $e) {
+ throw new NotFoundException();
+ }
return $file;
}