create new api for drawing random marks

This commit is contained in:
2026-02-24 13:08:31 +05:30
parent 65be794ea4
commit 572327b540

View File

@@ -42,19 +42,24 @@ const saveGameScore2 = async (req, res) => {
const result = await newGame.save(); const result = await newGame.save();
// Upload screenshot to S3 if provided // Upload screenshot to S3 if provided
if (screenShot) { if (screenShot) {
let base64Image = screenShot.split(";base64,").pop(); try {
const buffer = Buffer.from(base64Image, "base64"); let base64Image = screenShot.split(";base64,").pop();
const buffer = Buffer.from(base64Image, "base64");
const uploadParams = { const uploadParams = {
Bucket: process.env.S3_BUCKET_NAME, Bucket: process.env.S3_BUCKET_NAME,
Key: `images/${result._id}.png`, Key: `images/${result._id}.png`,
Body: buffer, Body: buffer,
ContentType: "image/png", ContentType: "image/png",
}; };
const s3Response = await s3.upload(uploadParams).promise(); const s3Response = await s3.upload(uploadParams).promise();
newGame.screenshotUrl = s3Response.Location; newGame.screenshotUrl = s3Response.Location;
await newGame.save(); await newGame.save();
} catch (uploadError) {
console.log("Screenshot upload failed, saving without screenshot:", uploadError.message);
// Continue without screenshot - the game data is still saved
}
} }
res.status(200).json({ res.status(200).json({