Skip to content

Commit 486c978

Browse files
authored
Merge pull request #345 from topcoder-platform/issues-335
Issues-335: ignore image pre-processing for bpm format
2 parents f1ad2bd + 25490f6 commit 486c978

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

vanilla/applications/dashboard/controllers/api/MediaApiController.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ public function delete_byUrl(array $query) {
9595
*
9696
* @param UploadedFile $upload An object representing an uploaded file.
9797
* @param string $type The upload type (e.g. "image").
98-
* @throws Exception if there was an error encountered when saving the upload.
98+
* @param bool $doImageProcessing
9999
* @return array
100+
* @throws Exception if there was an error encountered when saving the upload.
100101
*/
101-
private function doUpload(UploadedFile $upload, $type) {
102+
private function doUpload(UploadedFile $upload, string $type, bool $doImageProcessing) {
102103
$file = $upload->getFile();
103104

104105
$media = [
@@ -109,9 +110,11 @@ private function doUpload(UploadedFile $upload, $type) {
109110
'ForeignTable' => 'embed'
110111
];
111112

112-
switch ($type) {
113-
case self::TYPE_IMAGE:
114-
[$media['ImageWidth'], $media['ImageHeight']] = $this->preprocessImage($upload);
113+
if($doImageProcessing) {
114+
switch ($type) {
115+
case self::TYPE_IMAGE:
116+
[$media['ImageWidth'], $media['ImageHeight']] = $this->preprocessImage($upload);
117+
}
115118
}
116119

117120
$ext = pathinfo(strtolower($upload->getClientFilename()), PATHINFO_EXTENSION);
@@ -385,10 +388,12 @@ public function post(array $body) {
385388
$imageExtensions = array_keys(ImageResizer::getExtType());
386389
/** @var UploadedFile $file */
387390
$file = $body['file'];
388-
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION) ?? '';
391+
$extension = strtolower(pathinfo($file->getClientFilename(), PATHINFO_EXTENSION) ?? '');
389392
$type = in_array($extension, $imageExtensions) ? self::TYPE_IMAGE : self::TYPE_FILE;
390393

391-
$row = $this->doUpload($body['file'], $type);
394+
$doImageProcessing = $type === self::TYPE_IMAGE && in_array($extension, ['gif', 'jpeg', 'png', 'jpg']);
395+
396+
$row = $this->doUpload($body['file'], $type, $doImageProcessing);
392397

393398
$row = $this->normalizeOutput($row);
394399
$result = $out->validate($row);

0 commit comments

Comments
 (0)