wtfai 1.6.2 → 1.6.4

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.
Files changed (2) hide show
  1. package/dist/upload.js +21 -14
  2. package/package.json +1 -1
package/dist/upload.js CHANGED
@@ -79,13 +79,7 @@ class UploadService {
79
79
  'Content-Type': 'application/json',
80
80
  ...this.headers
81
81
  },
82
- body: JSON.stringify({
83
- resourceType: params.resourceType,
84
- filename: params.filename,
85
- hash: params.hash,
86
- size: params.size,
87
- durationSeconds: params.durationSeconds
88
- })
82
+ body: JSON.stringify(params)
89
83
  });
90
84
  if (!response.ok) {
91
85
  const error = await response.json().catch(()=>({}));
@@ -112,7 +106,7 @@ class UploadService {
112
106
  };
113
107
  }
114
108
  async uploadFile(params) {
115
- const { file, resourceType, onProgress } = params;
109
+ const { file, resourceType, onProgress, ...rest } = params;
116
110
  const hash = await this.computeFileHash(file);
117
111
  let durationSeconds;
118
112
  if (this.isMediaFile(file)) durationSeconds = await this.getMediaDuration(file);
@@ -121,7 +115,8 @@ class UploadService {
121
115
  filename: file.name,
122
116
  hash,
123
117
  size: file.size,
124
- durationSeconds
118
+ durationSeconds,
119
+ ...rest
125
120
  });
126
121
  return new Promise((resolve, reject)=>{
127
122
  cos.putObject({
@@ -132,22 +127,34 @@ class UploadService {
132
127
  onProgress: (progressData)=>{
133
128
  if (onProgress) onProgress(progressData.percent);
134
129
  }
135
- }, (err, _data)=>{
130
+ }, async (err, _data)=>{
136
131
  if (err) reject(err);
137
132
  else {
138
- const url = cdnDomain ? `https://${cdnDomain}/${key}` : `https://${bucket}.cos.${region}.myqcloud.com/${key}`;
139
- resolve(url);
133
+ const searchParams = new URLSearchParams({
134
+ key,
135
+ ...rest
136
+ });
137
+ const res = await fetch(`${this.baseUrl}/workflows/signed-url?${searchParams.toString()}`, {
138
+ method: 'GET',
139
+ headers: {
140
+ 'Content-Type': 'application/json',
141
+ ...this.headers
142
+ }
143
+ });
144
+ const data = await res.json();
145
+ resolve(data.url);
140
146
  }
141
147
  });
142
148
  });
143
149
  }
144
150
  async uploadImage(params) {
145
- const { file, resourceType, onProgress, compressOptions } = params;
151
+ const { file, resourceType, onProgress, compressOptions, ...rest } = params;
146
152
  const compressedFile = await this.compressImage(file, compressOptions);
147
153
  return this.uploadFile({
148
154
  file: compressedFile,
149
155
  resourceType,
150
- onProgress
156
+ onProgress,
157
+ ...rest
151
158
  });
152
159
  }
153
160
  constructor(baseUrl, headers = {}){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtfai",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {