wavespeed 0.0.5 → 0.0.7
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/index.d.ts +22 -0
- package/dist/index.js +42 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,16 @@ export type PredictionStatus = 'created' | 'processing' | 'completed' | 'failed'
|
|
|
11
11
|
export interface PredictionUrls {
|
|
12
12
|
get: string;
|
|
13
13
|
}
|
|
14
|
+
export interface UploadFileResp {
|
|
15
|
+
code: number;
|
|
16
|
+
message: string;
|
|
17
|
+
data: {
|
|
18
|
+
type: string;
|
|
19
|
+
download_url: string;
|
|
20
|
+
filename: string;
|
|
21
|
+
size: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
14
24
|
/**
|
|
15
25
|
* Request options for fetch
|
|
16
26
|
*/
|
|
@@ -18,6 +28,7 @@ export interface RequestOptions extends RequestInit {
|
|
|
18
28
|
timeout?: number;
|
|
19
29
|
maxRetries?: number;
|
|
20
30
|
webhook?: string;
|
|
31
|
+
isUpload?: boolean;
|
|
21
32
|
}
|
|
22
33
|
/**
|
|
23
34
|
* Prediction model representing an image generation job
|
|
@@ -94,5 +105,16 @@ export declare class WaveSpeed {
|
|
|
94
105
|
* @param options Additional fetch options
|
|
95
106
|
*/
|
|
96
107
|
create(modelId: string, input: Record<string, any>, options?: RequestOptions): Promise<Prediction>;
|
|
108
|
+
/**
|
|
109
|
+
* Upload a file (binary) to the /media/upload/binary endpoint
|
|
110
|
+
* @param filePath Absolute path to the file to upload
|
|
111
|
+
* @returns The API response JSON
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Upload a file (binary) to the /media/upload/binary endpoint (browser Blob version)
|
|
115
|
+
* @param file Blob to upload
|
|
116
|
+
* @returns The API response JSON
|
|
117
|
+
*/
|
|
118
|
+
upload(file: Blob, options?: RequestOptions): Promise<string>;
|
|
97
119
|
}
|
|
98
120
|
export default WaveSpeed;
|
package/dist/index.js
CHANGED
|
@@ -102,11 +102,19 @@ class WaveSpeed {
|
|
|
102
102
|
async fetchWithTimeout(path, options = {}) {
|
|
103
103
|
const { timeout = this.timeout * 1000, ...fetchOptions } = options;
|
|
104
104
|
// Ensure headers exist
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
if (!options.isUpload) {
|
|
106
|
+
fetchOptions.headers = {
|
|
107
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
108
|
+
...(fetchOptions.headers || {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
fetchOptions.headers = {
|
|
113
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
114
|
+
'content-type': 'application/json',
|
|
115
|
+
...(fetchOptions.headers || {}),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
110
118
|
// Default retry options
|
|
111
119
|
const maxRetries = options.maxRetries || 3;
|
|
112
120
|
const initialBackoff = 1000; // 1 second
|
|
@@ -218,6 +226,35 @@ class WaveSpeed {
|
|
|
218
226
|
}
|
|
219
227
|
return new Prediction(data.data, this);
|
|
220
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Upload a file (binary) to the /media/upload/binary endpoint
|
|
231
|
+
* @param filePath Absolute path to the file to upload
|
|
232
|
+
* @returns The API response JSON
|
|
233
|
+
*/
|
|
234
|
+
/**
|
|
235
|
+
* Upload a file (binary) to the /media/upload/binary endpoint (browser Blob version)
|
|
236
|
+
* @param file Blob to upload
|
|
237
|
+
* @returns The API response JSON
|
|
238
|
+
*/
|
|
239
|
+
async upload(file, options) {
|
|
240
|
+
const form = new FormData();
|
|
241
|
+
form.append('file', file);
|
|
242
|
+
// Only set Authorization header; browser will set Content-Type
|
|
243
|
+
if (options == null) {
|
|
244
|
+
options = { isUpload: true };
|
|
245
|
+
}
|
|
246
|
+
const response = await this.fetchWithTimeout('media/upload/binary', {
|
|
247
|
+
method: 'POST',
|
|
248
|
+
body: form,
|
|
249
|
+
...options
|
|
250
|
+
});
|
|
251
|
+
if (!response.ok) {
|
|
252
|
+
const errorText = await response.text();
|
|
253
|
+
throw new Error(`Failed to upload file: ${response.status} ${errorText}`);
|
|
254
|
+
}
|
|
255
|
+
const resp = await response.json();
|
|
256
|
+
return resp.data.download_url;
|
|
257
|
+
}
|
|
221
258
|
}
|
|
222
259
|
exports.WaveSpeed = WaveSpeed;
|
|
223
260
|
// Export default and named exports for different import styles
|