glitch-javascript-sdk 1.4.6 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glitch-javascript-sdk",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "Javascript SDK for Glitch",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -150,34 +150,32 @@ class Requests {
150
150
  .join('&');
151
151
  url = `${url}?${queryString}`;
152
152
  }
153
-
153
+
154
154
  // Prepare FormData
155
155
  const formData = new FormData();
156
156
  formData.append(filename, file);
157
-
157
+
158
158
  if (Requests.community_id) {
159
159
  data = {
160
160
  ...data,
161
161
  communities: [Requests.community_id],
162
162
  };
163
163
  }
164
-
164
+
165
165
  for (let key in data) {
166
166
  formData.append(key, data[key]);
167
167
  }
168
-
168
+
169
169
  // Prepare headers
170
- let headers: { [key: string]: string } = {
171
- 'Content-Type': 'multipart/form-data',
172
- };
173
-
170
+ let headers: { [key: string]: string } = {};
171
+
174
172
  if (Requests.authToken) {
175
173
  headers['Authorization'] = `Bearer ${Requests.authToken}`;
176
174
  }
177
-
178
- // Construct the full URL properly
179
- const uri = new URL(url, Requests.baseUrl).href;
180
-
175
+
176
+ // Format URL correctly
177
+ const uri = Requests.baseUrl.replace(/\/+$/, '') + '/' + url.replace(/^\/+/, '');
178
+
181
179
  // Make the request
182
180
  return axios({
183
181
  method: 'POST',
@@ -187,7 +185,8 @@ class Requests {
187
185
  onUploadProgress,
188
186
  });
189
187
  }
190
-
188
+
189
+
191
190
  public static uploadBlob<T>(
192
191
  url: string,
193
192
  filename: string,
@@ -196,11 +195,6 @@ class Requests {
196
195
  params?: Record<string, any>,
197
196
  onUploadProgress?: (progressEvent: AxiosProgressEvent) => void
198
197
  ): AxiosPromise<Response<T>> {
199
-
200
- if (!url.startsWith('/api')) {
201
- url = `/api${url}`;
202
- }
203
-
204
198
  // Process URL and params
205
199
  if (params && Object.keys(params).length > 0) {
206
200
  const queryString = Object.entries(params)
@@ -208,34 +202,35 @@ class Requests {
208
202
  .join('&');
209
203
  url = `${url}?${queryString}`;
210
204
  }
211
-
205
+
212
206
  // Prepare FormData
213
207
  const formData = new FormData();
214
208
  formData.append(filename, blob);
215
-
209
+
216
210
  if (Requests.community_id) {
217
211
  data = {
218
212
  ...data,
219
213
  communities: [Requests.community_id],
220
214
  };
221
215
  }
222
-
216
+
223
217
  for (let key in data) {
224
218
  formData.append(key, data[key]);
225
219
  }
226
-
220
+
227
221
  // Prepare headers
228
222
  let headers: { [key: string]: string } = {
229
223
  'Content-Type': 'multipart/form-data',
230
224
  };
231
-
225
+
232
226
  if (Requests.authToken) {
233
227
  headers['Authorization'] = `Bearer ${Requests.authToken}`;
234
228
  }
235
-
236
- // Construct the full URL properly
237
- const uri = new URL(url, Requests.baseUrl).href;
238
-
229
+
230
+ // Format URL
231
+ url = url.replace(/\/\//g, '/');
232
+ const uri = `${Requests.baseUrl}${url}`.replace(/\/\//g, '/');
233
+
239
234
  // Make the request
240
235
  return axios({
241
236
  method: 'POST',
@@ -245,7 +240,7 @@ class Requests {
245
240
  onUploadProgress,
246
241
  });
247
242
  }
248
-
243
+
249
244
 
250
245
  // Method adapted for browser environments
251
246
 
@@ -257,10 +252,6 @@ class Requests {
257
252
  chunkSize?: number, // Default chunk size of 1MB
258
253
  ): Promise<void> {
259
254
 
260
- if (!uploadUrl.startsWith('/api')) {
261
- uploadUrl = `/api${uploadUrl}`;
262
- }
263
-
264
255
  if (!chunkSize) {
265
256
  chunkSize = 1024 * 1024
266
257
  }