glitch-javascript-sdk 1.4.5 → 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.5",
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,
@@ -203,34 +202,35 @@ class Requests {
203
202
  .join('&');
204
203
  url = `${url}?${queryString}`;
205
204
  }
206
-
205
+
207
206
  // Prepare FormData
208
207
  const formData = new FormData();
209
208
  formData.append(filename, blob);
210
-
209
+
211
210
  if (Requests.community_id) {
212
211
  data = {
213
212
  ...data,
214
213
  communities: [Requests.community_id],
215
214
  };
216
215
  }
217
-
216
+
218
217
  for (let key in data) {
219
218
  formData.append(key, data[key]);
220
219
  }
221
-
220
+
222
221
  // Prepare headers
223
222
  let headers: { [key: string]: string } = {
224
223
  'Content-Type': 'multipart/form-data',
225
224
  };
226
-
225
+
227
226
  if (Requests.authToken) {
228
227
  headers['Authorization'] = `Bearer ${Requests.authToken}`;
229
228
  }
230
-
231
- // Construct the full URL properly
232
- const uri = new URL(url, Requests.baseUrl).href;
233
-
229
+
230
+ // Format URL
231
+ url = url.replace(/\/\//g, '/');
232
+ const uri = `${Requests.baseUrl}${url}`.replace(/\/\//g, '/');
233
+
234
234
  // Make the request
235
235
  return axios({
236
236
  method: 'POST',
@@ -240,7 +240,7 @@ class Requests {
240
240
  onUploadProgress,
241
241
  });
242
242
  }
243
-
243
+
244
244
 
245
245
  // Method adapted for browser environments
246
246