Skip to content

Commit

Permalink
Improved Signed URL and Added Cache to Sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnv committed Sep 28, 2021
1 parent 0a055b4 commit e63701a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
15 changes: 15 additions & 0 deletions sample/sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,21 @@
$bulkJob = $imageKit->getBulkJobStatus($moveFolder->success->jobId);
echo('Move Folder Job Status : ' . print_r($bulkJob, true));


// Purge Cache
echo "\n\n-------------------------------------------------------------------\n\n";

$purgeCache = $imageKit->purgeCache($randomFile->url);
echo('Purge Cache : ' . print_r($purgeCache, true));

// Purge Cache Status
echo "\n\n-------------------------------------------------------------------\n\n";

$purgeCacheStatus = $imageKit->getPurgeCacheStatus($purgeCache->success->requestId);
echo('Purge Cache Status : ' . print_r($purgeCacheStatus, true));



// Auth params
echo "\n\n-------------------------------------------------------------------\n\n";

Expand Down
4 changes: 4 additions & 0 deletions src/ImageKit/Url/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function buildURL($urlOptions)

if (isset($obj->expireSeconds)) {
$expireSeconds = $obj->expireSeconds;

if ($signed === true && $expireSeconds !== '' && !is_numeric($expireSeconds)) {
throw new \InvalidArgumentException('expireSeconds should be numeric');
}
}

if (isset($obj->path)) {
Expand Down
32 changes: 5 additions & 27 deletions tests/ImageKit/Url/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testUrlSignedUrl()
'signed' => true
]);
UrlTest::assertEquals(
'https://ik.imagekit.io/demo/default-image.jpg?ik-s=f2e41285adccc8b8601eb6d0974c65af0f4f6247&ik-sdk-version=php-' . ImageKit::SDK_VERSION,
'https://ik.imagekit.io/demo/default-image.jpg?ik-s=16f944062d8d1ab884bac6cce37b77c6b0aff8ee&ik-sdk-version=php-' . ImageKit::SDK_VERSION,
$url
);
}
Expand All @@ -116,7 +116,7 @@ public function testUrlSignedUrlWithEmptyExpiryString()
'expireSeconds' => ''
]);
UrlTest::assertEquals(
'https://ik.imagekit.io/demo/default-image.jpg?ik-s=f2e41285adccc8b8601eb6d0974c65af0f4f6247&ik-sdk-version=php-' . ImageKit::SDK_VERSION,
'https://ik.imagekit.io/demo/default-image.jpg?ik-s=16f944062d8d1ab884bac6cce37b77c6b0aff8ee&ik-sdk-version=php-' . ImageKit::SDK_VERSION,
$url
);
}
Expand All @@ -126,15 +126,13 @@ public function testUrlSignedUrlWithEmptyExpiryString()
*/
public function testUrlSignedUrlWithInvalidExpiryString()
{
$url = $this->client->url([
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('expireSeconds should be numeric');
$this->client->url([
'path' => '/default-image.jpg',
'signed' => true,
'expireSeconds' => 'asdad'
]);
UrlTest::assertEquals(
'https://ik.imagekit.io/demo/default-image.jpg?ik-s=f2e41285adccc8b8601eb6d0974c65af0f4f6247&ik-sdk-version=php-' . ImageKit::SDK_VERSION,
$url
);
}

/**
Expand Down Expand Up @@ -1073,24 +1071,4 @@ public function testUnitTestGeneratedSignature()
UrlTest::assertEquals('41b3075c40bc84147eb71b8b49ae7fbf349d0f00', $signature);
}


/**
*
*/
public function testUnitTestGeneratedSignatureEmptyPrivateKey()
{
$opts = [
'privateKey' => '',
'url' => 'https://test-domain.com/test-endpoint/tr:w-100/test-signed-url.png',
'urlEndpoint' => 'https://test-domain.com/test-endpoint',
'expiryTimestamp' => '9999999999'
];

$urlInstance = new Url();
$signature = $urlInstance->getSignature($opts);

UrlTest::assertEquals('', $signature);
}


}

0 comments on commit e63701a

Please sign in to comment.