Skip to content

Commit 5d65802

Browse files
committed
Fix offloading logic
1 parent 9f3390e commit 5d65802

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Offload/Manager.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function getUsage(): OffloadUsage
114114
/**
115115
* Update the metadata of the image with the given ID.
116116
*/
117-
public function updateImageMetadata(string $imageId, int $fileSize = 0, $height = 'auto', $width = 'auto'): void
117+
public function updateImageMetadata(string $imageId, int $fileSize = 0, $height = 'auto', $width = 'auto', $originalUrl = ''): void
118118
{
119119
if ('auto' !== $height && !is_int($height)) {
120120
throw new InvalidArgumentException('Image height must be "auto" or an integer.');
@@ -127,6 +127,7 @@ public function updateImageMetadata(string $imageId, int $fileSize = 0, $height
127127
'originalFileSize' => $fileSize,
128128
'height' => is_int($height) ? max(0, $height) : $height,
129129
'width' => is_int($width) ? max(0, $width) : $width,
130+
'originalUrl' => $originalUrl,
130131
'updateDynamo' => 'success',
131132
]);
132133
}
@@ -179,7 +180,7 @@ public function uploadImage(string $filename, string $imageUrl): string
179180
}
180181

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

189190
$imagesize = getimagesize($filename);
190191

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

193194
return $imageId;
194195
}
@@ -237,8 +238,8 @@ private function getUploadApiCredentialsFromDashboardApi(): array
237238
*/
238239
private function requestToDashboardApi(): array
239240
{
240-
return $this->httpClient->sendRequest('post', sprintf('%s/optml/v2/account/details', $this->options['dashboard_api_url']), null, [
241-
'Authorization' => sprintf('Bearer %s', $this->key),
241+
return $this->httpClient->sendRequest('POST', sprintf('%s/optml/v2/account/details', $this->options['dashboard_api_url']), null, [
242+
'Authorization' => sprintf('Bearer %s', $this->options['dashboard_api_key']),
242243
'Content-Type' => 'application/json',
243244
]);
244245
}
@@ -252,7 +253,7 @@ private function requestToUploadApi(array $body): array
252253
$this->options['upload_api_credentials'] = $this->getUploadApiCredentialsFromDashboardApi();
253254
}
254255

255-
return $this->httpClient->sendRequest('post', $this->options['upload_api_url'], array_merge($this->options['upload_api_credentials'], $body), [
256+
return $this->httpClient->sendRequest('POST', $this->options['upload_api_url'], array_merge($this->options['upload_api_credentials'], $body), [
256257
'Content-Type' => 'application/json',
257258
]);
258259
}

src/Optimole.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class Optimole
3333
/**
3434
* The Optimole SDK version.
3535
*/
36-
public const VERSION = '1.2.0';
36+
public const VERSION = '1.2.1';
3737

3838
/**
3939
* The Optimole dashboard API URL.
@@ -94,6 +94,7 @@ public static function init(string $key, array $options = []): void
9494
$options = array_merge([
9595
'base_domain' => 'i.optimole.com',
9696
'cache_buster' => '',
97+
'dashboard_api_key' => '',
9798
'dashboard_api_url' => self::DASHBOARD_API_URL,
9899
'upload_api_url' => self::UPLOAD_API_URL,
99100
], $options);

0 commit comments

Comments
 (0)