@spider-cloud/spider-client 0.0.33 → 0.0.35
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 +14 -0
- package/dist/client.d.ts +6 -4
- package/dist/client.js +14 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -91,6 +91,19 @@ spider
|
|
|
91
91
|
.catch((error) => console.error(error));
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
#### Download storage data
|
|
95
|
+
|
|
96
|
+
To download stored data like raw HTML or markdown use the `downloadFiles` method. Provide the website name and an object containing query parameters:
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
const websiteName = "spider.cloud";
|
|
100
|
+
const queryParams = { limit: 20, page: 0 };
|
|
101
|
+
spider
|
|
102
|
+
.downloadFiles(websiteName, queryParams)
|
|
103
|
+
.then((response) => console.log(response))
|
|
104
|
+
.catch((error) => console.error(error));
|
|
105
|
+
```
|
|
106
|
+
|
|
94
107
|
### Available Methods
|
|
95
108
|
|
|
96
109
|
- **`scrapeUrl(url, params)`**: Scrape data from a specified URL. Optional parameters can be passed to customize the scraping behavior.
|
|
@@ -105,6 +118,7 @@ spider
|
|
|
105
118
|
- **`getCredits()`**: Retrieve account's remaining credits.
|
|
106
119
|
- **`getData(table, params)`**: Retrieve data records from the DB.
|
|
107
120
|
- **`deleteData(table, params)`**: Delete records from the DB.
|
|
121
|
+
- **`downloadFiles(domain, params)`**: Download the records from the DB.
|
|
108
122
|
|
|
109
123
|
## Error Handling
|
|
110
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
|
-
* Downloads files from the specified user's storage.
|
|
111
|
+
* Downloads files from the specified user's storage. This will create signed URLS to use.
|
|
112
112
|
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
113
|
-
* @param {
|
|
114
|
-
* @param {
|
|
113
|
+
* @param {Object} [options] - The download options.
|
|
114
|
+
* @param {boolean} [raw] - Return the raw response.
|
|
115
|
+
|
|
115
116
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
116
117
|
*/
|
|
117
118
|
downloadFiles(domain?: string, options?: {
|
|
118
119
|
page?: number;
|
|
119
120
|
limit?: number;
|
|
120
|
-
|
|
121
|
+
expiresIn?: number;
|
|
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,18 +161,20 @@ class Spider {
|
|
|
161
161
|
return this._apiPost("data/crawl_state", { url: url, ...params });
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
|
-
* Downloads files from the specified user's storage.
|
|
164
|
+
* Downloads files from the specified user's storage. This will create signed URLS to use.
|
|
165
165
|
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
166
|
-
* @param {
|
|
167
|
-
* @param {
|
|
166
|
+
* @param {Object} [options] - The download options.
|
|
167
|
+
* @param {boolean} [raw] - Return the raw response.
|
|
168
|
+
|
|
168
169
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
169
170
|
*/
|
|
170
|
-
async downloadFiles(domain, options) {
|
|
171
|
-
const { page, limit } = options !== null && options !== void 0 ? options : {};
|
|
171
|
+
async downloadFiles(domain, options, raw) {
|
|
172
|
+
const { page, limit, expiresIn } = options !== null && options !== void 0 ? options : {};
|
|
172
173
|
const params = new URLSearchParams({
|
|
173
174
|
...(domain && { domain }),
|
|
174
175
|
...(page && { page: page.toString() }),
|
|
175
176
|
...(limit && { limit: limit.toString() }),
|
|
177
|
+
...(expiresIn && { expiresIn: expiresIn.toString() }),
|
|
176
178
|
});
|
|
177
179
|
const endpoint = `https://api.spider.cloud/v1/data/storage?${params.toString()}`;
|
|
178
180
|
const headers = this.prepareHeaders();
|
|
@@ -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
|
}
|