XF2 : API FlySystem adapter and CDN Store zone

zeus1971

Collaborate
Collaborate
Registered
Joined
Apr 18, 2020
Messages
310
Points
73

Reputation:

I think I have done some steps...in this nightmare configuration...
Let see :
I created a storage zone in BUNNYCDN, connected to my pullzone = cdn.mydomain.com
Now...following the xenforo documentation for S3, I found that there are adapters for Bunnycdn too... ( yeah ! great ! but wait....:rolleyes: :ROFLMAO: )
Here the doc links :
GitHub - BunnyWay/BunnyCDN.PHP.Storage: The official PHP library used for interacting with the BunnyCDN Storage API.
GitHub - PlatformCommunity/flysystem-bunnycdn: A flysystem adapter for BunnyCDN's storage
Using DigitalOcean Spaces or Amazon S3 for file storage in XF 2.x | XenForo community

The problem is that this code ( in config.php ) doesn't work...

PHP:
use BunnyCDN\Storage\BunnyCDNStorage;
use League\Flysystem\Filesystem;
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter;

$client = new BunnyCDNAdapter(new BunnyCDNStorage('myzone', 'apikey', 'de'));
$filesystem = new Filesystem($client);

$config['fsAdapters']['data'] = function() use($filesystem)
{
   return new \League\Flysystem\Filesystem($filesystem(), 'data');
};

$config['externalDataUrl'] = function($externalPath, $canonical)
{
   return 'https://cdn.mydomain.com/forum/data/' . $externalPath;
};

$config['fsAdapters']['internal-data'] = function() use($filesystem)
{
   return new \League\Flysystem\Filesystem($filesystem(),  'internal_data');
};

Probably there are errors...or wrong path, or wrong reference, but no idea where...
HELP
 

zeus1971

Collaborate
Collaborate
Registered
Joined
Apr 18, 2020
Messages
310
Points
73

Reputation:

of course "myzone,apikey,mydomain" are example...
I put the corrects there.
 

zeus1971

Collaborate
Collaborate
Registered
Joined
Apr 18, 2020
Messages
310
Points
73

Reputation:

I change the code, and now at least XF opens...
But....
Error: Class 'PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter' not found in src/config.php

And the path and class exists !
:mad:
 

Soft4Win

Developer
Staff member
Moderator
Collaborate
Registered
Joined
Apr 27, 2019
Messages
370
Points
103

Reputation:

@zeus1971

Code:
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter;

Make sure this file have correct namespace, go to that file, and copy the namespace and replace in the config.php
 

zeus1971

Collaborate
Collaborate
Registered
Joined
Apr 18, 2020
Messages
310
Points
73

Reputation:

@Soft4Win yes, for sure the problem s there, because if I try a simply autoload, I get a 500 error opening my dev site.
I have readen the guide, very quick, but omg... too difficult for me.
thanks in any case
 

zeus1971

Collaborate
Collaborate
Registered
Joined
Apr 18, 2020
Messages
310
Points
73

Reputation:

@Soft4Win , one question...
I saw that we can use also FTP adapters, and Bunny has this opcion of course for StorageZone (<attached to my CDN pull zone), and it seems that is native with FLYSSYTEM, so no addon or something strange needed.
My question is : people try to use others protocols becouse FTP is very slow or why ?

https://flysystem.thephpleague.com/v1/docs/adapter/ftp/

I mean, would be possible to use FTP also has internal and external data path with good performance ?
 
Last edited:

Soft4Win

Developer
Staff member
Moderator
Collaborate
Registered
Joined
Apr 27, 2019
Messages
370
Points
103

Reputation:

Not sure though, but as ftp uses an host, username and port method to connect, and sometimes could take time depending on the servers port response time, so yeah i believe that's definitely going to be a bit slower compared to direct api method, however as its a CDN FTP, so they might have optimized it quite well to perform good, so the difference might not be that big.

But yeah FTP Authentication will be slower compared to API Authentication i believe.
 

zeus1971

Collaborate
Collaborate
Registered
Joined
Apr 18, 2020
Messages
310
Points
73

Reputation:

Well, others error trying FTP too.
I'm going to abandon this to try to cache (and save disk sapce) images with CDN.
Unfortunately, as says in others occasion there are no addons that give me security for production. (there is one, I know...but give errors , and overall when you try to go back, more errors).
So...hoping in the future to have others addons, and a easier way to get internal attachments cached.
 

zeus1971

Collaborate
Collaborate
Registered
Joined
Apr 18, 2020
Messages
310
Points
73

Reputation:

Ok, just an update, and if someone can help here...
FInally I could configure my XF 2.2. to work with external path (internal and expternal) , and everything is working fine !
The problem now is that I would like to use BunnyCDN ( I followed his guide) , but it's not caching, and nothing in the Bunny logs.

I paste my (new) config.php that is working with B2 (you need to install the addon S3 API, firstable) :

PHP:
$s3 = function()
{
   return new \Aws\S3\S3Client([
      'credentials' => [
         'key' => '1234',
         'secret' => 'abc'
      ],
      'region' => 'eu-central',
      'version' => 'latest',
      'endpoint' => 'https://s3.eu-central-003.backblazeb2.com'
   ]);
};

$config['fsAdapters']['data'] = function() use($s3)
{
   return new \League\Flysystem\AwsS3v3\AwsS3Adapter($s3(), 'bucketname', 'data');
};

$config['externalDataUrl'] = function($externalPath, $canonical)
{
   return 'https://bucketname.s3.eu-central-003.backblazeb2.com/data/' . $externalPath;
};

$config['fsAdapters']['internal-data'] = function() use($s3)
{
   return new \League\Flysystem\AwsS3v3\AwsS3Adapter($s3(), 'bucketname', 'internal_data');
};


#$config['externalDataUrl'] = 'https://cdn.mydomain.com/forum/data';
#$config['javaScriptUrl'] = 'https://cdn.mydomain.com/forum/js';

As you can see the finals lines are commented, becouse was my previuos configuration, before using external path pointing to B2.
 
Last edited:
Top