Skip to content

Commit 6c39a7d

Browse files
authored
release: fixes
* Improve offloading mechanism * Fix offloaded attachments from other sources getting replaced when post is saved even if there is no associated attachment * Improve error handling
2 parents 51043b6 + ae080ed commit 6c39a7d

File tree

8 files changed

+188
-197
lines changed

8 files changed

+188
-197
lines changed

assets/src/dashboard/parts/connect/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const ConnectLayout = () => {
139139
}
140140
if ( 'success' !== response.code ) {
141141
setErrors({
142-
'error_register': optimoleDashboardApp.strings.error_register
142+
'error_register': response.message
143143
});
144144
}
145145
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"require": {
5656
"php": ">=7.4",
5757
"codeinwp/themeisle-sdk": "^3.3",
58-
"codeinwp/optimole-sdk": "^1.0",
58+
"codeinwp/optimole-sdk": "^1.1",
5959
"enshrined/svg-sanitize": "^0.18.0"
6060
}
6161
}

composer.lock

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/api.php

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ final class Optml_Api {
1515
* @var string Api root.
1616
*/
1717
private $api_root = 'https://dashboard.optimole.com/api/';
18-
/**
19-
* Optimole upload api root url.
20-
*
21-
* @var string Api root.
22-
*/
23-
private $upload_api_root = 'https://generateurls-prod.i.optimole.com/upload';
2418
/**
2519
* Optimole onboard api root url.
2620
*
@@ -48,9 +42,6 @@ public function __construct() {
4842
if ( defined( 'OPTIML_API_ROOT' ) ) {
4943
$this->api_root = constant( 'OPTIML_API_ROOT' );
5044
}
51-
if ( defined( 'OPTIML_UPLOAD_API_ROOT' ) ) {
52-
$this->upload_api_root = constant( 'OPTIML_UPLOAD_API_ROOT' );
53-
}
5445
if ( defined( 'OPTIML_ONBOARD_API_ROOT' ) ) {
5546
$this->onboard_api_root = constant( 'OPTIML_ONBOARD_API_ROOT' );
5647
}
@@ -258,19 +249,6 @@ private function build_args( $method, $url, $headers, $params ) {
258249
return $args;
259250
}
260251

261-
/**
262-
* Upload image to our servers using the generated signed url.
263-
*
264-
* @param string $upload_url The signed to url to upload the image to.
265-
* @param string $content_type Image mime type, it must match the actual mime type of the image.
266-
* @param string $image Image data from file_get_contents.
267-
* @return mixed
268-
*/
269-
public function upload_image( $upload_url, $content_type, $image ) {
270-
$args = $this->build_args( 'PUT', '', ['content-type' => $content_type], $image );
271-
return wp_remote_request( $upload_url, $args );
272-
}
273-
274252
/**
275253
* Check if the optimized url is available.
276254
*
@@ -287,47 +265,6 @@ public function check_optimized_url( $url ) {
287265
return true;
288266
}
289267

290-
/**
291-
* Get options for the signed urls api call.
292-
*
293-
* @param string $original_url Image original url.
294-
* @param string $delete Whether to delete a bucket object or not(ie. generate signed upload url).
295-
* @param string $table_id Remote id used on our servers.
296-
* @param string $update_table False or success.
297-
* @param string $get_url Whether to return a get url or not.
298-
* @param string $width Original image width.
299-
* @param string $height Original image height.
300-
* @param int $file_size Original file size.
301-
* @return array|WP_Error
302-
*/
303-
public function call_upload_api( $original_url = '', $delete = 'false', $table_id = '', $update_table = 'false', $get_url = 'false', $width = 'auto', $height = 'auto', $file_size = 0 ) {
304-
$body = [
305-
'secret' => Optml_Config::$secret,
306-
'userKey' => Optml_Config::$key,
307-
'originalUrl' => $original_url,
308-
'deleteUrl' => $delete,
309-
'id' => $table_id,
310-
'updateDynamo' => $update_table,
311-
'getUrl' => $get_url,
312-
'width' => $width,
313-
'height' => $height,
314-
'originalFileSize' => $file_size,
315-
];
316-
$body = wp_json_encode( $body );
317-
318-
$options = [
319-
'body' => $body,
320-
'headers' => [
321-
'Content-Type' => 'application/json',
322-
],
323-
'timeout' => 60,
324-
'blocking' => true,
325-
'sslverify' => false,
326-
'data_format' => 'body',
327-
];
328-
return wp_remote_post( $this->upload_api_root, $options );
329-
}
330-
331268
/**
332269
* Send a list of images to upload.
333270
*

inc/config.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ public static function init( $service_settings = [] ) {
127127
self::$service_url = constant( 'OPTML_CUSTOM_DOMAIN' );
128128
}
129129

130-
Optimole::init( self::$key, [ 'domain' => parse_url( self::$service_url, PHP_URL_HOST ) ] );
130+
$options = [ 'domain' => parse_url( self::$service_url, PHP_URL_HOST ) ];
131+
132+
if ( defined( 'OPTIML_API_ROOT' ) ) {
133+
$options['dashboard_api_url'] = OPTIML_API_ROOT;
134+
}
135+
136+
if ( defined( 'OPTIML_UPLOAD_API_ROOT' ) ) {
137+
$options['upload_api_url'] = OPTIML_UPLOAD_API_ROOT;
138+
}
139+
140+
if ( isset( $service_settings['cdn_key'], $service_settings['cdn_secret'] ) ) {
141+
$options['upload_api_credentials'] = [
142+
'userKey' => $service_settings['cdn_key'],
143+
'secret' => $service_settings['cdn_secret'],
144+
];
145+
}
146+
147+
Optimole::init( self::$key, $options );
131148
}
132149
}

0 commit comments

Comments
 (0)