chg: [internal] Faster sending images

pull/7975/head
Jakub Onderka 2021-11-21 11:59:52 +01:00
parent c2bdf167a6
commit 63d9fc7274
3 changed files with 10 additions and 7 deletions

View File

@ -1031,9 +1031,13 @@ class AttributesController extends AppController
$width = isset($this->request->params['named']['width']) ? $this->request->params['named']['width'] : 200;
$height = isset($this->request->params['named']['height']) ? $this->request->params['named']['height'] : 200;
$imageData = $this->Attribute->getPictureData($attribute, $thumbnail, $width, $height);
$extension = pathinfo($attribute['Attribute']['value'], PATHINFO_EXTENSION);
$imageData = $this->Attribute->getPictureData($attribute, $thumbnail, $width, $height);
if ($imageData instanceof File) {
return $this->RestResponse->sendFile($imageData, strtolower($extension));
}
$this->response->body($imageData);
$this->response->type(strtolower($extension));
return $this->response;

View File

@ -156,7 +156,7 @@ class AttachmentTool
} else {
$filepath = $this->attachmentDir() . DS . $path;
$file = new File($filepath);
if (!$file->exists()) {
if (!is_file($file->path)) {
throw new NotFoundException("File '$filepath' does not exists.");
}
}

View File

@ -949,7 +949,7 @@ class Attribute extends AppModel
* @param bool $thumbnail
* @param int $maxWidth - When $thumbnail is true
* @param int $maxHeight - When $thumbnail is true
* @return string
* @return string|File
* @throws Exception
*/
public function getPictureData(array $attribute, $thumbnail = false, $maxWidth = 200, $maxHeight = 200)
@ -958,7 +958,7 @@ class Attribute extends AppModel
if ($maxWidth == 200 && $maxHeight == 200) {
// Return thumbnail directly if already exists
try {
return $this->getAttachment($attribute['Attribute'], $path_suffix = '_thumbnail');
return $this->loadAttachmentTool()->getFile($attribute['Attribute']['event_id'], $attribute['Attribute']['id'], $path_suffix = '_thumbnail');
} catch (NotFoundException $e) {
// pass
}
@ -973,11 +973,10 @@ class Attribute extends AppModel
$attribute['Attribute']['data'] = $imageData;
$this->saveAttachment($attribute['Attribute'], $path_suffix='_thumbnail');
}
} else {
$imageData = $this->getAttachment($attribute['Attribute']);
return $imageData;
}
return $imageData;
return $this->loadAttachmentTool()->getFile($attribute['Attribute']['event_id'], $attribute['Attribute']['id']);
}
/**