Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Support new "cname" option to deliver resource with privatecdn #37

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions Classes/Services/ConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
*/


/**
* Class ConfigurationService
*/
class ConfigurationService
{
/**
* @var array
*/
protected $configuration = [];
protected array $configuration = [];

/**
* ConfigurationService constructor.
Expand All @@ -33,8 +27,8 @@ public function __construct(array $configuration)
*/
public function get(string $key): string
{
$value = (string)$this->configuration[$key];
if (preg_match('/^%(.*)%$/', $value, $matches)) {
$value = trim((string)$this->configuration[$key]);
if (preg_match('/^%env\((.*)\)%$/', $value, $matches) || preg_match('/^%(.*)%$/', $value, $matches)) {
$value = getenv($matches[1]);

if ($value === false) {
Expand Down
4 changes: 3 additions & 1 deletion Classes/Utility/CloudinaryApiUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public static function initializeByConfiguration(array $configuration)
'api_key' => $configurationService->get('apiKey'),
'api_secret' => $configurationService->get('apiSecret'),
'timeout' => $configurationService->get('timeout'),
'secure' => true
'secure' => true,
'private_cdn' => $configurationService->get('cname') !== '',
jrenggli marked this conversation as resolved.
Show resolved Hide resolved
'secure_distribution' => $configurationService->get('cname'),
]
);
}
Expand Down
8 changes: 8 additions & 0 deletions Configuration/FlexForm/CloudinaryFlexForm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
</config>
</TCEforms>
</basePath>
<cname>
<TCEforms>
<label>LLL:EXT:cloudinary/Resources/Private/Language/backend.xlf:driverConfiguration.cname</label>
<config>
<type>input</type>
</config>
</TCEforms>
</cname>
<timeout>
<TCEforms>
<label>LLL:EXT:cloudinary/Resources/Private/Language/backend.xlf:driverConfiguration.timeout</label>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Notice the first time you click on a folder in the File list module,
it will take some time since the images must be fetched and put into the cloudinary cache.

Notice you can also use environment variable to configure the storage.
The environment variable should be surrounded by %. Example `%BUCKET_NAME%`
The environment variable should be surrounded by %. Example `%env(BUCKET_NAME%)`

![](Documentation/driver-configuration-01.png)

Expand Down
7 changes: 5 additions & 2 deletions Resources/Private/Language/backend.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
<source>Cloudinary API Secret</source>
</trans-unit>
<trans-unit id="driverConfiguration.basePath">
<source>A possible base path to store files in a parent directory. Example `production/`</source>
<source>A possible base path for storing files in a parent directory on cloudinary. Example `production/`</source>
</trans-unit>
<trans-unit id="driverConfiguration.cname">
<source>A possible CNAME to serve your assets from, instead of the default res.cloudinary.com domain name.</source>
</trans-unit>
<trans-unit id="driverConfiguration.authenticationEmail">
<source>Email used for authentication (auto-login) in file reference fields in TCEForm.</source>
<source>Email address used for authentication (auto-login) in file reference fields within TCEForm.</source>
</trans-unit>
<trans-unit id="driverConfiguration.timeout">
<source>Cloudinary API timeout</source>
Expand Down
Loading