pull/10/head
parent
7dda27e86e
commit
c2ee394195
|
@ -5,9 +5,9 @@ const gameSchema = new mongoose.Schema({
|
||||||
userId: { type: String, required: true },
|
userId: { type: String, required: true },
|
||||||
gameID: { type: String, required: true },
|
gameID: { type: String, required: true },
|
||||||
gameTime: { type: String, required: false },
|
gameTime: { type: String, required: false },
|
||||||
score: { type: String},
|
score: { type: String },
|
||||||
gameStar: { type: Number},
|
gameStar: { type: Number },
|
||||||
screenshotUrl: { type: String }, // Store the S3 URL of the screenshot
|
screenshotUrl: { type: String },
|
||||||
});
|
}, { collection: "gameData" });
|
||||||
|
|
||||||
module.exports = mongoose.model("Game", gameSchema);
|
module.exports = mongoose.model("Game", gameSchema);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const AWS = require("aws-sdk");
|
const AWS = require("aws-sdk");
|
||||||
|
const mongoose = require("mongoose");
|
||||||
const Game = require("../../models/gameModel");
|
const Game = require("../../models/gameModel");
|
||||||
|
|
||||||
const s3 = new AWS.S3({
|
const s3 = new AWS.S3({
|
||||||
|
@ -7,12 +8,27 @@ const s3 = new AWS.S3({
|
||||||
region: process.env.AWS_REGION,
|
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 saveGameScore2 = async (req, res) => {
|
||||||
const { userId, gameName, gameID, gameTime, score, gameStar, screenShot } = req.body;
|
const { userId, gameName, gameID, gameTime, score, gameStar, screenShot } = req.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!gameName || !userId || !gameID) {
|
if (!gameName || !userId || !gameID) {
|
||||||
return res.status(400).json({ error: "Missing required fields" });
|
return res.status(400).json({ error: "Missing required fields" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const newGame = new Game({
|
const newGame = new Game({
|
||||||
gameName,
|
gameName,
|
||||||
userId,
|
userId,
|
||||||
|
@ -21,21 +37,26 @@ const saveGameScore2 = async (req, res) => {
|
||||||
score,
|
score,
|
||||||
gameStar,
|
gameStar,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Save to MongoDB
|
||||||
const result = await newGame.save();
|
const result = await newGame.save();
|
||||||
|
// Upload screenshot to S3 if provided
|
||||||
if (screenShot) {
|
if (screenShot) {
|
||||||
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 buffer = Buffer.from(screenShot, "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();
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({
|
res.status(200).json({
|
||||||
message: "Game data saved successfully",
|
message: "Game data saved successfully",
|
||||||
data: newGame,
|
data: newGame,
|
||||||
|
|
|
@ -31,7 +31,7 @@ const aiMarkDrawing = require("../api/aiMarkDrawing");
|
||||||
const aiFeedbackOnReportWithFollowup = require("../api/aiFeedbackOnReportWithFollowup");
|
const aiFeedbackOnReportWithFollowup = require("../api/aiFeedbackOnReportWithFollowup");
|
||||||
const aiTextToSpeech = require("../api/aiTextToSpeech");
|
const aiTextToSpeech = require("../api/aiTextToSpeech");
|
||||||
const aiEvaluateImageToStar = require("../api/aiEvaluateImageToStar");
|
const aiEvaluateImageToStar = require("../api/aiEvaluateImageToStar");
|
||||||
const getGameInfo = require("../api/getGameInfo");
|
// const getGameInfo = require("../api/getGameInfo");
|
||||||
const saveGalleryImage = require("../api/saveGalleryImage");
|
const saveGalleryImage = require("../api/saveGalleryImage");
|
||||||
const getGalleryImage = require("../api/getGalleryImage");
|
const getGalleryImage = require("../api/getGalleryImage");
|
||||||
|
|
||||||
|
@ -194,9 +194,9 @@ router.get("/ping", (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// getGameInfo.
|
// getGameInfo.
|
||||||
router.get("/getGameInfo", (req, res) => {
|
// // router.get("/getGameInfo", (req, res) => {
|
||||||
getGameInfo(req, res);
|
// // getGameInfo(req, res);
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Save Drawing Game Gallery Image
|
// Save Drawing Game Gallery Image
|
||||||
router.post("/saveGalleryImage", (req, res) => {
|
router.post("/saveGalleryImage", (req, res) => {
|
||||||
|
|
Loading…
Reference in New Issue