mirror of https://github.com/MISP/MISP
chg: [internal] Faster sending images
parent
c2bdf167a6
commit
63d9fc7274
|
@ -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;
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue