feat: add S3-compatible storage provider (MinIO, Ceph, R2, etc.)
Adds a new 'S3-Compatible Storage' provider that works with any
S3-API-compatible object storage service, including MinIO, Ceph,
Cloudflare R2, Backblaze B2, and others.
Changes:
- New provider class: classes/providers/storage/s3-compatible-provider.php
- Provider key: s3compatible
- Reads user-configured endpoint URL from settings
- Uses path-style URL access (required by most S3-compatible services)
- Supports credentials via AS3CF_S3COMPAT_ACCESS_KEY_ID /
AS3CF_S3COMPAT_SECRET_ACCESS_KEY wp-config.php constants
- Disables AWS-specific features (Block Public Access, Object Ownership)
- New provider SVG icons (s3compatible.svg, -link.svg, -round.svg)
- Registered provider in main plugin class with endpoint setting support
- Updated StorageProviderSubPage to show endpoint URL input for S3-compatible
- Built pro settings bundle with rollup (Svelte 4.2.19)
- Added package.json and updated rollup.config.mjs for pro-only builds
This commit is contained in:
118
vendor/Aws3/Aws/Multipart/AbstractUploader.php
vendored
Normal file
118
vendor/Aws3/Aws/Multipart/AbstractUploader.php
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws\Multipart;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\AwsClientInterface as Client;
|
||||
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Exception\AwsException;
|
||||
use DeliciousBrains\WP_Offload_Media\Aws3\GuzzleHttp\Psr7;
|
||||
use InvalidArgumentException as IAE;
|
||||
use DeliciousBrains\WP_Offload_Media\Aws3\Psr\Http\Message\StreamInterface as Stream;
|
||||
abstract class AbstractUploader extends AbstractUploadManager
|
||||
{
|
||||
/** @var Stream Source of the data to be uploaded. */
|
||||
protected $source;
|
||||
/**
|
||||
* @param Client $client
|
||||
* @param mixed $source
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(Client $client, $source, array $config = [])
|
||||
{
|
||||
$this->source = $this->determineSource($source);
|
||||
parent::__construct($client, $config);
|
||||
}
|
||||
/**
|
||||
* Create a stream for a part that starts at the current position and
|
||||
* has a length of the upload part size (or less with the final part).
|
||||
*
|
||||
* @param Stream $stream
|
||||
*
|
||||
* @return Psr7\LimitStream
|
||||
*/
|
||||
protected function limitPartStream(Stream $stream)
|
||||
{
|
||||
// Limit what is read from the stream to the part size.
|
||||
return new Psr7\LimitStream($stream, $this->state->getPartSize(), $this->source->tell());
|
||||
}
|
||||
protected function getUploadCommands(callable $resultHandler)
|
||||
{
|
||||
// Determine if the source can be seeked.
|
||||
$seekable = $this->source->isSeekable() && $this->source->getMetadata('wrapper_type') === 'plainfile';
|
||||
for ($partNumber = 1; $this->isEof($seekable); $partNumber++) {
|
||||
// If we haven't already uploaded this part, yield a new part.
|
||||
if (!$this->state->hasPartBeenUploaded($partNumber)) {
|
||||
$partStartPos = $this->source->tell();
|
||||
if (!($data = $this->createPart($seekable, $partNumber))) {
|
||||
break;
|
||||
}
|
||||
$command = $this->client->getCommand($this->info['command']['upload'], $data + $this->state->getId());
|
||||
$command->getHandlerList()->appendSign($resultHandler, 'mup');
|
||||
$numberOfParts = $this->getNumberOfParts($this->state->getPartSize());
|
||||
if (isset($numberOfParts) && $partNumber > $numberOfParts) {
|
||||
throw new $this->config['exception_class']($this->state, new AwsException("Maximum part number for this job exceeded, file has likely been corrupted." . " Please restart this upload.", $command));
|
||||
}
|
||||
(yield $command);
|
||||
if ($this->source->tell() > $partStartPos) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Advance the source's offset if not already advanced.
|
||||
if ($seekable) {
|
||||
$this->source->seek(\min($this->source->tell() + $this->state->getPartSize(), $this->source->getSize()));
|
||||
} else {
|
||||
$this->source->read($this->state->getPartSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Generates the parameters for an upload part by analyzing a range of the
|
||||
* source starting from the current offset up to the part size.
|
||||
*
|
||||
* @param bool $seekable
|
||||
* @param int $number
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
protected abstract function createPart($seekable, $number);
|
||||
/**
|
||||
* Checks if the source is at EOF.
|
||||
*
|
||||
* @param bool $seekable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isEof($seekable)
|
||||
{
|
||||
return $seekable ? $this->source->tell() < $this->source->getSize() : !$this->source->eof();
|
||||
}
|
||||
/**
|
||||
* Turns the provided source into a stream and stores it.
|
||||
*
|
||||
* If a string is provided, it is assumed to be a filename, otherwise, it
|
||||
* passes the value directly to `Psr7\Utils::streamFor()`.
|
||||
*
|
||||
* @param mixed $source
|
||||
*
|
||||
* @return Stream
|
||||
*/
|
||||
private function determineSource($source)
|
||||
{
|
||||
// Use the contents of a file as the data source.
|
||||
if (\is_string($source)) {
|
||||
$source = Psr7\Utils::tryFopen($source, 'r');
|
||||
}
|
||||
// Create a source stream.
|
||||
$stream = Psr7\Utils::streamFor($source);
|
||||
if (!$stream->isReadable()) {
|
||||
throw new IAE('Source stream must be readable.');
|
||||
}
|
||||
return $stream;
|
||||
}
|
||||
protected function getNumberOfParts($partSize)
|
||||
{
|
||||
if ($sourceSize = $this->source->getSize()) {
|
||||
return \ceil($sourceSize / $partSize);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user