forked from Mini-Proto/amazon-listing-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-vercel-blob.ts
More file actions
83 lines (68 loc) · 2.49 KB
/
test-vercel-blob.ts
File metadata and controls
83 lines (68 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env node
import 'dotenv/config';
import chalk from 'chalk';
import { VercelBlobUploadService } from './api/vercel-blob-upload.js';
import { existsSync } from 'fs';
import { resolve } from 'path';
async function testVercelBlob() {
console.log(chalk.blue('🧪 Testing Vercel Blob Storage Integration\n'));
// Check configuration
if (!VercelBlobUploadService.validateConfiguration()) {
process.exit(1);
}
const token = process.env.VERCEL_BLOB_TOKEN!;
const service = new VercelBlobUploadService(token);
// Test image path
const testImagePath = resolve('test-images/test-harness.jpg');
if (!existsSync(testImagePath)) {
console.error(chalk.red('❌ Test image not found. Creating a test image...'));
// Create test image using Sharp
try {
const { default: sharp } = await import('sharp');
await sharp({
create: {
width: 1200,
height: 1200,
channels: 3,
background: { r: 255, g: 100, b: 100 }
}
})
.jpeg({ quality: 90 })
.toFile(testImagePath);
console.log(chalk.green('✅ Test image created'));
} catch (error) {
console.error(chalk.red('Failed to create test image:'), error);
process.exit(1);
}
}
// Test upload
try {
console.log(chalk.yellow('\n📤 Uploading test image to Vercel Blob...'));
const result = await service.uploadImage(testImagePath, 'TEST-SKU-123');
console.log(chalk.green('\n✅ Upload successful!'));
console.log(chalk.gray('URL:'), result.url);
console.log(chalk.gray('Download URL:'), result.downloadUrl);
console.log(chalk.gray('Path:'), result.pathname);
console.log(chalk.gray('Content Type:'), result.contentType);
console.log(chalk.blue('\n🌐 You can view the uploaded image at:'));
console.log(chalk.cyan(result.url));
// Test delete (optional)
const readline = await import('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const answer = await new Promise<string>(resolve => {
rl.question(chalk.yellow('\nDelete the uploaded image? (y/N): '), resolve);
});
rl.close();
if (answer.toLowerCase() === 'y') {
await service.deleteImage(result.url);
console.log(chalk.green('✅ Image deleted from Vercel Blob'));
}
} catch (error) {
console.error(chalk.red('❌ Upload failed:'), error);
process.exit(1);
}
}
testVercelBlob().catch(console.error);