@spider-cloud/spider-client 0.0.30 → 0.0.32
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/dist/client.d.ts +9 -0
- package/dist/client.js +26 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -107,6 +107,15 @@ export declare class Spider {
|
|
|
107
107
|
* @returns {Promise<any>} The crawl state data.
|
|
108
108
|
*/
|
|
109
109
|
getCrawlState(url: string, params?: GenericParams): Promise<any>;
|
|
110
|
+
/**
|
|
111
|
+
* Downloads files from the specified user's storage.
|
|
112
|
+
* @param {string} userId - The user's ID whose files you want to download.
|
|
113
|
+
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
114
|
+
* @param {number} [page] - The page number for pagination.
|
|
115
|
+
* @param {number} [limit] - The number of files to return per page.
|
|
116
|
+
* @returns {Promise<Response>} The response containing the file stream.
|
|
117
|
+
*/
|
|
118
|
+
downloadFiles(userId: string, domain?: string, page?: number, limit?: number): Promise<Response>;
|
|
110
119
|
/**
|
|
111
120
|
* Retrieves the number of credits available on the account.
|
|
112
121
|
* @returns {Promise<any>} The current credit balance.
|
package/dist/client.js
CHANGED
|
@@ -158,7 +158,32 @@ class Spider {
|
|
|
158
158
|
* @returns {Promise<any>} The crawl state data.
|
|
159
159
|
*/
|
|
160
160
|
async getCrawlState(url, params = {}) {
|
|
161
|
-
return this._apiPost("
|
|
161
|
+
return this._apiPost("data/crawl_state", { url: url, ...params });
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Downloads files from the specified user's storage.
|
|
165
|
+
* @param {string} userId - The user's ID whose files you want to download.
|
|
166
|
+
* @param {string} [domain] - The domain for the user's storage. If not provided, downloads all files.
|
|
167
|
+
* @param {number} [page] - The page number for pagination.
|
|
168
|
+
* @param {number} [limit] - The number of files to return per page.
|
|
169
|
+
* @returns {Promise<Response>} The response containing the file stream.
|
|
170
|
+
*/
|
|
171
|
+
async downloadFiles(userId, domain, page, limit) {
|
|
172
|
+
const params = new URLSearchParams({
|
|
173
|
+
...(domain && { domain }),
|
|
174
|
+
...(page && { page: page.toString() }),
|
|
175
|
+
...(limit && { limit: limit.toString() }),
|
|
176
|
+
});
|
|
177
|
+
const endpoint = `https://api.spider.cloud/v1/data/storage?${params.toString()}`;
|
|
178
|
+
const headers = this.prepareHeaders();
|
|
179
|
+
const response = await fetch(endpoint, {
|
|
180
|
+
method: "GET",
|
|
181
|
+
headers,
|
|
182
|
+
});
|
|
183
|
+
if (!response.ok) {
|
|
184
|
+
this.handleError(response, `download files for user: ${userId}`);
|
|
185
|
+
}
|
|
186
|
+
return response;
|
|
162
187
|
}
|
|
163
188
|
/**
|
|
164
189
|
* Retrieves the number of credits available on the account.
|