NeahNew/lib/mission-uploads.ts
2025-05-24 12:44:18 +02:00

48 lines
1.7 KiB
TypeScript

/**
* Utilities for mission-related file paths
*/
// Generate the mission logo path in Minio
export function getMissionLogoPath(userId: string, missionId: string, fileExtension: string): string {
// Use a consistent path structure: missions/{missionId}/logo{extension}
return `missions/${missionId}/logo${fileExtension}`;
}
// Generate the mission attachment path in Minio
export function getMissionAttachmentPath(userId: string, missionId: string, filename: string): string {
// Use a consistent path structure: missions/{missionId}/attachments/{filename}
return `missions/${missionId}/attachments/${filename}`;
}
// Helper function to ensure a path has the missions/ prefix
export function ensureMissionsPrefix(path: string): string {
return path.startsWith('missions/') ? path : `missions/${path}`;
}
// Helper function to construct a public URL for a mission file
export function getMissionFileUrl(path: string): string {
const normalizedPath = ensureMissionsPrefix(path);
return `/api/missions/image/${normalizedPath}`;
}
// Helper function to delete a mission logo
export async function deleteMissionLogo(missionId: string, logoPath: string): Promise<void> {
try {
const normalizedPath = ensureMissionsPrefix(logoPath);
// Add your S3/MinIO deletion logic here
console.log('Deleting mission logo:', {
missionId,
originalPath: logoPath,
normalizedPath
});
} catch (error) {
console.error('Error deleting mission logo:', {
error,
missionId,
logoPath,
errorType: error instanceof Error ? error.constructor.name : typeof error,
message: error instanceof Error ? error.message : String(error)
});
throw error;
}
}