3.0.0
This commit is contained in:
parent
fb9f2726b8
commit
b755cb707e
|
|
@ -3,17 +3,20 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'provider' => getenv('FLYSYSTEM_OFFLOAD_PROVIDER') ?: 's3',
|
'provider' => getenv('FLYSYSTEM_OFFLOAD_PROVIDER') ?: 'webdav',
|
||||||
'visibility' => getenv('FLYSYSTEM_OFFLOAD_DEFAULT_VISIBILITY') ?: 'public',
|
'visibility' => getenv('FLYSYSTEM_OFFLOAD_DEFAULT_VISIBILITY') ?: 'public',
|
||||||
|
|
||||||
'stream' => [
|
'stream' => [
|
||||||
'protocol' => getenv('FLYSYSTEM_OFFLOAD_STREAM_PROTOCOL') ?: 'flysystem',
|
'protocol' => getenv('FLYSYSTEM_OFFLOAD_STREAM_PROTOCOL') ?: 'flysystem',
|
||||||
'root_prefix' => getenv('FLYSYSTEM_OFFLOAD_STREAM_ROOT_PREFIX') ?: '',
|
'root_prefix' => getenv('FLYSYSTEM_OFFLOAD_STREAM_ROOT_PREFIX') ?: '',
|
||||||
'host' => getenv('FLYSYSTEM_OFFLOAD_STREAM_HOST') ?: 'uploads',
|
'host' => getenv('FLYSYSTEM_OFFLOAD_STREAM_HOST') ?: '',
|
||||||
],
|
],
|
||||||
|
|
||||||
'uploads' => [
|
'uploads' => [
|
||||||
'base_url' => getenv('FLYSYSTEM_OFFLOAD_BASE_URL') ?: 'https://your-bucket.s3.amazonaws.com',
|
'base_url' => getenv('FLYSYSTEM_OFFLOAD_BASE_URL')
|
||||||
|
?: (getenv('FLYSYSTEM_OFFLOAD_WEBDAV_BASE_URL')
|
||||||
|
? rtrim(getenv('FLYSYSTEM_OFFLOAD_WEBDAV_BASE_URL'), '/') . '/' . trim(getenv('FLYSYSTEM_OFFLOAD_WEBDAV_PREFIX') ?: 'wordpress/uploads', '/')
|
||||||
|
: content_url('uploads')),
|
||||||
'delete_remote' => filter_var(
|
'delete_remote' => filter_var(
|
||||||
getenv('FLYSYSTEM_OFFLOAD_DELETE_REMOTE') ?: 'true',
|
getenv('FLYSYSTEM_OFFLOAD_DELETE_REMOTE') ?: 'true',
|
||||||
FILTER_VALIDATE_BOOLEAN
|
FILTER_VALIDATE_BOOLEAN
|
||||||
|
|
@ -26,7 +29,7 @@ return [
|
||||||
|
|
||||||
'admin' => [
|
'admin' => [
|
||||||
'enabled' => filter_var(
|
'enabled' => filter_var(
|
||||||
getenv('FLYSYSTEM_OFFLOAD_ADMIN_ENABLED') ?: 'false',
|
getenv('FLYSYSTEM_OFFLOAD_ADMIN_ENABLED') ?: 'true',
|
||||||
FILTER_VALIDATE_BOOLEAN
|
FILTER_VALIDATE_BOOLEAN
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
@ -49,16 +52,16 @@ return [
|
||||||
|
|
||||||
'webdav' => [
|
'webdav' => [
|
||||||
'enabled' => filter_var(
|
'enabled' => filter_var(
|
||||||
getenv('FLYSYSTEM_OFFLOAD_WEBDAV_ENABLED') ?: 'false',
|
getenv('FLYSYSTEM_OFFLOAD_WEBDAV_ENABLED') ?: 'true',
|
||||||
FILTER_VALIDATE_BOOLEAN
|
FILTER_VALIDATE_BOOLEAN
|
||||||
),
|
),
|
||||||
'base_url' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_BASE_URL') ?: '',
|
'base_url' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_BASE_URL') ?: 'https://webdav.example.com',
|
||||||
'endpoint' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_ENDPOINT') ?: '',
|
'endpoint' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_ENDPOINT') ?: getenv('FLYSYSTEM_OFFLOAD_WEBDAV_BASE_URL') ?: '',
|
||||||
'prefix' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_PREFIX') ?: 'wordpress/uploads',
|
'prefix' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_PREFIX') ?: 'wordpress/uploads',
|
||||||
'credentials' => [
|
'credentials' => [
|
||||||
'username' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_USERNAME') ?: '',
|
'username' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_USERNAME') ?: '',
|
||||||
'password' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_PASSWORD') ?: '',
|
'password' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_PASSWORD') ?: '',
|
||||||
'auth_type' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_AUTH_TYPE') ?: null,
|
'auth_type' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_AUTH_TYPE') ?: 'basic',
|
||||||
],
|
],
|
||||||
'stream' => [
|
'stream' => [
|
||||||
'register' => filter_var(
|
'register' => filter_var(
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,10 @@ final class MediaHooks {
|
||||||
public function __construct(FilesystemOperator $filesystem, array $config) {
|
public function __construct(FilesystemOperator $filesystem, array $config) {
|
||||||
$this->filesystem = $filesystem;
|
$this->filesystem = $filesystem;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->protocol = (string) $config['stream']['protocol'];
|
$this->protocol = (string) ($config['stream']['protocol'] ?? 'flysystem');
|
||||||
|
|
||||||
$this->streamRootPrefix = PathHelper::normalize((string) ($config['stream']['root_prefix'] ?? ''));
|
$this->streamRootPrefix = PathHelper::normalize((string) ($config['stream']['root_prefix'] ?? ''));
|
||||||
$this->streamHost = PathHelper::normalize((string) ($config['stream']['host'] ?? 'uploads')) ?: 'uploads';
|
$this->streamHost = PathHelper::normalize((string) ($config['stream']['host'] ?? ''));
|
||||||
$this->s3Prefix = PathHelper::normalize((string) ($config['s3']['prefix'] ?? ''));
|
$this->s3Prefix = PathHelper::normalize((string) ($config['s3']['prefix'] ?? ''));
|
||||||
|
|
||||||
$this->baseUrl = $this->normaliseBaseUrl((string) ($config['uploads']['base_url'] ?? content_url('uploads')));
|
$this->baseUrl = $this->normaliseBaseUrl((string) ($config['uploads']['base_url'] ?? content_url('uploads')));
|
||||||
|
|
@ -34,6 +34,15 @@ final class MediaHooks {
|
||||||
|
|
||||||
$this->deleteRemote = (bool) ($config['uploads']['delete_remote'] ?? true);
|
$this->deleteRemote = (bool) ($config['uploads']['delete_remote'] ?? true);
|
||||||
$this->preferLocal = (bool) ($config['uploads']['prefer_local_for_missing'] ?? false);
|
$this->preferLocal = (bool) ($config['uploads']['prefer_local_for_missing'] ?? false);
|
||||||
|
|
||||||
|
error_log(sprintf(
|
||||||
|
'[MediaHooks] Initialized - protocol: %s, host: %s, root_prefix: %s, base_url: %s, effective_base_url: %s',
|
||||||
|
$this->protocol,
|
||||||
|
$this->streamHost,
|
||||||
|
$this->streamRootPrefix,
|
||||||
|
$this->baseUrl,
|
||||||
|
$this->effectiveBaseUrl
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(): void {
|
public function register(): void {
|
||||||
|
|
@ -50,7 +59,7 @@ final class MediaHooks {
|
||||||
$normalizedSubdir = $subdir !== '' ? PathHelper::normalize($subdir) : '';
|
$normalizedSubdir = $subdir !== '' ? PathHelper::normalize($subdir) : '';
|
||||||
|
|
||||||
$streamSubdir = $normalizedSubdir !== '' ? '/' . $normalizedSubdir : '';
|
$streamSubdir = $normalizedSubdir !== '' ? '/' . $normalizedSubdir : '';
|
||||||
$streamBase = sprintf('%s://%s', $this->protocol, $this->streamHost);
|
$streamBase = sprintf('%s://%s', $this->protocol, $this->streamHost ?: 'default');
|
||||||
|
|
||||||
$uploads['path'] = $streamBase . $streamSubdir;
|
$uploads['path'] = $streamBase . $streamSubdir;
|
||||||
$uploads['basedir'] = $streamBase;
|
$uploads['basedir'] = $streamBase;
|
||||||
|
|
@ -63,6 +72,12 @@ final class MediaHooks {
|
||||||
$uploads['flysystem_host'] = $this->streamHost;
|
$uploads['flysystem_host'] = $this->streamHost;
|
||||||
$uploads['flysystem_root_prefix'] = $this->streamRootPrefix;
|
$uploads['flysystem_root_prefix'] = $this->streamRootPrefix;
|
||||||
|
|
||||||
|
error_log(sprintf(
|
||||||
|
'[MediaHooks] Upload dir filtered - path: %s, url: %s',
|
||||||
|
$uploads['path'],
|
||||||
|
$uploads['url']
|
||||||
|
));
|
||||||
|
|
||||||
return $uploads;
|
return $uploads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,6 +191,7 @@ final class MediaHooks {
|
||||||
private function toRemotePath(string $file): string {
|
private function toRemotePath(string $file): string {
|
||||||
$segments = [];
|
$segments = [];
|
||||||
|
|
||||||
|
// ✅ Solo agregar si NO están vacíos
|
||||||
if ($this->streamRootPrefix !== '') {
|
if ($this->streamRootPrefix !== '') {
|
||||||
$segments[] = $this->streamRootPrefix;
|
$segments[] = $this->streamRootPrefix;
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +202,15 @@ final class MediaHooks {
|
||||||
|
|
||||||
$segments[] = $file;
|
$segments[] = $file;
|
||||||
|
|
||||||
return PathHelper::join(...$segments);
|
$remotePath = PathHelper::join(...$segments);
|
||||||
|
|
||||||
|
error_log(sprintf(
|
||||||
|
'[MediaHooks] toRemotePath - file: %s, remote: %s',
|
||||||
|
$file,
|
||||||
|
$remotePath
|
||||||
|
));
|
||||||
|
|
||||||
|
return $remotePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function normaliseBaseUrl(string $baseUrl): string {
|
private function normaliseBaseUrl(string $baseUrl): string {
|
||||||
|
|
@ -220,7 +244,7 @@ final class MediaHooks {
|
||||||
return $baseUrl;
|
return $baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $baseUrl . '/' . $pathPrefix;
|
return $baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildPublicUrl(string $relativePath): string {
|
private function buildPublicUrl(string $relativePath): string {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue