@devicecloud.dev/dcd 4.4.0 → 4.4.1

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/dist/methods.js CHANGED
@@ -326,15 +326,15 @@ async function uploadToSupabase(env, tempPath, file, debug) {
326
326
  * @returns Upload result with success status and any error
327
327
  */
328
328
  async function handleBackblazeUpload(config) {
329
- const { b2, apiUrl, apiKey, finalPath, file, filePath, debug, supabaseSuccess } = config;
329
+ const { b2, apiUrl, apiKey, finalPath, file, filePath, debug } = config;
330
330
  if (!b2) {
331
- if (debug && !supabaseSuccess) {
332
- console.log('[DEBUG] Backblaze not configured, cannot fallback');
331
+ if (debug) {
332
+ console.log('[DEBUG] Backblaze not configured, will fall back to Supabase');
333
333
  }
334
334
  return { error: null, success: false };
335
335
  }
336
336
  if (debug) {
337
- console.log(supabaseSuccess ? '[DEBUG] Starting Backblaze backup upload...' : '[DEBUG] Starting Backblaze fallback upload...');
337
+ console.log('[DEBUG] Starting Backblaze upload (primary)...');
338
338
  }
339
339
  try {
340
340
  const b2UploadStartTime = Date.now();
@@ -484,10 +484,7 @@ async function performUpload(config) {
484
484
  // Extract app metadata
485
485
  const metadata = await extractBinaryMetadata(filePath, debug);
486
486
  const env = apiUrl === 'https://api.devicecloud.dev' ? 'prod' : 'dev';
487
- // Upload to Supabase
488
- const supabaseResult = await uploadToSupabase(env, tempPath, file, debug);
489
- let lastError = supabaseResult.error;
490
- // Upload to Backblaze
487
+ // Upload to Backblaze first (primary)
491
488
  const backblazeResult = await handleBackblazeUpload({
492
489
  apiKey,
493
490
  apiUrl,
@@ -496,26 +493,36 @@ async function performUpload(config) {
496
493
  file,
497
494
  filePath,
498
495
  finalPath,
499
- supabaseSuccess: supabaseResult.success,
500
496
  });
501
- // Update lastError if Supabase also failed
502
- if (!supabaseResult.success && backblazeResult.error) {
503
- lastError = backblazeResult.error;
497
+ let lastError = backblazeResult.error;
498
+ // Only upload to Supabase if Backblaze failed
499
+ let supabaseResult = { error: null, success: false };
500
+ if (!backblazeResult.success) {
501
+ if (debug) {
502
+ console.log('[DEBUG] Backblaze upload failed, falling back to Supabase...');
503
+ }
504
+ supabaseResult = await uploadToSupabase(env, tempPath, file, debug);
505
+ if (!supabaseResult.success && supabaseResult.error) {
506
+ lastError = supabaseResult.error;
507
+ }
508
+ }
509
+ else if (debug) {
510
+ console.log('[DEBUG] Backblaze upload succeeded, skipping Supabase upload');
504
511
  }
505
512
  // Validate results
506
513
  validateUploadResults(supabaseResult.success, backblazeResult.success, lastError, b2, debug);
507
514
  // Log upload summary
508
515
  if (debug) {
509
- const hasWarning = !supabaseResult.success && backblazeResult.success;
510
- console.log(`[DEBUG] Upload summary - Supabase: ${supabaseResult.success ? '✓' : '✗'}, Backblaze: ${backblazeResult.success ? '✓' : '✗'}`);
516
+ const hasWarning = supabaseResult.success && !backblazeResult.success;
517
+ console.log(`[DEBUG] Upload summary - Backblaze: ${backblazeResult.success ? '✓' : '✗'}, Supabase: ${supabaseResult.success ? '✓' : '✗ (fallback ' + (backblazeResult.success ? 'not needed' : 'attempted') + ')'}`);
511
518
  console.log('[DEBUG] Finalizing upload...');
512
519
  console.log(`[DEBUG] Target endpoint: ${apiUrl}/uploads/finaliseUpload`);
513
520
  console.log(`[DEBUG] Uploaded to staging path: ${tempPath}`);
514
521
  console.log(`[DEBUG] API will move to final path: ${finalPath}`);
515
- console.log(`[DEBUG] Supabase upload status: ${supabaseResult.success ? 'SUCCESS' : 'FAILED'}`);
516
522
  console.log(`[DEBUG] Backblaze upload status: ${backblazeResult.success ? 'SUCCESS' : 'FAILED'}`);
523
+ console.log(`[DEBUG] Supabase upload status: ${supabaseResult.success ? 'SUCCESS (fallback)' : backblazeResult.success ? 'SKIPPED' : 'FAILED'}`);
517
524
  if (hasWarning)
518
- console.log('[DEBUG] ⚠ Warning: File only exists in Backblaze (Supabase failed)');
525
+ console.log('[DEBUG] ⚠ Warning: File only exists in Supabase (Backblaze failed)');
519
526
  }
520
527
  // Finalize upload
521
528
  const finalizeStartTime = Date.now();
@@ -880,5 +880,5 @@
880
880
  ]
881
881
  }
882
882
  },
883
- "version": "4.4.0"
883
+ "version": "4.4.1"
884
884
  }
package/package.json CHANGED
@@ -69,7 +69,7 @@
69
69
  "type": "git",
70
70
  "url": "https://devicecloud.dev"
71
71
  },
72
- "version": "4.4.0",
72
+ "version": "4.4.1",
73
73
  "bugs": {
74
74
  "url": "https://discord.gg/gm3mJwcNw8"
75
75
  },