Skip to content

Commit 9a0b182

Browse files
committed
changed url type from 'encoded' to 'encrypted', fixed build
1 parent f15eb58 commit 9a0b182

11 files changed

Lines changed: 40 additions & 32 deletions

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ It takes the following arguments:
5555
- `baseUrl` (`string`) - (required) the base URL of your imgproxy instance
5656
- `url` (`Object | string`) - (required) a string with url value or an object that contains the value and resultType properties. You can specify only url if you agree with default `url.resultType` = "base64" or you have to specify `url.value` and `url.resultType`.
5757
- `value` (`string`) - (required) the plain text URL of the image.
58-
- `resultType` (`"base64" | "encoded" | "plain"`) - (optional) the type of the URL. Deafult value is `"base64"`.
58+
- `resultType` (`"base64" | "encrypted" | "plain"`) - (optional) the type of the URL. Deafult value is `"base64"`.
5959
Can be one of the following:
6060
- `"base64"` - a base64 encoded URL. Default value.
61-
- `"encoded"` - (**PRO feature**) an AES-CBC encrypted URL.
62-
- `"plain"` - a plain text URL. We strongly recommend using `base64` or `encoded` type.
61+
- `"encrypted"` - (**PRO feature**) an AES-CBC encrypted URL.
62+
- `"plain"` - a plain text URL. We strongly recommend using `base64` or `encrypted` type.
6363
- `options` (`Object | undefined`) - (optional) an object that contains the resizing options. You can see all options in [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=processing-options) or in [Options types in imgproxy-js-core library](https://github.com/imgproxy/imgproxy-js-core/blob/main/src/types/index.ts).
6464
- `salt` (`string | undefined`) - (optional) the salt used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_SALT environment variable from process.env for this call.
6565
- `key` (`string | undefined`) - (optional) the key used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_KEY environment variable from process.env for this call.
@@ -74,11 +74,11 @@ It takes the following arguments:
7474
- `baseUrl` (`string`) - (required) the base URL of your imgproxy instance
7575
- `url` (`Object | string`) - (required) a string with url value or an object that contains the value and resultType properties. You can specify only url if you agree with default `url.resultType` = "base64" or you will have to specify `url.value` and `url.resultType`.
7676
- `value` (`string`) - (required) the plain text URL of the image.
77-
- `resultType` (`"base64" | "encoded" | "plain"`) - (optional) the type of the URL. Deafult value is `"base64"`.
77+
- `resultType` (`"base64" | "encrypted" | "plain"`) - (optional) the type of the URL. Deafult value is `"base64"`.
7878
Can be one of the following:
7979
- `"base64"` - a base64 encoded URL. Default value.
80-
- `"encoded"` - (**PRO feature**) an AES-CBC encrypted URL.
81-
- `"plain"` - a plain text URL. We strongly recommend using `base64` or `encoded` type.
80+
- `"encrypted"` - (**PRO feature**) an AES-CBC encrypted URL.
81+
- `"plain"` - a plain text URL. We strongly recommend using `base64` or `encrypted` type.
8282
- `options` (`Object | undefined`) - (optional) an object that contains the resizing options. You can see all options in [imgproxy docs](https://docs.imgproxy.net/getting_the_image_info?id=info-options) or in [OptionsImageInfo types in imgproxy-js-core library](https://github.com/imgproxy/imgproxy-js-core/blob/main/src/types/index.ts).
8383
- `salt` (`string | undefined`) - (optional) the salt used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_SALT from process.env for one request.
8484
- `key` (`string | undefined`) - (optional) the key used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_KEY from process.env for one request.

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
"vitest": "^0.34.1"
4242
},
4343
"dependencies": {
44-
"@imgproxy/imgproxy-js-core": "^1.0.3"
44+
"@imgproxy/imgproxy-js-core": "^1.0.5"
4545
}
4646
}

