Skip to content

Commit

Permalink
* Fix for Bunny CDN region list
Browse files Browse the repository at this point in the history
  • Loading branch information
jawngee committed Mar 24, 2024
1 parent b2bb4ca commit 18c4cdd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 275 deletions.
12 changes: 6 additions & 6 deletions classes/Tools/Storage/Driver/BunnyCDN/BunnyCDNClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct($apiKey, $storageZone, $region, $pullZone) {

$this->apiKey = $apiKey;
$this->storageZone = $storageZone;
$this->region = $region;
$this->region = empty($region) ? '' : "{$region}.";
$this->pullZone = $pullZone;

$this->client = new Client();
Expand All @@ -33,7 +33,7 @@ public function __construct($apiKey, $storageZone, $region, $pullZone) {
public function upload($sourceFile, $destPath) {
$res = fopen($sourceFile, 'r');

$res = $this->client->put("https://{$this->region}.storage.bunnycdn.com/{$this->storageZone}/{$destPath}", [
$res = $this->client->put("https://{$this->region}storage.bunnycdn.com/{$this->storageZone}/{$destPath}", [
RequestOptions::HEADERS => [
'Content-Type' => 'application/octet-stream',
'AccessKey' => $this->apiKey
Expand All @@ -50,7 +50,7 @@ public function mkdir($path) {
return false;
}

$ftpId = ftp_connect("{$this->region}.storage.bunnycdn.com");
$ftpId = ftp_connect("{$this->region}storage.bunnycdn.com");
$login = ftp_login($ftpId, $this->storageZone, $this->apiKey);
if (!$login) {
throw new StorageException("Invalid settings");
Expand All @@ -64,7 +64,7 @@ public function mkdir($path) {
}

public function listFiles($path) {
$res = $this->client->get("https://{$this->region}.storage.bunnycdn.com/{$this->storageZone}/{$path}/", [
$res = $this->client->get("https://{$this->region}storage.bunnycdn.com/{$this->storageZone}/{$path}/", [
RequestOptions::HEADERS => [
'AccessKey' => $this->apiKey
],
Expand Down Expand Up @@ -95,7 +95,7 @@ public function listFiles($path) {

public function deleteFile($file) {

$res = $this->client->delete("https://{$this->region}.storage.bunnycdn.com/{$this->storageZone}/{$file}", [
$res = $this->client->delete("https://{$this->region}storage.bunnycdn.com/{$this->storageZone}/{$file}", [
RequestOptions::HEADERS => [
'AccessKey' => $this->apiKey
],
Expand All @@ -110,7 +110,7 @@ public function exists($file) {
return false;
}

$ftpId = ftp_connect("{$this->region}.storage.bunnycdn.com");
$ftpId = ftp_connect("{$this->region}storage.bunnycdn.com");
$login = ftp_login($ftpId, $this->storageZone, $this->apiKey);
if (!$login) {
throw new StorageException("Invalid settings");
Expand Down
145 changes: 9 additions & 136 deletions classes/Tools/Storage/Driver/BunnyCDN/BunnyCDNStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace MediaCloud\Plugin\Tools\Storage\Driver\BunnyCDN;

use MediaCloud\Plugin\Tools\Storage\FileInfo;
use MediaCloud\Plugin\Tools\Storage\InvalidStorageSettingsException;
use MediaCloud\Plugin\Tools\Storage\StorageException;
use MediaCloud\Plugin\Tools\Storage\StorageInterface;
use MediaCloud\Plugin\Tools\Storage\StorageToolSettings;
use MediaCloud\Plugin\Utilities\Environment;
Expand All @@ -14,7 +12,7 @@
use MediaCloud\Plugin\Wizard\ConfiguresWizard;
use MediaCloud\Plugin\Wizard\StorageWizardTrait;
use MediaCloud\Plugin\Wizard\WizardBuilder;
use MediaCloud\Vendor\FasterImage\FasterImage;
use function MediaCloud\Plugin\Utilities\anyEmpty;
use function MediaCloud\Plugin\Utilities\anyNull;
use function MediaCloud\Plugin\Utilities\arrayPath;

Expand Down Expand Up @@ -121,7 +119,7 @@ public function signedURLExpirationForType($type = null) {
* @inheritDoc
*/
public function enabled() {
if(!($this->settings->apiKey && $this->settings->region && $this->settings->pullZone && $this->settings->storageZone)) {
if(anyEmpty($this->settings->apiKey && $this->settings->pullZone && $this->settings->storageZone)) {
if (current_user_can('manage_options')) {
$adminUrl = admin_url('admin.php?page=media-cloud-settings&tab=storage');
NoticeManager::instance()->displayAdminNotice('error', "To start using Cloud Storage, you will need to <a href='$adminUrl'>supply your Bunny CDN credentials.</a>.", true, 'ilab-cloud-storage-setup-warning', 'forever');
Expand Down Expand Up @@ -417,136 +415,11 @@ public static function configureWizard($builder = null) {
->textField('mcloud-storage-bunnycdn-storage-zone', 'Storage Zone', '', null)
->textField('mcloud-storage-bunnycdn-pull-zone', 'Pull Zone URL', '', null)
->selectField('mcloud-storage-bunnycdn-region', 'Region', '', null, [
'jo' => 'AF: Amman, JO',
'eg2' => 'AF: Cairo 2, EG',
'eg' => 'AF: Cairo, EG',
'ct' => 'AF: Cape Town, SA',
'jh' => 'AF: Johannesburg, ZA',
'ng' => 'AF: Lagos, NG',
'ao' => 'AF: Luanda, AO',
'ke' => 'AF: Nairobi, KE',
'tn' => 'AF: Tunis, TN',
'pk' => 'ASIA: Karachi, PK',
'tw' => 'ASIA: Taipei, TW',
'kz' => 'Asia: Almaty, KZ',
'az' => 'Asia: Baku, AZ',
'in' => 'Asia: Bangalore, IN',
'th' => 'Asia: Bangkok, TH',
'kg' => 'Asia: Bishkek, KG',
'cen' => 'Asia: Chennai, IN',
'bd' => 'Asia: Dhaka, BD',
'vn' => 'Asia: Ho Chi Minh, VN',
'hk' => 'Asia: Hong Kong, HK',
'tr' => 'Asia: Istanbul, TR',
'id' => 'Asia: Jakarta, ID',
'np' => 'Asia: Kathmandu, NP',
'ccu' => 'Asia: Kolkata, IN',
'my' => 'Asia: Kuala Lumpur, MY',
'ph' => 'Asia: Manila, PH',
'mu' => 'Asia: Mumbai, IN',
'nd' => 'Asia: New Delhi, IN',
'cy' => 'Asia: Nicosia, CY',
'pp' => 'Asia: Phnom Penh, KH',
'kr' => 'Asia: Seoul, KR',
'sg2' => 'Asia: Singapore 2, SG',
'sg' => 'Asia: Singapore, SG',
'geo' => 'Asia: Tbilisi, GE',
'isr' => 'Asia: Tel Aviv, IL',
'jp' => 'Asia: Tokyo, JP',
'mg' => 'Asia: Ulaanbaatar, MN',
'rgn' => 'Asia: Yangon, MM',
'am' => 'Asia: Yerevan, AM',
'ams' => 'EU: Amsterdam, NL',
'gr' => 'EU: Athens, GR',
'rs' => 'EU: Belgrade, RS',
'sk' => 'EU: Bratislava, SK',
'bu' => 'EU: Bucharest, RO',
'hu' => 'EU: Budapest, HU',
'md' => 'EU: Chisinau, MD',
'dk' => 'EU: Copenhagen, DK',
'ie' => 'EU: Dublin, IE',
'dd' => 'EU: Dusseldorf, DE',
'de2' => 'EU: Frankfurt 2, DE2',
'de' => 'EU: Frankfurt, DE',
'fi' => 'EU: Helsinki, FI',
'is' => 'EU: Keflavik, IS',
'kh' => 'EU: Khabarovsk, RU',
'ky' => 'EU: Krasnoyarsk, RU',
'ua' => 'EU: Kyiv, UA',
'pt' => 'EU: Lisbon, PT',
'lj' => 'EU: Ljubljana, SI',
'uk' => 'EU: London, UK',
'lu' => 'EU: Luxembourg, LU',
'es' => 'EU: Madrid, ES',
'ms' => 'EU: Marseille, FR',
'it' => 'EU: Milan, IT',
'ru' => 'EU: Moscow, RU',
'ba' => 'EU: Novi Travnik, BA',
'no' => 'EU: Oslo, NO',
'fr' => 'EU: Paris, FR',
'cz' => 'EU: Prague, CZ',
'lv' => 'EU: Riga, LV',
'bg' => 'EU: Sofia, BG',
'se' => 'EU: Stockholm, SE',
'at' => 'EU: Vienna, AT',
'at2' => 'EU: Vienna, AT2',
'lt' => 'EU: Vilnius, LT',
'pl' => 'EU: Warsaw, PL',
'hr' => 'EU: Zagreb, HR',
'ch' => 'EU: Zurich, CH',
'bs' => 'LATAM: Brasilia, BR',
'fo' => 'LATAM: Fortaleza, BR',
'gt' => 'LATAM: Guatemala, GT',
'mx' => 'LATAM: Mexico City, MX',
'pa' => 'LATAM: Porto Alegre, BR',
'pr' => 'LATAM: San Juan, PR',
'cr' => 'LATAM: San Pedro, CR',
'bol' => 'LATAM: Sucre, BO',
'iq2' => 'ME: Baghdad 2, IQ',
'iq' => 'ME: Baghdad, IQ',
'bhr' => 'ME: Bahrain, BH',
'ae' => 'ME: Dubai, AE',
'fu' => 'ME: Fujairah, UAE',
'ri' => 'ME: Riyadh, SA',
'hi' => 'NA: Honolulu, HI',
'asb' => 'NA: Ashburn, VA',
'ga' => 'NA: Atlanta, GA',
'bo' => 'NA: Boston, MA',
'clt' => 'NA: Charlotte, NC',
'il' => 'NA: Chicago, IL',
'tx' => 'NA: Dallas, TX',
'den' => 'NA: Denver, CO',
'hou' => 'NA: Houston, TX',
'kc' => 'NA: Kansas City, MO',
'la' => 'NA: Los Angeles, CA',
'mi' => 'NA: Miami, FL',
'msp' => 'NA: Minneapolis, MN',
'mn' => 'NA: Montreal, CA',
'ny' => 'NA: New York City, NY',
'og' => 'NA: Ogden, UT',
'phx' => 'NA: Phoenix, AZ',
'pb' => 'NA: Pittsburgh, PA',
'sil' => 'NA: San Jose, CA',
'wa' => 'NA: Seattle, WA',
'ca' => 'NA: Toronto, CA',
'va' => 'NA: Vancouver, CA',
'adl' => 'OC: Adelaide, AU',
'auc' => 'OC: Auckland, NZ',
'brb' => 'OC: Brisbane, AU',
'gu' => 'OC: Hagatna: GU',
'mel' => 'OC: Melbourne, AU',
'per' => 'OC: Perth, AU',
'syd' => 'OC: Sydney, SYD',
'co' => 'SA: Bogota, SA',
'ar' => 'SA: Buenos Aires, AR',
'cwb' => 'SA: Curitiba, BR',
'lap' => 'SA: La Paz, BO',
'pe' => 'SA: Lima, PE',
'ec' => 'SA: Quito, EC',
'rj' => 'SA: Rio de Janeiro, BR',
'ssa' => 'SA: Salvador, BR',
'cl' => 'SA: Santiago, CL',
'br' => 'SA: Sao Paulo, BR',
'' => 'Falkenstein: storage.bunnycdn.com',
'ny' => 'New York: ny.storage.bunnycdn.com',
'la' => 'Los Angeles: la.storage.bunnycdn.com',
'sg' => 'Singapore: sg.storage.bunnycdn.com',
'syd' => 'Sydney: syd.storage.bunnycdn.com',
])
->endStep()
->testStep('wizard.cloud-storage.providers.bunnycdn.test', 'Test Settings', 'Perform tests to insure that your cloud storage provider is configured correctly.', false);
Expand Down Expand Up @@ -584,9 +457,9 @@ public static function processWizardSettings() {
$apiKey = arrayPath($_POST, $apiKeyName, null);
$storageZone = arrayPath($_POST, $storageZoneName, null);
$pullZone = arrayPath($_POST, $pullZoneName, null);
$region = arrayPath($_POST, $regionName, null);
$region = arrayPath($_POST, $regionName, '');

if (anyNull($provider, $apiKey, $storageZone, $pullZone, $region)) {
if (anyNull($provider, $apiKey, $storageZone, $pullZone)) {
wp_send_json(['status' => 'error', 'message' => 'Missing required fields'], 200);
}

Expand Down
135 changes: 5 additions & 130 deletions config/storage/bunnycdn.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,136 +41,11 @@
"display-order" => 11,
"type" => "select",
"options" => [
'jo' => 'AF: Amman, JO',
'eg2' => 'AF: Cairo 2, EG',
'eg' => 'AF: Cairo, EG',
'ct' => 'AF: Cape Town, SA',
'jh' => 'AF: Johannesburg, ZA',
'ng' => 'AF: Lagos, NG',
'ao' => 'AF: Luanda, AO',
'ke' => 'AF: Nairobi, KE',
'tn' => 'AF: Tunis, TN',
'pk' => 'ASIA: Karachi, PK',
'tw' => 'ASIA: Taipei, TW',
'kz' => 'Asia: Almaty, KZ',
'az' => 'Asia: Baku, AZ',
'in' => 'Asia: Bangalore, IN',
'th' => 'Asia: Bangkok, TH',
'kg' => 'Asia: Bishkek, KG',
'cen' => 'Asia: Chennai, IN',
'bd' => 'Asia: Dhaka, BD',
'vn' => 'Asia: Ho Chi Minh, VN',
'hk' => 'Asia: Hong Kong, HK',
'tr' => 'Asia: Istanbul, TR',
'id' => 'Asia: Jakarta, ID',
'np' => 'Asia: Kathmandu, NP',
'ccu' => 'Asia: Kolkata, IN',
'my' => 'Asia: Kuala Lumpur, MY',
'ph' => 'Asia: Manila, PH',
'mu' => 'Asia: Mumbai, IN',
'nd' => 'Asia: New Delhi, IN',
'cy' => 'Asia: Nicosia, CY',
'pp' => 'Asia: Phnom Penh, KH',
'kr' => 'Asia: Seoul, KR',
'sg2' => 'Asia: Singapore 2, SG',
'sg' => 'Asia: Singapore, SG',
'geo' => 'Asia: Tbilisi, GE',
'isr' => 'Asia: Tel Aviv, IL',
'jp' => 'Asia: Tokyo, JP',
'mg' => 'Asia: Ulaanbaatar, MN',
'rgn' => 'Asia: Yangon, MM',
'am' => 'Asia: Yerevan, AM',
'ams' => 'EU: Amsterdam, NL',
'gr' => 'EU: Athens, GR',
'rs' => 'EU: Belgrade, RS',
'sk' => 'EU: Bratislava, SK',
'bu' => 'EU: Bucharest, RO',
'hu' => 'EU: Budapest, HU',
'md' => 'EU: Chisinau, MD',
'dk' => 'EU: Copenhagen, DK',
'ie' => 'EU: Dublin, IE',
'dd' => 'EU: Dusseldorf, DE',
'de2' => 'EU: Frankfurt 2, DE2',
'de' => 'EU: Frankfurt, DE',
'fi' => 'EU: Helsinki, FI',
'is' => 'EU: Keflavik, IS',
'kh' => 'EU: Khabarovsk, RU',
'ky' => 'EU: Krasnoyarsk, RU',
'ua' => 'EU: Kyiv, UA',
'pt' => 'EU: Lisbon, PT',
'lj' => 'EU: Ljubljana, SI',
'uk' => 'EU: London, UK',
'lu' => 'EU: Luxembourg, LU',
'es' => 'EU: Madrid, ES',
'ms' => 'EU: Marseille, FR',
'it' => 'EU: Milan, IT',
'ru' => 'EU: Moscow, RU',
'ba' => 'EU: Novi Travnik, BA',
'no' => 'EU: Oslo, NO',
'fr' => 'EU: Paris, FR',
'cz' => 'EU: Prague, CZ',
'lv' => 'EU: Riga, LV',
'bg' => 'EU: Sofia, BG',
'se' => 'EU: Stockholm, SE',
'at' => 'EU: Vienna, AT',
'at2' => 'EU: Vienna, AT2',
'lt' => 'EU: Vilnius, LT',
'pl' => 'EU: Warsaw, PL',
'hr' => 'EU: Zagreb, HR',
'ch' => 'EU: Zurich, CH',
'bs' => 'LATAM: Brasilia, BR',
'fo' => 'LATAM: Fortaleza, BR',
'gt' => 'LATAM: Guatemala, GT',
'mx' => 'LATAM: Mexico City, MX',
'pa' => 'LATAM: Porto Alegre, BR',
'pr' => 'LATAM: San Juan, PR',
'cr' => 'LATAM: San Pedro, CR',
'bol' => 'LATAM: Sucre, BO',
'iq2' => 'ME: Baghdad 2, IQ',
'iq' => 'ME: Baghdad, IQ',
'bhr' => 'ME: Bahrain, BH',
'ae' => 'ME: Dubai, AE',
'fu' => 'ME: Fujairah, UAE',
'ri' => 'ME: Riyadh, SA',
'hi' => 'NA: Honolulu, HI',
'asb' => 'NA: Ashburn, VA',
'ga' => 'NA: Atlanta, GA',
'bo' => 'NA: Boston, MA',
'clt' => 'NA: Charlotte, NC',
'il' => 'NA: Chicago, IL',
'tx' => 'NA: Dallas, TX',
'den' => 'NA: Denver, CO',
'hou' => 'NA: Houston, TX',
'kc' => 'NA: Kansas City, MO',
'la' => 'NA: Los Angeles, CA',
'mi' => 'NA: Miami, FL',
'msp' => 'NA: Minneapolis, MN',
'mn' => 'NA: Montreal, CA',
'ny' => 'NA: New York City, NY',
'og' => 'NA: Ogden, UT',
'phx' => 'NA: Phoenix, AZ',
'pb' => 'NA: Pittsburgh, PA',
'sil' => 'NA: San Jose, CA',
'wa' => 'NA: Seattle, WA',
'ca' => 'NA: Toronto, CA',
'va' => 'NA: Vancouver, CA',
'adl' => 'OC: Adelaide, AU',
'auc' => 'OC: Auckland, NZ',
'brb' => 'OC: Brisbane, AU',
'gu' => 'OC: Hagatna: GU',
'mel' => 'OC: Melbourne, AU',
'per' => 'OC: Perth, AU',
'syd' => 'OC: Sydney, SYD',
'co' => 'SA: Bogota, SA',
'ar' => 'SA: Buenos Aires, AR',
'cwb' => 'SA: Curitiba, BR',
'lap' => 'SA: La Paz, BO',
'pe' => 'SA: Lima, PE',
'ec' => 'SA: Quito, EC',
'rj' => 'SA: Rio de Janeiro, BR',
'ssa' => 'SA: Salvador, BR',
'cl' => 'SA: Santiago, CL',
'br' => 'SA: Sao Paulo, BR',
'' => 'Falkenstein: storage.bunnycdn.com',
'ny' => 'New York: ny.storage.bunnycdn.com',
'la' => 'Los Angeles: la.storage.bunnycdn.com',
'sg' => 'Singapore: sg.storage.bunnycdn.com',
'syd' => 'Sydney: syd.storage.bunnycdn.com',
]
],
]
Expand Down
4 changes: 2 additions & 2 deletions ilab-media-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/interfacelab/ilab-media-tools
Description: Automatically upload media to Amazon S3 and integrate with Imgix, a real-time image processing CDN. Boosts site performance and simplifies workflows.
Author: interfacelab
Version: 4.6.1
Version: 4.6.2
Requires PHP: 7.4
Author URI: http://interfacelab.io
*/
Expand Down Expand Up @@ -117,7 +117,7 @@
define( 'WP_FS__ENABLE_GARBAGE_COLLECTOR', false );
}
// Version Defines
define( 'MEDIA_CLOUD_VERSION', '4.6.1' );
define( 'MEDIA_CLOUD_VERSION', '4.6.2' );
define( 'MEDIA_CLOUD_INFO_VERSION', '4.0.2' );
define( 'MCLOUD_IS_BETA', false );
// Debugging
Expand Down
Loading

0 comments on commit 18c4cdd

Please sign in to comment.