glitch-javascript-sdk 1.4.6 → 1.4.8

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.8",
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)
@@ -225,16 +219,14 @@ class Requests {
225
219
  }
226
220
 
227
221
  // Prepare headers
228
- let headers: { [key: string]: string } = {
229
- 'Content-Type': 'multipart/form-data',
230
- };
222
+ let headers: { [key: string]: string } = {};
231
223
 
232
224
  if (Requests.authToken) {
233
225
  headers['Authorization'] = `Bearer ${Requests.authToken}`;
234
226
  }
235
227
 
236
- // Construct the full URL properly
237
- const uri = new URL(url, Requests.baseUrl).href;
228
+ // Format URL correctly
229
+ const uri = Requests.baseUrl.replace(/\/+$/, '') + '/' + url.replace(/^\/+/, '');
238
230
 
239
231
  // Make the request
240
232
  return axios({
@@ -247,6 +239,7 @@ class Requests {
247
239
  }
248
240
 
249
241
 
242
+
250
243
  // Method adapted for browser environments
251
244
 
252
245
  public static async uploadFileInChunks<T>(
@@ -257,10 +250,6 @@ class Requests {
257
250
  chunkSize?: number, // Default chunk size of 1MB
258
251
  ): Promise<void> {
259
252
 
260
- if (!uploadUrl.startsWith('/api')) {
261
- uploadUrl = `/api${uploadUrl}`;
262
- }
263
-
264
253
  if (!chunkSize) {
265
254
  chunkSize = 1024 * 1024
266
255
  }