This commit introduces several new scripts for managing database operations, including user creation, permission grants, and data migrations. It also adds new documentation files to guide users through the setup and configuration processes. Additionally, the project structure is updated to enhance organization and maintainability, ensuring a smoother development experience for contributors. These changes support the ongoing transition to a web-based architecture and improve overall project functionality.
103 lines
2.3 KiB
TypeScript
103 lines
2.3 KiB
TypeScript
/**
|
|
* Test script to verify image source detection logic
|
|
* Run with: npx tsx test-image-detection.ts
|
|
*/
|
|
|
|
/**
|
|
* Determines if a path is a URL (http/https) or a file system path
|
|
*/
|
|
function isUrl(path: string): boolean {
|
|
return path.startsWith('http://') || path.startsWith('https://');
|
|
}
|
|
|
|
/**
|
|
* Gets the appropriate image source URL
|
|
*/
|
|
function getImageSrc(photoId: number, path: string): string {
|
|
if (isUrl(path)) {
|
|
return path; // Direct access
|
|
} else {
|
|
return `/api/photos/${photoId}/image`; // API proxy
|
|
}
|
|
}
|
|
|
|
// Test cases
|
|
const testCases = [
|
|
{
|
|
id: 1,
|
|
path: 'https://picsum.photos/800/600',
|
|
expected: 'direct',
|
|
description: 'HTTPS URL (SharePoint, CDN)',
|
|
},
|
|
{
|
|
id: 2,
|
|
path: 'http://example.com/image.jpg',
|
|
expected: 'direct',
|
|
description: 'HTTP URL',
|
|
},
|
|
{
|
|
id: 3,
|
|
path: '/path/to/photos/image.jpg',
|
|
expected: 'proxy',
|
|
description: 'Unix file system path',
|
|
},
|
|
{
|
|
id: 4,
|
|
path: 'C:\\Photos\\image.jpg',
|
|
expected: 'proxy',
|
|
description: 'Windows file system path',
|
|
},
|
|
{
|
|
id: 5,
|
|
path: 'https://yourcompany.sharepoint.com/sites/Photos/image.jpg',
|
|
expected: 'direct',
|
|
description: 'SharePoint Online URL',
|
|
},
|
|
{
|
|
id: 6,
|
|
path: 'https://sharepoint.company.com/sites/Photos/image.jpg',
|
|
expected: 'direct',
|
|
description: 'SharePoint Server URL',
|
|
},
|
|
];
|
|
|
|
console.log('🧪 Testing Image Source Detection Logic\n');
|
|
console.log('=' .repeat(60));
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
testCases.forEach((testCase) => {
|
|
const result = getImageSrc(testCase.id, testCase.path);
|
|
const isDirect = isUrl(testCase.path);
|
|
const actual = isDirect ? 'direct' : 'proxy';
|
|
const success = actual === testCase.expected;
|
|
|
|
if (success) {
|
|
passed++;
|
|
console.log(`✅ Test ${testCase.id}: PASSED`);
|
|
} else {
|
|
failed++;
|
|
console.log(`❌ Test ${testCase.id}: FAILED`);
|
|
}
|
|
|
|
console.log(` Description: ${testCase.description}`);
|
|
console.log(` Path: ${testCase.path}`);
|
|
console.log(` Detected as: ${actual} (expected: ${testCase.expected})`);
|
|
console.log(` Image src: ${result}`);
|
|
console.log('');
|
|
});
|
|
|
|
console.log('=' .repeat(60));
|
|
console.log(`Results: ${passed} passed, ${failed} failed`);
|
|
|
|
if (failed === 0) {
|
|
console.log('🎉 All tests passed!');
|
|
process.exit(0);
|
|
} else {
|
|
console.log('⚠️ Some tests failed');
|
|
process.exit(1);
|
|
}
|
|
|
|
|