create new api for drawing random marks
This commit is contained in:
@@ -42,24 +42,19 @@ 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) {
|
||||||
try {
|
let base64Image = screenShot.split(";base64,").pop();
|
||||||
let base64Image = screenShot.split(";base64,").pop();
|
const buffer = Buffer.from(base64Image, "base64");
|
||||||
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({
|
||||||
|
|||||||
Reference in New Issue
Block a user