Skip to content

Commit a0af134

Browse files
Manu ChaudharyManu Chaudhary
authored andcommitted
Fix in signed url and readme.md
1 parent 3ffa4de commit a0af134

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The `.url()` method accepts the following parameters
9898
| transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. |
9999
| transformationPostion | Optional. Default value is `path` that places the transformation string as a path parameter in the URL. Can also be specified as `query` which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
100100
| queryParameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful, if you want to add some versioning parameter to your URLs. |
101-
| signed | Optional. Boolean. Default is `false`. If set to `true`, the SDK generates a signed image URL adding the image signature to the image URL. This can only be used if you are creating the URL with the `urlEndpoint` and `path` parameters, and not with the `src` parameter. |
101+
| signed | Optional. Boolean. Default is `false`. If set to `true`, the SDK generates a signed image URL adding the image signature to the image URL. If you are creating URL using `src` parameter instead of `path` then do correct `urlEndpoint` for this to work. Otherwise returned URL will have wrong signature |
102102
| expireSeconds | Optional. Integer. Meant to be used along with the `signed` parameter to specify the time in seconds from now when the URL should expire. If specified, the URL contains the expiry timestamp in the URL and the image signature is modified accordingly. |
103103

104104
#### Examples of generating URLs

libs/url/builder.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,20 @@ module.exports.buildURL = function(opts) {
7575
urlObject.pathname = urlFormatter.addLeadingSlash(urlObject.pathname);
7676
urlObject.search = queryParameters.toString();
7777

78-
// Signature String and Timestamp
79-
// We can do this only for URLs that are created using urlEndpoint and path parameter
80-
// because we need to know the endpoint to be able to remove it from the URL to create a signature
81-
// for the remaining. With the src parameter, we would not know the "pattern" in the URL
78+
/*
79+
Signature String and Timestamp
80+
If the url is constructed using src parameter instead of path then we still replace the urlEndpoint we have
81+
But the user is responsible for passing correct urlEndpoint value
82+
83+
Signature generation logic, let's assume:
84+
urlEndpoint value = https://ik.imagekit.io/your_imagekit_id
85+
expiryTimestamp 9999999999
86+
1. Let the final URL construct e.g. https://ik.imagekit.io/your_imagekit_id/tr:w-400:rotate-91/sample/testing-file.jpg?param1=123
87+
2. Now remove urlEndpoint from it i.e tr:w-400:rotate-91/sample/testing-file.jpg?param1=123
88+
3. Append expiryTimestamp to above string and calcualte signature of this string i.e "tr:w-400:rotate-91/sample/testing-file.jpg?param1=1239999999999"
89+
*/
8290
var expiryTimestamp;
83-
if(opts.signed === true && !isSrcParameterUsedForURL) {
91+
if(opts.signed === true) {
8492
if(opts.expireSeconds) {
8593
expiryTimestamp = getSignatureTimestamp(opts.expireSeconds);
8694
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit",
3-
"version": "3.0.3",
3+
"version": "3.0.4",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
55
"main": "index.js",
66
"scripts": {

sample/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ const sampleApp = async () => {
4444
});
4545
console.log("Url for first image transformed with height: 300, width: 400: ", imageURL, "\n");
4646

47+
var signedUrl = imagekit.url({
48+
path : filesList[0].filePath,
49+
signed : true,
50+
transformation : [{
51+
height: 300,
52+
width: 400
53+
}]
54+
});
55+
console.log("Signed Url for first image transformed with height: 300, width: 400: ", signedUrl, "\n");
56+
4757
// Get File Details
4858
const fileDetails_1 = await getFileDetails(imagekit, filesList[0].fileId);
4959
console.log("File Details fetched: ", JSON.stringify(fileDetails_1, undefined, 2), "\n");
@@ -58,6 +68,7 @@ const sampleApp = async () => {
5868
console.log("File Update Response: ", JSON.stringify(fileUpdateResponse, undefined, 2), "\n");
5969

6070
// pHash Distance
71+
console.log(fileMetadata_1.pHash, fileMetadata_2.pHash)
6172
const pHashDistance = imagekit.pHashDistance(fileMetadata_1.pHash, fileMetadata_2.pHash);
6273
console.log(`pHash distance: ${pHashDistance}`, "\n");
6374

0 commit comments

Comments
 (0)