bytex-sdk 1.7.3 → 1.7.5

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/index.js +21 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -359,15 +359,34 @@ export class BytexCloud {
359
359
  */
360
360
  async download(name, password) {
361
361
  this._requireKey();
362
- const streamName = name.endsWith('.stream.btx') ? name : `${name}.stream.btx`;
362
+ // Only append .stream.btx if it's a media file or doesn't have an extension
363
+ const isDataFile = name.endsWith('.json') || name.endsWith('.txt') || name.endsWith('.csv');
364
+ const streamName = (isDataFile || name.endsWith('.stream.btx')) ? name : `${name}.stream.btx`;
365
+
363
366
  let url = `${this.workerUrl}?action=view&key=${this.apiKey}&file=${encodeURIComponent(streamName)}`;
364
367
  if (password) url += `&password=${encodeURIComponent(password)}`;
365
368
 
366
- const res = await fetch(url);
369
+ const { data: { session } } = await this.supabase.auth.getSession();
370
+ const res = await fetch(url, {
371
+ headers: {
372
+ 'Authorization': `Bearer ${session?.access_token || ''}`
373
+ }
374
+ });
367
375
  if (!res.ok) throw new Error(`Download failed: ${res.status}`);
368
376
  return await res.blob();
369
377
  }
370
378
 
379
+ /**
380
+ * Helper to download JSON data directly from cloud.
381
+ * @param {string} name
382
+ * @returns {object}
383
+ */
384
+ async downloadData(name) {
385
+ const blob = await this.download(name);
386
+ const text = await blob.text();
387
+ return JSON.parse(text);
388
+ }
389
+
371
390
  /**
372
391
  * Get the streaming URL for a media file (video/audio).
373
392
  * Supports precision seeking with range requests.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bytex-sdk",
3
- "version": "1.7.3",
3
+ "version": "1.7.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {