@spider-cloud/spider-client 0.0.34 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/client.d.ts +6 -4
- package/dist/client.js +12 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,13 +93,13 @@ spider
|
|
|
93
93
|
|
|
94
94
|
#### Download storage data
|
|
95
95
|
|
|
96
|
-
To download stored data like raw HTML or markdown use the `
|
|
96
|
+
To download stored data like raw HTML or markdown use the `createSignedUrl` method. Provide the website name and an object containing query parameters:
|
|
97
97
|
|
|
98
98
|
```javascript
|
|
99
99
|
const websiteName = "spider.cloud";
|
|
100
100
|
const queryParams = { limit: 20, page: 0 };
|
|
101
101
|
spider
|
|
102
|
-
.
|
|
102
|
+
.createSignedUrl(websiteName, queryParams)
|
|
103
103
|
.then((response) => console.log(response))
|
|
104
104
|
.catch((error) => console.error(error));
|
|
105
105
|
```
|
|
@@ -118,7 +118,7 @@ spider
|
|
|
118
118
|
- **`getCredits()`**: Retrieve account's remaining credits.
|
|
119
119
|
- **`getData(table, params)`**: Retrieve data records from the DB.
|
|
120
120
|
- **`deleteData(table, params)`**: Delete records from the DB.
|
|
121
|
-
- **`
|
|
121
|
+
- **`createSignedUrl(domain, params)`**: Download the records from the DB.
|
|
122
122
|
|
|
123
123
|
## Error Handling
|
|
124
124
|
|
package/dist/client.d.ts
CHANGED
|
@@ -108,16 +108,18 @@ export declare class Spider {
|
|
|
108
108
|
*/
|
|
109
109
|
getCrawlState(url: string, params?: GenericParams): Promise<any>;
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
111
|
+
* Create a signed url to download files from the storage.
|
|
112
112
|
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
113
|
-
* @param {Object} [options] - The download options
|
|
113
|
+
* @param {Object} [options] - The download options.
|
|
114
|
+
* @param {boolean} [raw] - Return the raw response.
|
|
115
|
+
|
|
114
116
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
115
117
|
*/
|
|
116
|
-
|
|
118
|
+
createSignedUrl(domain?: string, options?: {
|
|
117
119
|
page?: number;
|
|
118
120
|
limit?: number;
|
|
119
121
|
expiresIn?: number;
|
|
120
|
-
}): Promise<Response>;
|
|
122
|
+
}, raw?: boolean): Promise<Response>;
|
|
121
123
|
/**
|
|
122
124
|
* Retrieves the number of credits available on the account.
|
|
123
125
|
* @returns {Promise<any>} The current credit balance.
|
package/dist/client.js
CHANGED
|
@@ -161,12 +161,14 @@ class Spider {
|
|
|
161
161
|
return this._apiPost("data/crawl_state", { url: url, ...params });
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
164
|
+
* Create a signed url to download files from the storage.
|
|
165
165
|
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
166
|
-
* @param {Object} [options] - The download options
|
|
166
|
+
* @param {Object} [options] - The download options.
|
|
167
|
+
* @param {boolean} [raw] - Return the raw response.
|
|
168
|
+
|
|
167
169
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
168
170
|
*/
|
|
169
|
-
async
|
|
171
|
+
async createSignedUrl(domain, options, raw) {
|
|
170
172
|
const { page, limit, expiresIn } = options !== null && options !== void 0 ? options : {};
|
|
171
173
|
const params = new URLSearchParams({
|
|
172
174
|
...(domain && { domain }),
|
|
@@ -180,8 +182,13 @@ class Spider {
|
|
|
180
182
|
method: "GET",
|
|
181
183
|
headers,
|
|
182
184
|
});
|
|
183
|
-
if (!
|
|
184
|
-
|
|
185
|
+
if (!raw) {
|
|
186
|
+
if (response.ok) {
|
|
187
|
+
return response.json();
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
this.handleError(response, `Failed to download files`);
|
|
191
|
+
}
|
|
185
192
|
}
|
|
186
193
|
return response;
|
|
187
194
|
}
|