Skip to content

Commit

Permalink
Fix offloading logic
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Aug 6, 2024
1 parent 9f3390e commit 5d65802
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/Offload/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function getUsage(): OffloadUsage
/**
* Update the metadata of the image with the given ID.
*/
public function updateImageMetadata(string $imageId, int $fileSize = 0, $height = 'auto', $width = 'auto'): void
public function updateImageMetadata(string $imageId, int $fileSize = 0, $height = 'auto', $width = 'auto', $originalUrl = ''): void
{
if ('auto' !== $height && !is_int($height)) {
throw new InvalidArgumentException('Image height must be "auto" or an integer.');
Expand All @@ -127,6 +127,7 @@ public function updateImageMetadata(string $imageId, int $fileSize = 0, $height
'originalFileSize' => $fileSize,
'height' => is_int($height) ? max(0, $height) : $height,
'width' => is_int($width) ? max(0, $width) : $width,
'originalUrl' => $originalUrl,
'updateDynamo' => 'success',
]);
}
Expand Down Expand Up @@ -179,7 +180,7 @@ public function uploadImage(string $filename, string $imageUrl): string
}

try {
$this->httpClient->sendRequest('put', $uploadUrl, $image, [
$this->httpClient->sendRequest('PUT', $uploadUrl, $image, [
'Content-Type' => $fileMimeType,
]);
} catch (BadResponseException $exception) {
Expand All @@ -188,7 +189,7 @@ public function uploadImage(string $filename, string $imageUrl): string

$imagesize = getimagesize($filename);

$this->updateImageMetadata($imageId, filesize($filename) ?: 0, $imagesize && !empty($imagesize[1]) ? $imagesize[1] : 'auto', $imagesize && !empty($imagesize[0]) ? $imagesize[0] : 'auto');
$this->updateImageMetadata($imageId, filesize($filename) ?: 0, $imagesize && !empty($imagesize[1]) ? $imagesize[1] : 'auto', $imagesize && !empty($imagesize[0]) ? $imagesize[0] : 'auto', $imageUrl);

return $imageId;
}
Expand Down Expand Up @@ -237,8 +238,8 @@ private function getUploadApiCredentialsFromDashboardApi(): array
*/
private function requestToDashboardApi(): array
{
return $this->httpClient->sendRequest('post', sprintf('%s/optml/v2/account/details', $this->options['dashboard_api_url']), null, [
'Authorization' => sprintf('Bearer %s', $this->key),
return $this->httpClient->sendRequest('POST', sprintf('%s/optml/v2/account/details', $this->options['dashboard_api_url']), null, [
'Authorization' => sprintf('Bearer %s', $this->options['dashboard_api_key']),
'Content-Type' => 'application/json',
]);
}
Expand All @@ -252,7 +253,7 @@ private function requestToUploadApi(array $body): array
$this->options['upload_api_credentials'] = $this->getUploadApiCredentialsFromDashboardApi();
}

return $this->httpClient->sendRequest('post', $this->options['upload_api_url'], array_merge($this->options['upload_api_credentials'], $body), [
return $this->httpClient->sendRequest('POST', $this->options['upload_api_url'], array_merge($this->options['upload_api_credentials'], $body), [
'Content-Type' => 'application/json',
]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Optimole.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Optimole
/**
* The Optimole SDK version.
*/
public const VERSION = '1.2.0';
public const VERSION = '1.2.1';

/**
* The Optimole dashboard API URL.
Expand Down Expand Up @@ -94,6 +94,7 @@ public static function init(string $key, array $options = []): void
$options = array_merge([
'base_domain' => 'i.optimole.com',
'cache_buster' => '',
'dashboard_api_key' => '',
'dashboard_api_url' => self::DASHBOARD_API_URL,
'upload_api_url' => self::UPLOAD_API_URL,
], $options);
Expand Down

0 comments on commit 5d65802

Please sign in to comment.