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:
11
classes/pro/api/api.php
Normal file
11
classes/pro/api/api.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\API;
|
||||
|
||||
use Amazon_S3_And_CloudFront_Pro;
|
||||
use DeliciousBrains\WP_Offload_Media\API\API as Lite_API;
|
||||
|
||||
abstract class API extends Lite_API {
|
||||
/** @var Amazon_S3_And_CloudFront_Pro */
|
||||
protected $as3cf;
|
||||
}
|
||||
114
classes/pro/api/v1/licences.php
Normal file
114
classes/pro/api/v1/licences.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\API\V1;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\API\API;
|
||||
use WP_Error;
|
||||
use WP_REST_Request;
|
||||
use WP_REST_Response;
|
||||
|
||||
class Licences extends API {
|
||||
/** @var int */
|
||||
protected static $version = 1;
|
||||
|
||||
/** @var string */
|
||||
protected static $name = 'licences';
|
||||
|
||||
/**
|
||||
* Register REST API routes.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route(
|
||||
static::api_namespace(),
|
||||
static::route(),
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array( $this, 'get_licences' ),
|
||||
'permission_callback' => array( $this, 'check_permissions' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
static::api_namespace(),
|
||||
static::route(),
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array( $this, 'post_licences' ),
|
||||
'permission_callback' => array( $this, 'check_permissions' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
static::api_namespace(),
|
||||
static::route(),
|
||||
array(
|
||||
'methods' => 'DELETE',
|
||||
'callback' => array( $this, 'delete_licences' ),
|
||||
'permission_callback' => array( $this, 'check_permissions' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a REST GET request to retrieve licence info.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response|mixed
|
||||
*/
|
||||
public function get_licences( WP_REST_Request $request ) {
|
||||
$data = $request->get_json_params();
|
||||
|
||||
$force = ! empty( $data['force'] );
|
||||
|
||||
return $this->rest_ensure_response( 'get', static::name(), array(
|
||||
'licences' => $this->as3cf->get_licences( $force ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a REST POST request to activate supplied licence and return resultant licence info.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response|mixed
|
||||
*/
|
||||
public function post_licences( WP_REST_Request $request ) {
|
||||
$data = $request->get_json_params();
|
||||
$licence_key = empty( $data['licence'] ) ? '' : $data['licence'];
|
||||
$result = $this->as3cf->activate_licence( $licence_key );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $this->rest_ensure_response( 'post', static::name(), $result );
|
||||
}
|
||||
|
||||
return $this->rest_ensure_response( 'post', static::name(), array(
|
||||
'licences' => $this->as3cf->get_licences(),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a REST DELETE request to deactivate current licence and return resultant licence info.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response|mixed
|
||||
*/
|
||||
public function delete_licences( WP_REST_Request $request ) {
|
||||
if ( $this->as3cf->is_licence_constant() ) {
|
||||
return $this->rest_ensure_response( 'delete', static::name(),
|
||||
new WP_Error(
|
||||
'licence-constant',
|
||||
__( 'Your licence key is currently defined via a constant and must be removed manually.', 'amazon-s3-and-cloudfront' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// We currently have one licence applied to a plugin install.
|
||||
$this->as3cf->remove_licence();
|
||||
|
||||
return $this->rest_ensure_response( 'delete', static::name(), array(
|
||||
'licences' => $this->as3cf->get_licences(),
|
||||
) );
|
||||
}
|
||||
}
|
||||
153
classes/pro/api/v1/tools.php
Normal file
153
classes/pro/api/v1/tools.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace DeliciousBrains\WP_Offload_Media\Pro\API\V1;
|
||||
|
||||
use DeliciousBrains\WP_Offload_Media\Pro\API\API;
|
||||
use WP_Error;
|
||||
use WP_REST_Request;
|
||||
use WP_REST_Response;
|
||||
|
||||
class Tools extends API {
|
||||
/** @var int */
|
||||
protected static $version = 1;
|
||||
|
||||
/** @var string */
|
||||
protected static $name = 'tools';
|
||||
|
||||
/**
|
||||
* Register REST API routes.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route(
|
||||
static::api_namespace(),
|
||||
static::route(),
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array( $this, 'get_tools' ),
|
||||
'permission_callback' => array( $this, 'check_permissions' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
static::api_namespace(),
|
||||
static::route(),
|
||||
array(
|
||||
'methods' => 'PUT',
|
||||
'callback' => array( $this, 'put_tools' ),
|
||||
'permission_callback' => array( $this, 'check_permissions' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
static::api_namespace(),
|
||||
static::route(),
|
||||
array(
|
||||
'methods' => 'DELETE',
|
||||
'callback' => array( $this, 'delete_tools' ),
|
||||
'permission_callback' => array( $this, 'check_permissions' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a REST GET request and returns the current tools.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response|mixed
|
||||
*/
|
||||
public function get_tools( WP_REST_Request $request ) {
|
||||
return $this->rest_ensure_response( 'get', static::name(), array(
|
||||
'tools' => $this->as3cf->get_tools_info(),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a REST PUT request to perform an action on a tool and returns confirmation of whether it was ok or not.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response|mixed
|
||||
*/
|
||||
public function put_tools( WP_REST_Request $request ) {
|
||||
$data = $request->get_json_params();
|
||||
|
||||
if ( empty( $data['id'] ) ) {
|
||||
return $this->rest_ensure_response( 'put', static::name(),
|
||||
new WP_Error( 'missing-tool-id', __( 'Tool ID not supplied.', 'amazon-s3-and-cloudfront' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( empty( $data['action'] ) ) {
|
||||
return $this->rest_ensure_response( 'put', static::name(),
|
||||
new WP_Error( 'missing-tool-action', __( 'Action not supplied.', 'amazon-s3-and-cloudfront' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! in_array( $data['action'], array( 'start', 'cancel', 'pause_resume' ) ) ) {
|
||||
return $this->rest_ensure_response( 'put', static::name(),
|
||||
new WP_Error( 'invalid-tool-action', __( 'Invalid tool action supplied.', 'amazon-s3-and-cloudfront' ) )
|
||||
);
|
||||
}
|
||||
|
||||
$result = $this->as3cf->perform_tool_action( $data['id'], $data['action'] );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $this->rest_ensure_response( 'put', static::name(), $result );
|
||||
}
|
||||
|
||||
return $this->rest_ensure_response( 'put', static::name(), array(
|
||||
'ok' => $result,
|
||||
'tools' => $this->as3cf->get_tools_info(),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a REST DELETE request to dismiss a tool's errors.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return WP_REST_Response|mixed
|
||||
*/
|
||||
public function delete_tools( WP_REST_Request $request ) {
|
||||
$data = $request->get_json_params();
|
||||
|
||||
if ( empty( $data['id'] ) ) {
|
||||
return $this->rest_ensure_response( 'delete', static::name(),
|
||||
new WP_Error( 'missing-tool-id', __( 'Tool ID not supplied.', 'amazon-s3-and-cloudfront' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( empty( $data['blog_id'] ) ) {
|
||||
return $this->rest_ensure_response( 'delete', static::name(),
|
||||
new WP_Error( 'missing-blog-id', __( 'Blog ID not supplied.', 'amazon-s3-and-cloudfront' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( empty( $data['source_type'] ) ) {
|
||||
return $this->rest_ensure_response( 'delete', static::name(),
|
||||
new WP_Error( 'missing-source-type', __( 'Source Type not supplied.', 'amazon-s3-and-cloudfront' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( empty( $data['source_id'] ) ) {
|
||||
return $this->rest_ensure_response( 'delete', static::name(),
|
||||
new WP_Error( 'missing-source-id', __( 'Source ID not supplied.', 'amazon-s3-and-cloudfront' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset( $data['errors'] ) ) {
|
||||
$data['errors'] = 'all';
|
||||
}
|
||||
|
||||
$result = $this->as3cf->dismiss_tool_errors( $data['id'], $data['blog_id'], $data['source_type'], $data['source_id'], $data['errors'] );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $this->rest_ensure_response( 'delete', static::name(), $result );
|
||||
}
|
||||
|
||||
return $this->rest_ensure_response( 'delete', static::name(), array(
|
||||
'ok' => true,
|
||||
) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user