I added a s3 storage driver, I wonder if this is the correct way to do it:
src/S3FilesystemDriver.php:
namespace Grey\Flarum;
use Flarum\Filesystem\DriverInterface;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Foundation\Config;
use Illuminate\Contracts\Filesystem\Cloud;
use League\Flysystem\Filesystem;
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter as S3Adapter;
use Illuminate\Filesystem\FilesystemAdapter;
class S3FilesystemDriver implements DriverInterface
{
public function build(string $diskName, SettingsRepositoryInterface $settings, Config $config, array $localConfig): Cloud
{
$client = new S3Client($config['s3']);
$adapter = new S3Adapter($client, $config['buckets'][$diskName]);
$filesystem = new Filesystem($adapter);
return new FilesystemAdapter($filesystem);
}
}
config.php:
return [
's3' => [
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => [
'key' => getenv('S3_ADDON_KEY_ID'),
'secret' => getenv('S3_ADDON_KEY_SECRET'),
],
],
'buckets' => [
'flarum-assets' => 's3',
'flarum-avatars' => 's3',
'flarum-uploads' => 's3',
],
];
extend.php:
use Flarum\Extend;
return [
(new Extend\Filesystem)->driver('s3', Grey\Flarum\S3FilesystemDriver::class),
];