Skip to content

Commit

Permalink
Fix getMetadata() to have data for S3 folders
Browse files Browse the repository at this point in the history
  • Loading branch information
bryannielsen committed Jul 10, 2023
1 parent a28a3cc commit 3fc87d0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
32 changes: 32 additions & 0 deletions Adapter/AbstractS3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace CloudFiles\Adapter;

use ExpressionEngine\Dependency\League\Flysystem;

abstract class AbstractS3 extends Flysystem\AwsS3v3\AwsS3Adapter
{

/**
* Get all the meta data of a file or directory.
*
* @param string $path
*
* @return false|array
*/
public function getMetadata($path)
{
$metadata = parent::getMetadata($path);

if ($metadata !== false) {
return $metadata;
}

// AWS looks for metadata with a headObject request, this returns 404 (false) on directories
if (!empty($this->listContents($path))) {
return ['type' => 'dir', 'path' => $path, 'size' => 0, 'timestamp' => null];
}

return false;
}
}
7 changes: 6 additions & 1 deletion Adapter/AwsS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use ExpressionEngine\Library\Filesystem\Adapter\AdapterTrait;
use ExpressionEngine\Service\Validation\ValidationAware;

class AwsS3 extends Flysystem\AwsS3v3\AwsS3Adapter implements AdapterInterface, ValidationAware
class AwsS3 extends AbstractS3 implements AdapterInterface, ValidationAware
{
use AdapterTrait;

Expand Down Expand Up @@ -118,7 +118,9 @@ public static function listAvailableRegions()
'af-south-1' => 'Africa (Cape Town)',
'ap-east-1' => 'Asia Pacific (Hong Kong)',
'ap-southeast-3' => 'Asia Pacific (Jakarta)',
'ap-southeast-4' => 'Asia Pacific (Melbourne)',
'ap-south-1' => 'Asia Pacific (Mumbai)',
'ap-south-2' => 'Asia Pacific (Hyderabad)',
'ap-northeast-3' => 'Asia Pacific (Osaka)',
'ap-northeast-2' => 'Asia Pacific (Seoul)',
'ap-southeast-1' => 'Asia Pacific (Singapore)',
Expand All @@ -133,7 +135,10 @@ public static function listAvailableRegions()
'eu-south-1' => 'Europe (Milan)',
'eu-west-3' => 'Europe (Paris)',
'eu-north-1' => 'Europe (Stockholm)',
'eu-south-2' => 'Europe (Spain)',
'eu-central-2' => 'Europe (Zurich)',
'me-south-1' => 'Middle East (Bahrain)',
'me-central-1' => 'Middle East (UAE)',
'sa-east-1' => 'South America (São Paulo)',
];
}
Expand Down
3 changes: 2 additions & 1 deletion Adapter/DigitalOcean.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use ExpressionEngine\Library\Filesystem\Adapter\AdapterTrait;
use ExpressionEngine\Service\Validation\ValidationAware;

class DigitalOcean extends Flysystem\AwsS3v3\AwsS3Adapter implements AdapterInterface, ValidationAware
class DigitalOcean extends AbstractS3 implements AdapterInterface, ValidationAware
{
use AdapterTrait;

Expand Down Expand Up @@ -125,6 +125,7 @@ public static function listAvailableRegions()
'fra1' => 'FRA1 - Frankfurt',
'tor1' => 'TOR1 - Toronto',
'blr1' => 'BLR1 - Bangalore',
'syd1' => 'SYD1 - Sydney',
];
}

Expand Down

0 comments on commit 3fc87d0

Please sign in to comment.