src/methods/generateImageInfoUrl.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("generateImageInfourl", () => {
1616
baseUrl: "https://imgproxy.example.com/",
1717
url: {
1818
value: "https://example.com/image.jpg",
19-
resultType: "encoded",
19+
resultType: "encrypted",
2020
},
2121
options,
2222
salt: "520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5",

src/methods/generateImageInfoUrl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import type { IGenerateImageInfoUrl } from "../types";
99
/**
1010
* Generate image info url. **PRO feature**
1111
* @param {string} baseUrl - Base url
12-
* @param {Object} url - url and type
12+
* @param {Object | string} url - you can specify only url if you agree with default url.resultType = "base64" or you have to specify url.value and url.resultType
1313
* @param {string} url.value - url value
14-
* @param {string} url.type - url type (plain, base64 or encoded)
14+
* @param {string} url.resultType - (optional) here you specify in what type of image URL is required in the generated.
15+
* Imgproxy request URL: "plain", "base64" or "encrypted" (encrypted is PRO feature). We strongly recommend to use "base64" or "encrypted" kind of url. default: `"base64"`.
1516
* @param {Object} [options] - (optional) options. You can see all options in [imgproxy docs](https://docs.imgproxy.net/getting_the_image_info?id=info-options)
1617
* or in OptionsImageInfo types in imgproxy-js-core.d.ts
1718
* @param {string} [salt] - (optional) hex-encoded salt. This option overrides IMGPROXY_SALT from process.env for this request
@@ -26,7 +27,7 @@ import type { IGenerateImageInfoUrl } from "../types";
2627
* @example
2728
* const url = generateImageInfoUrl({
2829
* baseUrl: "https://imgproxy.example",
29-
* url: { value: "hLhDnxN9acjq3LDooARQ3t6OU1UwAG1IeXsM2b7qxOyMP4DF+GsbBdnG1K9B0+bz", type: "encoded"},
30+
* url: "https://example.com/image.jpg",
3031
* options: {
3132
* average: { average: 1, ignore_transparent: "f" },
3233
* detect_objects: true,

src/methods/generateImageUrl.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe("generateImageUrl", () => {
6161
);
6262
});
6363

64-
it("should generate a valid encoded URL with encryption", () => {
64+
it("should generate a valid encrypted URL with encryption", () => {
6565
const options: Options = {
6666
resizing_type: "fit",
6767
width: 300,
@@ -71,7 +71,7 @@ describe("generateImageUrl", () => {
7171

7272
const result = generateImageUrl({
7373
baseUrl: "https://imgproxy.example.com/",
74-
url: { value: "https://example.com/image.jpg", resultType: "encoded" },
74+
url: { value: "https://example.com/image.jpg", resultType: "encrypted" },
7575
options,
7676
salt: "520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5",
7777
key: "943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881",

src/methods/generateImageUrl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import type { IGenerateImageUrl } from "../types";
66
/**
77
* Generate image url
88
* @param {string} baseUrl - Base url
9-
* @param {Object | string} url - you should specify only url if you agree with default url.resultType = "base64" or you should specify url.value and url.resultType
9+
* @param {Object | string} url - you can specify only url if you agree with default url.resultType = "base64" or you have to specify url.value and url.resultType
1010
* @param {string} url.value - url value
11-
* @param {string} url.resultType - (optional) here you specify in what type of image URL is required in the generated
12-
* Imgproxy request URL: "plain", "base64" or "encoded" (encoded is PRO feature). We strongly recommend to use "base64" or "encoded" kind of url. default: "base64"
11+
* @param {string} url.resultType - (optional) here you specify in what type of image URL is required in the generated.
12+
* Imgproxy request URL: "plain", "base64" or "encrypted" (encrypted is PRO feature). We strongly recommend to use "base64" or "encrypted" kind of url. default: `"base64"`
1313
* @param {Object} [options] - (optional) options. You can see all options in [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=processing-options)
1414
* or in Options types in imgproxy-js-core.d.ts
1515
* @param {string} [salt] - (optional) hex-encoded salt. This option overrides IMGPROXY_SALT from process.env for this request

src/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { Options, OptionsImageInfo } from "@imgproxy/imgproxy-js-core";
1+
import type {
2+
Options,
3+
OptionsImageInfo,
4+
URL,
5+
} from "@imgproxy/imgproxy-js-core";
26

37
export interface IMaybePair {
48
salt: string | undefined;
@@ -12,7 +16,7 @@ export interface IPair {
1216

1317
export interface IRawUrl {
1418
value: string;
15-
resultType?: "plain" | "base64" | "encoded";
19+
resultType?: URL["type"];
1620
}
1721

1822
interface BaseGenerateImageUrl {

src/utils/getSignedUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createHmac } from "crypto";
1+
import crypto from "crypto";
22
import type { IPair } from "../types";
33
import withCache from "./withCache";
44

55
const hexDecode = (hex: string): Buffer => Buffer.from(hex, "hex");
66

77
const sign = (target: string, signPair: IPair): string => {
8-
const hmac = createHmac("sha256", hexDecode(signPair.key));
8+
const hmac = crypto.createHmac("sha256", hexDecode(signPair.key));
99
hmac.update(hexDecode(signPair.salt));
1010
hmac.update(target);
1111

src/utils/normalizeUrl.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@ import { describe, expect, it } from "vitest";
22
import normalizeUrl from "./normalizeUrl";
33

44
describe("normalizeUrl", () => {
5-
it("should return a throw error if resultType is 'encoded' and encryptKey is not provided", () => {
5+
it("should return a throw error if resultType is 'encrypted' and encryptKey is not provided", () => {
66
expect(() =>
77
normalizeUrl({
8-
url: { value: "https://example.com/image.jpg", resultType: "encoded" },
8+
url: {
9+
value: "https://example.com/image.jpg",
10+
resultType: "encrypted",
11+
},
912
})
1013
).toThrowError(
11-
"You should provide encryptKey if you want to use encoded url type"
14+
"You should provide encryptKey if you want to use encrypted url type"
1215
);
1316
});
1417

1518
it("should return a changed url type if encryptKey is provided", () => {
1619
const result = normalizeUrl({
17-
url: { value: "https://example.com/image.jpg", resultType: "encoded" },
20+
url: { value: "https://example.com/image.jpg", resultType: "encrypted" },
1821
encryptKey:
1922
"52dd01d54fcbd79ff247fcff1d2f200ce6b95546f960b084faa1d269fb95d600",
2023
});
2124

22-
expect(result.type).toBe("encoded");
25+
expect(result.type).toBe("encrypted");
2326
});
2427

2528
it("should return a url type without changes if encryptKey and noEcroption are provided", () => {

0 commit comments

Comments
 (0)