Skip to content

Commit

Permalink
* Fixed a bug with the AWS SDK with DigitalOcean that resulted in url…
Browse files Browse the repository at this point in the history
…s missing the scheme (eg the https:// part). This

  bug seems to be with the AWS SDK MultiRegionClient and not with Media Cloud.
* Fixed another AWS SDK MultiRegionClient bug where the path style endpoint setting was being ignored.
  • Loading branch information
jawngee committed Nov 8, 2022
1 parent 8802781 commit 7601aee
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
39 changes: 39 additions & 0 deletions classes/Tools/Storage/Driver/S3/DigitalOceanStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace MediaCloud\Plugin\Tools\Storage\Driver\S3;

use MediaCloud\Plugin\Tools\Storage\StorageException;
use function MediaCloud\Plugin\Utilities\anyNull;
use MediaCloud\Plugin\Wizard\WizardBuilder;

Expand Down Expand Up @@ -71,6 +72,44 @@ public static function settingsErrorOptionName() {
//region URLs
//endregion

//region Uploads


/**
* Uploads a file, returning the new URL for the file.
*
* @param string $key
* @param string $fileName
* @param string $acl
* @param string|null $cacheControl
* @param string|null $expires
* @param string|null $contentType
* @param string|null $contentEncoding
* @param string|null $contentLength
* @throws StorageException
* @return string
*/
public function upload($key, $fileName, $acl, $cacheControl=null, $expires=null, $contentType=null, $contentEncoding=null, $contentLength=null) {
$uploadedUrl = parent::upload($key, $fileName, $acl, $cacheControl, $expires, $contentType, $contentEncoding, $contentLength);
if ($uploadedUrl) {
if (empty(parse_url($uploadedUrl, PHP_URL_SCHEME))) {
$uploadedUrl = "https://{$uploadedUrl}";
}

if (!$this->settings->endPointPathStyle) {
$urlParts = parse_url($uploadedUrl);
if ($urlParts && strpos($urlParts['path'], "/{$this->settings->bucket}/") === 0) {
$fixedPath = substr($urlParts['path'], strlen($this->settings->bucket) + 1);
$uploadedUrl = "${urlParts['scheme']}://{$this->settings->bucket}.${urlParts['host']}{$fixedPath}";
}

}
}

return $uploadedUrl;
}
//endregion

//region Direct Uploads
public function enqueueUploaderScripts() {
wp_enqueue_script('ilab-media-direct-upload-s3', ILAB_PUB_JS_URL.'/ilab-media-direct-upload-s3.js', [], MEDIA_CLOUD_VERSION, true);
Expand Down
6 changes: 6 additions & 0 deletions classes/Tools/Storage/StorageTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,9 @@ public function getAttachmentURL( $url, $post_id )
$new_url = str_replace( '//s3-.amazonaws', '//s3.amazonaws', $new_url );
}
}
if ( !parse_url( $new_url, PHP_URL_SCHEME ) ) {
$new_url = 'https://' . $new_url;
}
return ( $new_url ?: $url );
}

Expand Down Expand Up @@ -2447,6 +2450,9 @@ public function processFile(
StorageToolSettings::cacheControl(),
StorageToolSettings::expires()
);
if ( $url && !parse_url( $url, PHP_URL_SCHEME ) ) {
$url = 'https://' . $url;
}
Logger::info(
"\tFinished uploading {$filename} to S3.",
[],
Expand Down
4 changes: 2 additions & 2 deletions ilab-media-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/interfacelab/ilab-media-tools
Description: Automatically upload media to Amazon S3 and integrate with Imgix, a real-time image processing CDN. Boosts site performance and simplifies workflows.
Author: interfacelab
Version: 4.5.7
Version: 4.5.9
Requires PHP: 7.4
Author URI: http://interfacelab.io
*/
Expand Down Expand Up @@ -95,7 +95,7 @@
}

// Version Defines
define( 'MEDIA_CLOUD_VERSION', '4.5.7' );
define( 'MEDIA_CLOUD_VERSION', '4.5.9' );
define( 'MEDIA_CLOUD_INFO_VERSION', '4.0.2' );
define( 'MCLOUD_IS_BETA', false );
// Debugging
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 4.9
Tested up to: 6.1
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Stable tag: 4.5.6
Stable tag: 4.5.9
Requires PHP: 7.4

Automatically store media on Amazon S3, Cloudflare R2, Google Cloud Storage, DigitalOcean Spaces + others. Serve CSS/JS assets through CDNs. Integrate with Imgix.
Expand Down Expand Up @@ -105,6 +105,12 @@ Imgix is a content delivery network with a twist. In addition to distributing y

== Changelog ==

= 4.5.9 - 11/08/2022 =

* Fixed a bug with the AWS SDK with DigitalOcean that resulted in urls missing the scheme (eg the https:// part). This
bug seems to be with the AWS SDK MultiRegionClient and not with Media Cloud.
* Fixed another AWS SDK MultiRegionClient bug where the path style endpoint setting was being ignored.

= 4.5.7 - 11/07/2022 =

* Fixed internal help links
Expand Down

0 comments on commit 7601aee

Please sign in to comment.