pull/10/head
parent
7dda27e86e
commit
c2ee394195
|
@ -5,9 +5,9 @@ const gameSchema = new mongoose.Schema({
|
|||
userId: { type: String, required: true },
|
||||
gameID: { type: String, required: true },
|
||||
gameTime: { type: String, required: false },
|
||||
score: { type: String},
|
||||
gameStar: { type: Number},
|
||||
screenshotUrl: { type: String }, // Store the S3 URL of the screenshot
|
||||
});
|
||||
score: { type: String },
|
||||
gameStar: { type: Number },
|
||||
screenshotUrl: { type: String },
|
||||
}, { collection: "gameData" });
|
||||
|
||||
module.exports = mongoose.model("Game", gameSchema);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const AWS = require("aws-sdk");
|
||||
const mongoose = require("mongoose");
|
||||
const Game = require("../../models/gameModel");
|
||||
|
||||
const s3 = new AWS.S3({
|
||||
|
@ -7,12 +8,27 @@ const s3 = new AWS.S3({
|
|||
region: process.env.AWS_REGION,
|
||||
});
|
||||
|
||||
// MongoDB Connection
|
||||
const mongoURI = process.env.MONGODB_URL;
|
||||
const dbName = process.env.MONGO_DB_NAME;
|
||||
|
||||
mongoose.connect(mongoURI, {
|
||||
dbName: dbName,
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
})
|
||||
.then(() =>
|
||||
console.log("Connected to MongoDB"))
|
||||
.catch((err) => console.error("MongoDB connection error:", err));
|
||||
|
||||
const saveGameScore2 = async (req, res) => {
|
||||
const { userId, gameName, gameID, gameTime, score, gameStar, screenShot } = req.body;
|
||||
|
||||
try {
|
||||
if (!gameName || !userId || !gameID) {
|
||||
return res.status(400).json({ error: "Missing required fields" });
|
||||
}
|
||||
|
||||
const newGame = new Game({
|
||||
gameName,
|
||||
userId,
|
||||
|
@ -21,21 +37,26 @@ const saveGameScore2 = async (req, res) => {
|
|||
score,
|
||||
gameStar,
|
||||
});
|
||||
|
||||
// Save to MongoDB
|
||||
const result = await newGame.save();
|
||||
// Upload screenshot to S3 if provided
|
||||
if (screenShot) {
|
||||
let base64Image = screenShot.split(";base64,").pop();
|
||||
const buffer = Buffer.from(base64Image, 'base64');
|
||||
// const buffer = Buffer.from(screenShot, "base64");
|
||||
let base64Image = screenShot.split(";base64,").pop();
|
||||
const buffer = Buffer.from(base64Image, "base64");
|
||||
|
||||
const uploadParams = {
|
||||
Bucket: process.env.S3_BUCKET_NAME,
|
||||
Key: `images/${result._id}.png`,
|
||||
Body: buffer,
|
||||
ContentType: "image/png",
|
||||
};
|
||||
|
||||
const s3Response = await s3.upload(uploadParams).promise();
|
||||
newGame.screenshotUrl = s3Response.Location;
|
||||
await newGame.save();
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
message: "Game data saved successfully",
|
||||
data: newGame,
|
||||
|
|
|
@ -31,7 +31,7 @@ const aiMarkDrawing = require("../api/aiMarkDrawing");
|
|||
const aiFeedbackOnReportWithFollowup = require("../api/aiFeedbackOnReportWithFollowup");
|
||||
const aiTextToSpeech = require("../api/aiTextToSpeech");
|
||||
const aiEvaluateImageToStar = require("../api/aiEvaluateImageToStar");
|
||||
const getGameInfo = require("../api/getGameInfo");
|
||||
// const getGameInfo = require("../api/getGameInfo");
|
||||
const saveGalleryImage = require("../api/saveGalleryImage");
|
||||
const getGalleryImage = require("../api/getGalleryImage");
|
||||
|
||||
|
@ -194,9 +194,9 @@ router.get("/ping", (req, res) => {
|
|||
});
|
||||
|
||||
// getGameInfo.
|
||||
router.get("/getGameInfo", (req, res) => {
|
||||
getGameInfo(req, res);
|
||||
});
|
||||
// // router.get("/getGameInfo", (req, res) => {
|
||||
// // getGameInfo(req, res);
|
||||
// });
|
||||
|
||||
// Save Drawing Game Gallery Image
|
||||
router.post("/saveGalleryImage", (req, res) => {
|
||||
|
|
Loading…
Reference in New Issue