cleanup logs

This commit is contained in:
zramsay 2025-03-14 10:58:48 -04:00
parent a1ff58a3dc
commit 9b0963c005
3 changed files with 9 additions and 43 deletions

View File

@ -39,11 +39,6 @@ export async function analyzeImage(
// Append file to FormData
formData.append('image', file, filename)
// Log FormData contents for debugging
for (const [key, value] of formData.entries()) {
console.log('FormData entry:', key, value)
}
// Prepare headers with user data if available
const userHeaders: Record<string, string> = {
'Accept': 'application/json'
@ -51,16 +46,13 @@ export async function analyzeImage(
if (sessionData?.userId) {
userHeaders['x-user-id'] = sessionData.userId;
console.log(`Setting user ID header: ${sessionData.userId}`);
console.log(`User ID: ${sessionData.userId}`);
}
if (sessionData?.userEmail) {
userHeaders['x-user-email'] = sessionData.userEmail;
console.log(`Setting user email header: ${sessionData.userEmail}`);
console.log(`User Email: ${sessionData.userEmail}`);
}
// Log headers for debugging
console.log('Sending request with headers:', userHeaders);
const response = await fetch('/api/analyze', {
method: 'POST',
headers: userHeaders,
@ -79,7 +71,7 @@ export async function analyzeImage(
const errorJson = await response.json();
errorMessage = errorJson.error || errorMessage;
} catch (parseError) {
console.error('Error parsing JSON error response:', parseError);
console.error('Error parsing JSON error response:', parseError)
}
} else {
// Otherwise try to get the text
@ -87,12 +79,13 @@ export async function analyzeImage(
const errorText = await response.text();
errorMessage = errorText || errorMessage;
} catch (textError) {
console.error('Error reading error response text:', textError);
console.error('Error reading error response text:', textError)
}
}
// For 409 Conflict specifically, give a friendly message about duplicates without logging as error
// For 409 Conflict specifically, give a friendly message about duplicates
if (response.status === 409) {
// Log duplicate detection but not as an error
console.log('Duplicate image detected:', {
status: response.status,
message: errorMessage

View File

@ -13,13 +13,6 @@ export async function normalizeImageUpload(
options: ImageConversionOptions = {}
): Promise<File> {
try {
// Detailed initial logging
console.log('Original File Details:', {
name: file.name,
type: file.type,
size: file.size
})
// Default conversion options with cross-browser considerations
const defaultOptions = {
maxSizeMB: 2, // Keep original size limit
@ -45,15 +38,9 @@ export async function normalizeImageUpload(
{ type: 'image/jpeg' }
)
// Logging normalized file details
console.log('Normalized File Details:', {
name: normalizedImage.name,
type: normalizedImage.type,
size: normalizedImage.size
})
return normalizedImage
} catch (error) {
// Keep error logging for debugging
console.error('Image normalization error:', error)
throw error
}

View File

@ -19,17 +19,13 @@ export const POINTS = {
export async function ensureUserExists(userId: string, email: string, name?: string) {
try {
if (!userId) {
console.warn('Cannot ensure user exists with undefined userId');
return null;
}
if (!email) {
console.warn('Cannot ensure user exists with undefined email');
return null;
}
console.log('Ensuring user exists:', { userId, email });
// IMPORTANT: Do NOT generate a new UUID, only validate format
if (!validateUuid(userId)) {
console.warn('Invalid UUID format for user:', userId);
@ -45,7 +41,6 @@ export async function ensureUserExists(userId: string, email: string, name?: str
if (error) {
console.error('Error ensuring user exists:', error);
// Fallback to direct query approach
try {
// First check if a user with this email already exists
@ -66,10 +61,9 @@ export async function ensureUserExists(userId: string, email: string, name?: str
.eq('id', existingUserByEmail.id);
if (updateError) {
console.warn('Error updating existing user by email:', updateError);
// Error updating user
}
console.log('Found existing user by email, using their ID:', existingUserByEmail.id);
return existingUserByEmail.id;
}
@ -92,7 +86,7 @@ export async function ensureUserExists(userId: string, email: string, name?: str
.eq('id', userId);
if (updateError) {
console.warn('Error updating existing user by ID:', updateError);
// Error updating user
}
return userId;
@ -121,7 +115,6 @@ export async function ensureUserExists(userId: string, email: string, name?: str
}
}
console.log('User ensured with ID:', data);
return data;
} catch (error) {
console.error('Unexpected error in ensureUserExists:', error);
@ -145,7 +138,6 @@ export async function awardPointsForImage(
// This allows the app to work during database schema transitions
const safeMode = process.env.POINTS_SAFE_MODE === 'true';
if (safeMode) {
console.log('Points system running in SAFE MODE - bypassing database operations');
return {
success: true,
points: POINTS.IMAGE_UPLOAD,
@ -154,7 +146,6 @@ export async function awardPointsForImage(
}
if (!userId) {
console.warn('Missing user data, cannot award points', { userId, email });
return {
success: false,
message: 'Missing user data, cannot award points'
@ -170,8 +161,6 @@ export async function awardPointsForImage(
};
}
console.log('Award points starting values:', { userId, email });
// Ensure user exists in database and get the correct UUID
// This ensures we're always using the same UUID for a given email
const userUuid = await ensureUserExists(userId, email);
@ -190,7 +179,6 @@ export async function awardPointsForImage(
// Generate hash for the image
const imageHash = generateImageHash(imageBuffer);
console.log(`Processing points for image ${imageHash.substring(0, 8)}... for user ${userUuid}`);
// Check if this image has already been awarded points
const { data: existingImage, error: checkError } = await supabaseAdmin.rpc('check_duplicate_upload', {
@ -200,7 +188,6 @@ export async function awardPointsForImage(
if (checkError) {
console.log('Error checking for duplicate image:', checkError.message);
// Fallback to direct query
const { data: existingTransaction, error: directError } = await supabaseAdmin
.from('point_transactions')
@ -238,7 +225,6 @@ export async function awardPointsForImage(
if (rpcError) {
console.log('Error creating transaction via RPC:', rpcError.message);
// Fallback to direct insert
const { data: insertData, error: insertError } = await supabaseAdmin
.from('point_transactions')