@spider-cloud/spider-client 0.0.33 → 0.0.34
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 +3 -3
- package/dist/client.js +5 -5
- 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,15 +108,15 @@ 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 {number} [limit] - The number of files to return per page.
|
|
113
|
+
* @param {Object} [options] - The download options
|
|
115
114
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
116
115
|
*/
|
|
117
116
|
downloadFiles(domain?: string, options?: {
|
|
118
117
|
page?: number;
|
|
119
118
|
limit?: number;
|
|
119
|
+
expiresIn?: number;
|
|
120
120
|
}): Promise<Response>;
|
|
121
121
|
/**
|
|
122
122
|
* Retrieves the number of credits available on the account.
|
package/dist/client.js
CHANGED
|
@@ -161,18 +161,18 @@ 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 {number} [limit] - The number of files to return per page.
|
|
166
|
+
* @param {Object} [options] - The download options
|
|
168
167
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
169
168
|
*/
|
|
170
169
|
async downloadFiles(domain, options) {
|
|
171
|
-
const { page, limit } = options !== null && options !== void 0 ? options : {};
|
|
170
|
+
const { page, limit, expiresIn } = options !== null && options !== void 0 ? options : {};
|
|
172
171
|
const params = new URLSearchParams({
|
|
173
172
|
...(domain && { domain }),
|
|
174
173
|
...(page && { page: page.toString() }),
|
|
175
174
|
...(limit && { limit: limit.toString() }),
|
|
175
|
+
...(expiresIn && { expiresIn: expiresIn.toString() }),
|
|
176
176
|
});
|
|
177
177
|
const endpoint = `https://api.spider.cloud/v1/data/storage?${params.toString()}`;
|
|
178
178
|
const headers = this.prepareHeaders();
|
|
@@ -181,7 +181,7 @@ class Spider {
|
|
|
181
181
|
headers,
|
|
182
182
|
});
|
|
183
183
|
if (!response.ok) {
|
|
184
|
-
this.handleError(response, `
|
|
184
|
+
this.handleError(response, `Failed to download files`);
|
|
185
185
|
}
|
|
186
186
|
return response;
|
|
187
187
|
}
|