Skip to content

Conversation

@davidhu2000
Copy link
Contributor

@davidhu2000 davidhu2000 commented Jan 14, 2026

realized we didn't support this in the node sdk, but supports it in python. so added the same logic here.

I had claude build a simple test script

=== Testing URL Support ===

Test 1: HTTP URL
  Input:  http://example.com/image.jpg
  Output: http://example.com/image.jpg
  Pass:   true

Test 2: HTTPS URL
  Input:  https://example.com/video.mp4
  Output: https://example.com/video.mp4
  Pass:   true

Test 3: URL with query parameters
  Input:  https://cdn.example.com/assets/image.png?token=abc123&size=large
  Output: https://cdn.example.com/assets/image.png?token=abc123&size=large
  Pass:   true

Test 4: Already-uploaded api-assets path
  Input:  api-assets/id/1234.png
  Output: api-assets/id/1234.png
  Pass:   true

Test 5: Invalid URL protocol (file://) - should fail
  Error:  File not found: file:///path/to/file.jpg
  Pass:   true

Test 6: Non-existent local file - should fail
  Error:  File not found: /path/to/nonexistent/file.jpg
  Pass:   true

=== Tests Complete ===
The script
/**
 * Simple test script to verify URL support in uploadFile()
 *
 * Usage: npx ts-node test-url-support.ts
 */

import Client from "./src";

async function main() {
  const client = new Client({
    token: process.env.MAGIC_HOUR_API_TOKEN || "test-token",
  });

  console.log("\n=== Testing URL Support ===\n");

  // Test 1: HTTP URL
  console.log("Test 1: HTTP URL");
  const httpUrl = "http://example.com/image.jpg";
  const result1 = await client.v1.files.uploadFile(httpUrl);
  console.log(`  Input:  ${httpUrl}`);
  console.log(`  Output: ${result1}`);
  console.log(`  Pass:   ${result1 === httpUrl}\n`);

  // Test 2: HTTPS URL
  console.log("Test 2: HTTPS URL");
  const httpsUrl = "https://example.com/video.mp4";
  const result2 = await client.v1.files.uploadFile(httpsUrl);
  console.log(`  Input:  ${httpsUrl}`);
  console.log(`  Output: ${result2}`);
  console.log(`  Pass:   ${result2 === httpsUrl}\n`);

  // Test 3: URL with query params
  console.log("Test 3: URL with query parameters");
  const urlWithParams =
    "https://cdn.example.com/assets/image.png?token=abc123&size=large";
  const result3 = await client.v1.files.uploadFile(urlWithParams);
  console.log(`  Input:  ${urlWithParams}`);
  console.log(`  Output: ${result3}`);
  console.log(`  Pass:   ${result3 === urlWithParams}\n`);

  // Test 4: Already-uploaded path
  console.log("Test 4: Already-uploaded api-assets path");
  const apiAssets = "api-assets/id/1234.png";
  const result4 = await client.v1.files.uploadFile(apiAssets);
  console.log(`  Input:  ${apiAssets}`);
  console.log(`  Output: ${result4}`);
  console.log(`  Pass:   ${result4 === apiAssets}\n`);

  // Test 5: Invalid URL (should fail - file not found)
  console.log("Test 5: Invalid URL protocol (file://) - should fail");
  const fileUrl = "file:///path/to/file.jpg";
  try {
    await client.v1.files.uploadFile(fileUrl);
    console.log(`  Pass:   false (should have thrown)\n`);
  } catch (e: any) {
    console.log(`  Error:  ${e.message}`);
    console.log(`  Pass:   ${e.message.includes("File not found")}\n`);
  }

  // Test 6: Non-existent local file (should fail)
  console.log("Test 6: Non-existent local file - should fail");
  const localPath = "/path/to/nonexistent/file.jpg";
  try {
    await client.v1.files.uploadFile(localPath);
    console.log(`  Pass:   false (should have thrown)\n`);
  } catch (e: any) {
    console.log(`  Error:  ${e.message}`);
    console.log(`  Pass:   ${e.message.includes("File not found")}\n`);
  }

  console.log("=== Tests Complete ===\n");
}

main().catch(console.error);

@davidhu2000 davidhu2000 merged commit 77a0439 into main Jan 14, 2026
5 checks passed
@davidhu2000 davidhu2000 deleted the support-local-path branch January 14, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants