ewr

32function doPost(e) { try { // Log the incoming request Logger.log('Received POST request'); // Parse the request data let data; try { data = JSON.parse(e.postData.contents); Logger.log('Successfully parsed JSON data'); } catch (parseError) { Logger.log('Error parsing JSON: ' + parseError.toString()); throw new Error('Invalid JSON data'); } // Validate required fields if (!data.title || !data.content) { throw new Error('Missing required fields'); } const emailAddress = "ncslite9.damncrazy1@blogger.com"; const subject = data.title; const content = data.content; // Prepare email options let options = { htmlBody: content }; // Handle image if present if (data.image && data.image.startsWith('data:image')) { Logger.log('Processing image data'); try { // Extract image data const matches = data.image.match(/^data:([^;]+);base64,(.+)$/); if (matches && matches.length === 3) { const mimeType = matches[1]; const base64Data = matches[2]; const imageBlob = Utilities.newBlob( Utilities.base64Decode(base64Data), mimeType, 'image.' + mimeType.split('/')[1] ); options.attachments = [imageBlob]; Logger.log('Successfully processed image'); } else { Logger.log('Invalid image data format'); } } catch (imageError) { Logger.log('Error processing image: ' + imageError.toString()); // Continue without image if there's an error } } // Send email GmailApp.sendEmail(emailAddress, subject, content, options); Logger.log('Email sent successfully'); // Return success response return ContentService.createTextOutput( JSON.stringify({ success: true, message: 'Post created successfully' }) ).setMimeType(ContentService.MimeType.JSON);

} catch (error) { // Log and return any errors Logger.log('Error in doPost: ' + error.toString());

return ContentService.createTextOutput( JSON.stringify({ success: false, error: error.toString() }) ).setMimeType(ContentService.MimeType.JSON);

} } function doGet(e) { return ContentService.createTextOutput( JSON.stringify({ success: true, message: 'Service is running' }) ).setMimeType(ContentService.MimeType.JSON); }