debug: add comprehensive logging to recipe image upload flow
All checks were successful
CI / update (push) Successful in 1m23s
All checks were successful
CI / update (push) Successful in 1m23s
Add detailed console logging throughout the image upload pipeline to help diagnose upload issues: - Log file metadata and validation steps in imageValidation.ts - Log image processing and file saving operations in imageProcessing.ts - Log form data and processing steps in recipe add page action - Log API request details and upload progress in img/add endpoint All logs are prefixed with component name ([ImageValidation], [ImageProcessing], [RecipeAdd], [API:ImgAdd]) for easy filtering and debugging.
This commit is contained in:
@@ -36,13 +36,19 @@ export const actions = {
|
||||
|
||||
try {
|
||||
const formData = await request.formData();
|
||||
console.log('[RecipeAdd] Form data received');
|
||||
|
||||
// Extract recipe data from FormData
|
||||
const recipeData = extractRecipeFromFormData(formData);
|
||||
console.log('[RecipeAdd] Recipe data extracted:', {
|
||||
short_name: recipeData.short_name,
|
||||
title: recipeData.title
|
||||
});
|
||||
|
||||
// Validate required fields
|
||||
const validationErrors = validateRecipeData(recipeData);
|
||||
if (validationErrors.length > 0) {
|
||||
console.error('[RecipeAdd] Validation errors:', validationErrors);
|
||||
return fail(400, {
|
||||
error: validationErrors.join(', '),
|
||||
errors: validationErrors,
|
||||
@@ -52,8 +58,16 @@ export const actions = {
|
||||
|
||||
// Handle optional image upload
|
||||
const recipeImage = formData.get('recipe_image') as File | null;
|
||||
console.log('[RecipeAdd] Recipe image from form:', {
|
||||
hasImage: !!recipeImage,
|
||||
size: recipeImage?.size,
|
||||
name: recipeImage?.name,
|
||||
type: recipeImage?.type
|
||||
});
|
||||
|
||||
if (recipeImage && recipeImage.size > 0) {
|
||||
try {
|
||||
console.log('[RecipeAdd] Starting image processing...');
|
||||
// Process and save the image
|
||||
const { filename } = await processAndSaveRecipeImage(
|
||||
recipeImage,
|
||||
@@ -61,13 +75,14 @@ export const actions = {
|
||||
IMAGE_DIR
|
||||
);
|
||||
|
||||
console.log('[RecipeAdd] Image processed successfully, filename:', filename);
|
||||
recipeData.images = [{
|
||||
mediapath: filename,
|
||||
alt: '',
|
||||
caption: ''
|
||||
}];
|
||||
} catch (imageError: any) {
|
||||
console.error('Image processing error:', imageError);
|
||||
console.error('[RecipeAdd] Image processing error:', imageError);
|
||||
return fail(400, {
|
||||
error: `Failed to process image: ${imageError.message}`,
|
||||
errors: ['Image processing failed'],
|
||||
@@ -75,6 +90,7 @@ export const actions = {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log('[RecipeAdd] No image uploaded, using placeholder');
|
||||
// No image uploaded - use placeholder based on short_name
|
||||
recipeData.images = [{
|
||||
mediapath: `${recipeData.short_name}.webp`,
|
||||
|
||||
Reference in New Issue
Block a user