Skip to content

Commit e9a0495

Browse files
authored
Merge pull request #3 from techulus/feat/update-url
Update URL, Edge support
2 parents c1e170a + e0aa518 commit e9a0495

File tree

4 files changed

+55
-23
lines changed

4 files changed

+55
-23
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Capture Node SDK
2-
Node Library for Capture by Techulus
32

4-
Get your API Key and Secret from https://capture.techulus.in/console
3+
Node Library for [capture.page](https://capture.page)
4+
5+
Get your API Key and Secret from [https://capture.page/console](https://capture.page/console)
6+
7+
List of all capture options: [https://docs.capture.page](https://docs.capture.page)
58

69
## Installation
710

@@ -11,25 +14,27 @@ npm install capture-node
1114

1215
## Usage
1316

14-
List of all capture options: https://docs.capture.techulus.in
17+
List of all capture options: https://docs.capture.page
1518

1619
### Image
1720

1821
```javascript
1922
import { Capture } from 'capture-node';
2023
const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET);
24+
// or initialize with edge endpoint
25+
// const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET, { useEdge: true });
2126

2227
// var url = capture.buildImageUrl(URL_TO_CAPTURE, CAPTURE_OPTIONS);
2328

24-
const url = capture.buildImageUrl('https://capture.techulus.in/', {
29+
const url = capture.buildImageUrl('https://capture.page/', {
2530
full: true,
2631
delay: 3,
2732
t: Date.now()
2833
});
2934

3035
// or
3136

32-
const image = await capture.fetchImage('https://capture.techulus.in/', {
37+
const image = await capture.fetchImage('https://capture.page/', {
3338
full: true,
3439
delay: 3,
3540
t: Date.now()
@@ -45,15 +50,15 @@ const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET);
4550

4651
// var url = capture.buildPdfUrl(URL_TO_CAPTURE, CAPTURE_OPTIONS);
4752

48-
const url = capture.buildPdfUrl('https://capture.techulus.in/', {
53+
const url = capture.buildPdfUrl('https://capture.page/', {
4954
full: true,
5055
delay: 3,
5156
t: Date.now()
5257
});
5358

5459
// or
5560

56-
const pdf = capture.fetchPdf('https://capture.techulus.in/', {
61+
const pdf = capture.fetchPdf('https://capture.page/', {
5762
full: true,
5863
delay: 3,
5964
t: Date.now()
@@ -68,11 +73,11 @@ const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET);
6873

6974
// var url = capture.buildContentUrl(URL_TO_CAPTURE, CAPTURE_OPTIONS);
7075

71-
const url = capture.buildContentUrl('https://capture.techulus.in/');
76+
const url = capture.buildContentUrl('https://capture.page/');
7277

7378
// or
7479

75-
const content = await capture.fetchContent('https://capture.techulus.in/');
80+
const content = await capture.fetchContent('https://capture.page/');
7681
```
7782

7883
### Metadata
@@ -83,9 +88,9 @@ const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET);
8388

8489
// var url = capture.buildMetadataUrl(URL_TO_CAPTURE, CAPTURE_OPTIONS);
8590

86-
const url = capture.buildMetadataUrl('https://capture.techulus.in/');
91+
const url = capture.buildMetadataUrl('https://capture.page/');
8792

8893
// or
8994

90-
const content = await capture.fetchMetadata('https://capture.techulus.in/');
95+
const content = await capture.fetchMetadata('https://capture.page/');
9196
```

__tests__/test.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ describe("Capture URL Builder", () => {
1313
const url = capture.buildImageUrl("https://news.ycombinator.com/");
1414
console.log(url);
1515
expect(url).toBe(
16-
"https://cdn.capture.techulus.in/test/f37d5fb3ee4540a05bf4ffeed6dffa28/image?url=https%3A%2F%2Fnews.ycombinator.com%2F",
16+
"https://cdn.capture.page/test/f37d5fb3ee4540a05bf4ffeed6dffa28/image?url=https%3A%2F%2Fnews.ycombinator.com%2F",
1717
);
1818
});
1919

2020
it("buildImageUrl with options should return valid url", () => {
21-
const url = capture.buildImageUrl("https://capture.techulus.in/", {
21+
const url = capture.buildImageUrl("https://capture.page/", {
2222
full: true,
2323
delay: 3,
2424
});
2525
expect(url).toBe(
26-
"https://cdn.capture.techulus.in/test/2cb8b7ed9dbdb5c0db4a5dc4523a0780/image?full=true&delay=3&url=https%3A%2F%2Fcapture.techulus.in%2F",
26+
"https://cdn.capture.page/test/0e944abb6d823d0c8618dc22e508be6d/image?full=true&delay=3&url=https%3A%2F%2Fcapture.page%2F",
2727
);
2828
});
2929
});
@@ -37,17 +37,17 @@ describe("Capture URL Builder", () => {
3737
it("buildPdfUrl should return valid url", () => {
3838
const url = capture.buildPdfUrl("https://news.ycombinator.com/");
3939
expect(url).toBe(
40-
"https://cdn.capture.techulus.in/test/f37d5fb3ee4540a05bf4ffeed6dffa28/pdf?url=https%3A%2F%2Fnews.ycombinator.com%2F",
40+
"https://cdn.capture.page/test/f37d5fb3ee4540a05bf4ffeed6dffa28/pdf?url=https%3A%2F%2Fnews.ycombinator.com%2F",
4141
);
4242
});
4343

4444
it("buildPdfUrl with options should return valid url", () => {
45-
const url = capture.buildPdfUrl("https://capture.techulus.in/", {
45+
const url = capture.buildPdfUrl("https://capture.page/", {
4646
full: true,
4747
delay: 3,
4848
});
4949
expect(url).toBe(
50-
"https://cdn.capture.techulus.in/test/2cb8b7ed9dbdb5c0db4a5dc4523a0780/pdf?full=true&delay=3&url=https%3A%2F%2Fcapture.techulus.in%2F",
50+
"https://cdn.capture.page/test/0e944abb6d823d0c8618dc22e508be6d/pdf?full=true&delay=3&url=https%3A%2F%2Fcapture.page%2F",
5151
);
5252
});
5353
});
@@ -61,7 +61,7 @@ describe("Capture URL Builder", () => {
6161
it("buildContentUrl should return valid url", () => {
6262
const url = capture.buildContentUrl("https://news.ycombinator.com/");
6363
expect(url).toBe(
64-
"https://cdn.capture.techulus.in/test/f37d5fb3ee4540a05bf4ffeed6dffa28/content?url=https%3A%2F%2Fnews.ycombinator.com%2F",
64+
"https://cdn.capture.page/test/f37d5fb3ee4540a05bf4ffeed6dffa28/content?url=https%3A%2F%2Fnews.ycombinator.com%2F",
6565
);
6666
});
6767
});
@@ -75,8 +75,32 @@ describe("Capture URL Builder", () => {
7575
it("buildMetadataUrl should return valid url", () => {
7676
const url = capture.buildMetadataUrl("https://news.ycombinator.com/");
7777
expect(url).toBe(
78-
"https://cdn.capture.techulus.in/test/f37d5fb3ee4540a05bf4ffeed6dffa28/metadata?url=https%3A%2F%2Fnews.ycombinator.com%2F",
78+
"https://cdn.capture.page/test/f37d5fb3ee4540a05bf4ffeed6dffa28/metadata?url=https%3A%2F%2Fnews.ycombinator.com%2F",
7979
);
8080
});
8181
});
8282
});
83+
84+
describe("Capture URL Builder with useEdge", () => {
85+
const edgeCapture = new Capture("test", "test", { useEdge: true });
86+
87+
it("buildImageUrl should use edge URL", () => {
88+
const url = edgeCapture.buildImageUrl("https://news.ycombinator.com/");
89+
expect(url.startsWith("https://edge.capture.page/")).toBe(true);
90+
});
91+
92+
it("buildPdfUrl should use edge URL", () => {
93+
const url = edgeCapture.buildPdfUrl("https://news.ycombinator.com/");
94+
expect(url.startsWith("https://edge.capture.page/")).toBe(true);
95+
});
96+
97+
it("buildContentUrl should use edge URL", () => {
98+
const url = edgeCapture.buildContentUrl("https://news.ycombinator.com/");
99+
expect(url.startsWith("https://edge.capture.page/")).toBe(true);
100+
});
101+
102+
it("buildMetadataUrl should use edge URL", () => {
103+
const url = edgeCapture.buildMetadataUrl("https://news.ycombinator.com/");
104+
expect(url.startsWith("https://edge.capture.page/")).toBe(true);
105+
});
106+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "capture-node",
33
"version": "2.1.0",
4-
"description": "Node Library for Capture by Techulus",
4+
"description": "Node Library for capture.page",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ export type RequestType = "image" | "pdf" | "content" | "metadata";
55
export type RequestOptions = Record<string, string | number | boolean>;
66

77
export class Capture {
8-
static API_URL = "https://cdn.capture.techulus.in";
8+
static API_URL = "https://cdn.capture.page";
9+
static EDGE_URL = "https://edge.capture.page";
910

1011
key: string;
1112
secret: string;
13+
options: { useEdge?: boolean };
1214

13-
constructor(key: string, secret: string) {
15+
constructor(key: string, secret: string, options?: { useEdge?: boolean }) {
1416
this.key = key;
1517
this.secret = secret;
18+
this.options = options ?? { useEdge: false };
1619
}
1720

1821
private _generateToken(secret: string, url: string) {
@@ -74,7 +77,7 @@ export class Capture {
7477
query = this._toQueryString(options);
7578
}
7679
const token = this._generateToken(this.secret, query);
77-
return `${Capture.API_URL}/${this.key}/${token}/${type}?${query}`;
80+
return `${this.options.useEdge ? Capture.EDGE_URL : Capture.API_URL}/${this.key}/${token}/${type}?${query}`;
7881
}
7982

8083
buildImageUrl(url: string, options?: RequestOptions) {

0 commit comments

Comments
 (0)