Skip to content

Commit 36de2b8

Browse files
committed
WIP
1 parent 16b3d77 commit 36de2b8

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.php_cs.cache
44
.php-cs-fixer.cache
55
.phpunit.result.cache
6+
.phpunit.cache
67
build
78
composer.lock
89
coverage

src/FlysystemCloudinaryAdapter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,17 @@ public function getUrl(string $path): string|false
524524
{
525525
$path = $this->ensureFolderIsPrefixed(trim($path, '/'));
526526

527+
try {
528+
return (string) $this->cloudinary->image($path)->toUrl();
529+
} catch (NotFound) {
530+
return false;
531+
}
532+
}
533+
534+
public function getUrlViaRequest(string $path): string|false
535+
{
536+
$path = $this->ensureFolderIsPrefixed(trim($path, '/'));
537+
527538
try {
528539
$response = $this->explicit($path);
529540
} catch (NotFound) {

tests/Feature/AdapterTest.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
Event::assertDispatched(FlysystemCloudinaryResponseLog::class, 4);
270270
});
271271

272-
it('can get url', function () {
272+
it('can get url via request', function () {
273273
Http::fake();
274274
$mock = $this->mock(Cloudinary::class, function (MockInterface $mock) {
275275
$mock->shouldReceive('uploadApi->explicit')->once()->andReturn(new ApiResponse([
@@ -279,8 +279,47 @@
279279
});
280280
$adapter = new FlysystemCloudinaryAdapter($mock);
281281

282-
$url = $adapter->getUrl('::path::');
282+
$url = $adapter->getUrlViaRequest('::path::');
283283

284284
$this->assertSame('::secure-url::', $url);
285285
Event::assertDispatched(FlysystemCloudinaryResponseLog::class, 2);
286286
});
287+
288+
it('can get url', function () {
289+
// Secure URL
290+
291+
$cloudinary = new Cloudinary([
292+
'cloud_name' => env('CLOUDINARY_CLOUD_NAME'),
293+
'api_key' => env('CLOUDINARY_API_KEY'),
294+
'api_secret' => env('CLOUDINARY_API_SECRET'),
295+
'url' => [
296+
'secure' => true,
297+
],
298+
]);
299+
300+
$adapter = new FlysystemCloudinaryAdapter($cloudinary);
301+
302+
$url = $adapter->getUrl('::path::');
303+
304+
expect($url)
305+
->toContain('https://', '::path::')
306+
->not->toContain('http://');
307+
308+
// Unsecure URL
309+
310+
$cloudinary = new Cloudinary([
311+
'cloud_name' => env('CLOUDINARY_CLOUD_NAME'),
312+
'api_key' => env('CLOUDINARY_API_KEY'),
313+
'api_secret' => env('CLOUDINARY_API_SECRET'),
314+
'url' => [
315+
'secure' => false,
316+
],
317+
]);
318+
319+
$adapter = new FlysystemCloudinaryAdapter($cloudinary);
320+
321+
$url = $adapter->getUrl('::path::');
322+
323+
expect($url)->toContain('http://', '::path::')
324+
->not->toContain('https://');
325+
});

0 commit comments

Comments
 (0)