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:
2026-03-03 12:30:18 +01:00
commit 3248cbb029
2086 changed files with 359427 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Rule;
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
/**
* A rule within a rule set. All rules contain a conditions property,
* which can be empty, and documentation about the rule.
*/
abstract class AbstractRule
{
private $conditions;
private $documentation;
public function __construct(array $definition)
{
$this->conditions = $definition['conditions'];
$this->documentation = isset($definition['documentation']) ? $definition['documentation'] : null;
}
/**
* @return array
*/
public function getConditions()
{
return $this->conditions;
}
/**
* @return mixed
*/
public function getDocumentation()
{
return $this->documentation;
}
/**
* Determines if all conditions for a given rule are met.
*
* @return boolean
*/
protected function evaluateConditions(array &$inputParameters, RulesetStandardLibrary $standardLibrary)
{
foreach ($this->getConditions() as $condition) {
$result = $standardLibrary->callFunction($condition, $inputParameters);
if (\is_null($result) || $result === \false) {
return \false;
}
}
return \true;
}
public abstract function evaluate(array $inputParameters, RulesetStandardLibrary $standardLibrary);
}

View File

@@ -0,0 +1,90 @@
<?php
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Rule;
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Ruleset\RulesetEndpoint;
class EndpointRule extends AbstractRule
{
/** @var array */
private $endpoint;
public function __construct(array $definition)
{
parent::__construct($definition);
$this->endpoint = $definition['endpoint'];
}
/**
* @return array
*/
public function getEndpoint()
{
return $this->endpoint;
}
/**
* If all the rule's conditions are met, return the resolved
* endpoint object.
*
* @return RulesetEndpoint | null
*/
public function evaluate(array $inputParameters, RulesetStandardLibrary $standardLibrary)
{
if ($this->evaluateConditions($inputParameters, $standardLibrary)) {
return $this->resolve($inputParameters, $standardLibrary);
}
return \false;
}
/**
* Given input parameters, resolve an endpoint in its entirety.
*
* @return RulesetEndpoint
*/
private function resolve(array $inputParameters, RulesetStandardLibrary $standardLibrary)
{
$uri = $standardLibrary->resolveValue($this->endpoint['url'], $inputParameters);
$properties = isset($this->endpoint['properties']) ? $this->resolveProperties($this->endpoint['properties'], $inputParameters, $standardLibrary) : null;
$headers = $this->resolveHeaders($inputParameters, $standardLibrary);
return new RulesetEndpoint($uri, $properties, $headers);
}
/**
* Recurse through an endpoint's `properties` attribute, resolving template
* strings when found. Return the fully resolved attribute.
*
* @return array
*/
private function resolveProperties($properties, array $inputParameters, RulesetStandardLibrary $standardLibrary)
{
if (\is_array($properties)) {
$propertiesArr = [];
foreach ($properties as $key => $val) {
$propertiesArr[$key] = $this->resolveProperties($val, $inputParameters, $standardLibrary);
}
return $propertiesArr;
} elseif ($standardLibrary->isTemplate($properties)) {
return $standardLibrary->resolveTemplateString($properties, $inputParameters);
}
return $properties;
}
/**
* If present, iterate through an endpoint's headers attribute resolving
* values along the way. Return the fully resolved attribute.
*
* @return array
*/
private function resolveHeaders(array $inputParameters, RulesetStandardLibrary $standardLibrary)
{
$headers = isset($this->endpoint['headers']) ? $this->endpoint['headers'] : null;
if (\is_null($headers)) {
return null;
}
$resolvedHeaders = [];
foreach ($headers as $headerName => $headerValues) {
$resolvedValues = [];
foreach ($headerValues as $value) {
$resolvedValue = $standardLibrary->resolveValue($value, $inputParameters, $standardLibrary);
$resolvedValues[] = $resolvedValue;
}
$resolvedHeaders[$headerName] = $resolvedValues;
}
return $resolvedHeaders;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Rule;
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Exception\UnresolvedEndpointException;
class ErrorRule extends AbstractRule
{
/** @var array */
private $error;
public function __construct($definition)
{
parent::__construct($definition);
$this->error = $definition['error'];
}
/**
* @return array
*/
public function getError()
{
return $this->error;
}
/**
* If an error rule's conditions are met, raise an
* UnresolvedEndpointError containing the fully resolved error string.
*
* @return null
* @throws UnresolvedEndpointException
*/
public function evaluate(array $inputParameters, RulesetStandardLibrary $standardLibrary)
{
if ($this->evaluateConditions($inputParameters, $standardLibrary)) {
$message = $standardLibrary->resolveValue($this->error, $inputParameters);
throw new UnresolvedEndpointException($message);
}
return \false;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Rule;
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Exception\UnresolvedEndpointException;
class RuleCreator
{
public static function create($type, $definition)
{
switch ($type) {
case 'endpoint':
return new EndpointRule($definition);
case 'error':
return new ErrorRule($definition);
case 'tree':
return new TreeRule($definition);
default:
throw new UnresolvedEndpointException('Unknown rule type ' . $type . ' must be of type `endpoint`, `tree` or `error`');
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Rule;
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
class TreeRule extends AbstractRule
{
/** @var array */
private $rules;
public function __construct(array $definition)
{
parent::__construct($definition);
$this->rules = $this->createRules($definition['rules']);
}
/**
* @return array
*/
public function getRules()
{
return $this->rules;
}
/**
* If a tree rule's conditions evaluate successfully, iterate over its
* subordinate rules and return a result if there is one. If any of the
* subsequent rules are trees, the function will recurse until it reaches
* an error or an endpoint rule
*
* @return mixed
*/
public function evaluate(array $inputParameters, RulesetStandardLibrary $standardLibrary)
{
if ($this->evaluateConditions($inputParameters, $standardLibrary)) {
foreach ($this->rules as $rule) {
$inputParametersCopy = $inputParameters;
$evaluation = $rule->evaluate($inputParametersCopy, $standardLibrary);
if ($evaluation !== \false) {
return $evaluation;
}
}
}
return \false;
}
private function createRules(array $rules)
{
$rulesList = [];
foreach ($rules as $rule) {
$ruleType = RuleCreator::create($rule['type'], $rule);
$rulesList[] = $ruleType;
}
return $rulesList;
}
}