@spider-cloud/spider-client 0.0.32 → 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 +7 -5
- package/dist/client.js +6 -6
- 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,14 +108,16 @@ 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.
|
|
112
|
-
* @param {string} userId - The user's ID whose files you want to download.
|
|
111
|
+
* Downloads files from the specified user's storage. This will create signed URLS to use.
|
|
113
112
|
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
114
|
-
* @param {
|
|
115
|
-
* @param {number} [limit] - The number of files to return per page.
|
|
113
|
+
* @param {Object} [options] - The download options
|
|
116
114
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
117
115
|
*/
|
|
118
|
-
downloadFiles(
|
|
116
|
+
downloadFiles(domain?: string, options?: {
|
|
117
|
+
page?: number;
|
|
118
|
+
limit?: number;
|
|
119
|
+
expiresIn?: number;
|
|
120
|
+
}): Promise<Response>;
|
|
119
121
|
/**
|
|
120
122
|
* Retrieves the number of credits available on the account.
|
|
121
123
|
* @returns {Promise<any>} The current credit balance.
|
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.
|
|
165
|
-
* @param {string} userId - The user's ID whose files you want to download.
|
|
164
|
+
* Downloads files from the specified user's storage. This will create signed URLS to use.
|
|
166
165
|
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
167
|
-
* @param {
|
|
168
|
-
* @param {number} [limit] - The number of files to return per page.
|
|
166
|
+
* @param {Object} [options] - The download options
|
|
169
167
|
* @returns {Promise<Response>} The response containing the file stream.
|
|
170
168
|
*/
|
|
171
|
-
async downloadFiles(
|
|
169
|
+
async downloadFiles(domain, 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, `download files
|
|
184
|
+
this.handleError(response, `Failed to download files`);
|
|
185
185
|
}
|
|
186
186
|
return response;
|
|
187
187
|
}
|