Compare commits
15 Commits
tmp
...
8f2f36bce0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f2f36bce0 | ||
|
|
d38702698a | ||
| 0296de1703 | |||
| 9384390811 | |||
| 92974caef1 | |||
| 956d0a72bd | |||
| c67378c3f4 | |||
| e34abbb017 | |||
| a4e9e9cfb3 | |||
| 4d9a785812 | |||
| f68b1e78e0 | |||
| 87afa13a42 | |||
|
|
4d251402af | ||
|
|
d96461aedb | ||
|
|
b7b168b2d0 |
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
yarn install
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
git status
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
yarn lint-staged
|
||||
22
game_links.txt
Normal file
22
game_links.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
/guided-tracing/A/
|
||||
|
||||
game_drawing /drawing/?id=
|
||||
game_drawing_v2 /drawing/v2/?id=
|
||||
game_drawing_v3 /drawing/v3/?id=
|
||||
drawing_phonics /drawing/drawing_phonics/?id=
|
||||
game_tick_variant1 /tick/v1/?id=
|
||||
game_tick_variant2 /tick/v2/?id=
|
||||
game_tick_varient3 /tick/v3/?id=
|
||||
game_cross_varient1 /cross/v1/?id=
|
||||
game_cross_varient2 /cross/v2/?id=
|
||||
game_cross_varient3 /cross/v3/?id=
|
||||
game_drag /drag/?id=
|
||||
game_drag_v2 /drag/v2/?id=
|
||||
game_drag_v3 /drag/v3/?id= // we do't use this version
|
||||
game_drag_v4 /drag/v4/?id=
|
||||
game_tick_v3_phonics /tick/tick_phonics_v1/?id=
|
||||
tick_phonics_option_6 /tick/tick_phonics_v2/?id=
|
||||
tick_phonics_option_9 /tick/tick_phonics_v3/?id=
|
||||
drag_drop_phonics /drag/dragdrop_phonics/?id=
|
||||
drag_phonics /drag/match_phonics/?id=
|
||||
cross_phonics_option_9 /cross/cross_phonics_v2/?id=
|
||||
43
package-lock.json
generated
43
package-lock.json
generated
@@ -25,6 +25,7 @@
|
||||
"http-status": "^1.4.0",
|
||||
"joi": "^17.3.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mariadb": "^3.4.0",
|
||||
"moment": "^2.24.0",
|
||||
"mongoose": "^8.7.1",
|
||||
"morgan": "^1.9.1",
|
||||
@@ -1731,6 +1732,12 @@
|
||||
"@babel/types": "^7.20.7"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/geojson": {
|
||||
"version": "7946.0.15",
|
||||
"resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.15.tgz",
|
||||
"integrity": "sha512-9oSxFzDCT2Rj6DfcHF8G++jxBKS7mBqXl5xrRW+Kbvjry6Uduya2iiwqHPhVXpasAVMBYKkEPGgKhd3+/HZ6xA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/graceful-fs": {
|
||||
"version": "4.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz",
|
||||
@@ -1785,7 +1792,6 @@
|
||||
"version": "22.10.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz",
|
||||
"integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.20.0"
|
||||
@@ -8412,6 +8418,40 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mariadb": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.4.0.tgz",
|
||||
"integrity": "sha512-hdRPcAzs+MTxK5VG1thBW18gGTlw6yWBe9YnLB65GLo7q0fO5DWsgomIevV/pXSaWRmD3qi6ka4oSFRTExRiEQ==",
|
||||
"license": "LGPL-2.1-or-later",
|
||||
"dependencies": {
|
||||
"@types/geojson": "^7946.0.14",
|
||||
"@types/node": "^22.5.4",
|
||||
"denque": "^2.1.0",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"lru-cache": "^10.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/mariadb/node_modules/iconv-lite": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
|
||||
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/mariadb/node_modules/lru-cache": {
|
||||
"version": "10.4.3",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
|
||||
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
@@ -13225,7 +13265,6 @@
|
||||
"version": "6.20.0",
|
||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
|
||||
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/union-value": {
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
"http-status": "^1.4.0",
|
||||
"joi": "^17.3.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mariadb": "^3.4.0",
|
||||
"moment": "^2.24.0",
|
||||
"mongoose": "^8.7.1",
|
||||
"morgan": "^1.9.1",
|
||||
|
||||
15
src/models/getGalleyImage.js
Normal file
15
src/models/getGalleyImage.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
// Define the GalleryImage schema
|
||||
const galleryImageSchema = new mongoose.Schema({
|
||||
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, // Assuming you have a User model
|
||||
gameName: { type: String, required: true },
|
||||
gameID: { type: String, required: true },
|
||||
screenshotUrl: { type: String, required: true },
|
||||
message: { type: String, default: 'Image received' },
|
||||
}, { timestamps: true });
|
||||
|
||||
// Check if the model already exists in mongoose.models
|
||||
const GalleryImage = mongoose.models.GalleryImage || mongoose.model('GalleryImage', galleryImageSchema);
|
||||
|
||||
module.exports = GalleryImage;
|
||||
10
src/models/imageGallery.js
Normal file
10
src/models/imageGallery.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const galleryImageScema = new mongoose.Schema({
|
||||
gameName: { type: String, required: true },
|
||||
userId: { type: String, required: true },
|
||||
gameID: { type: String, required: true },
|
||||
screenshotUrl: { type: String },
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("GalleryImage", galleryImageScema);
|
||||
@@ -1,7 +1,8 @@
|
||||
const AWS = require('aws-sdk');
|
||||
const axios = require('axios');
|
||||
const FormData = require('form-data');
|
||||
const mongoose = require('mongoose');
|
||||
const Game = require('../../models/gameModel'); // Ensure this path matches your project structure
|
||||
const Game = require('../../models/gameModel');
|
||||
|
||||
const aiEvaluateImageToStar = async (req, res) => {
|
||||
try {
|
||||
@@ -32,7 +33,7 @@ const aiEvaluateImageToStar = async (req, res) => {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'The coloring was done by a 5-year-old kid. Give a score between 1 to 10 in JSON format.',
|
||||
text: 'The coloring was done by a 5-year-old kid. Give a score between 3 to 5 in JSON format.',
|
||||
},
|
||||
{
|
||||
type: 'image_url',
|
||||
@@ -46,7 +47,7 @@ const aiEvaluateImageToStar = async (req, res) => {
|
||||
max_tokens: 300,
|
||||
};
|
||||
|
||||
console.log('AAAAAA')
|
||||
// console.log('AAAAAA')
|
||||
const openAiResponse = await axios.post(
|
||||
'https://api.openai.com/v1/chat/completions',
|
||||
openAiPayload,
|
||||
@@ -57,20 +58,18 @@ const aiEvaluateImageToStar = async (req, res) => {
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// Extract the score from OpenAI's response
|
||||
const scoreResponse = openAiResponse.data.choices[0].message.content;
|
||||
const parsedScore = JSON.parse(scoreResponse);
|
||||
|
||||
console.log(openAiResponse)
|
||||
const rResp=openAiResponse.data.choices[0].message;
|
||||
const cleanContent = rResp.content.replace(/```json|```/g, '').trim();
|
||||
const parsedScore = JSON.parse(cleanContent);
|
||||
// console.log(parsedScore); // { score: 8 }
|
||||
const gameData = new Game({
|
||||
gameName,
|
||||
userId,
|
||||
gameID,
|
||||
gameTime,
|
||||
score: parsedScore.score || 'N/A', // Adjust key to match OpenAI response
|
||||
score: parsedScore.score || 'N/A',
|
||||
gameStar,
|
||||
screenshotUrl,
|
||||
screenshotUrl:screenshotUrl.data.filePath,
|
||||
});
|
||||
|
||||
await gameData.save();
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
const aiFeedbackOnReport = async (req, res) => {
|
||||
// const fetch = require('node-fetch');
|
||||
const fetch = require('node-fetch');
|
||||
const url = process.env.AI_API_ENDOINT;
|
||||
const api_key = process.env.AI_API_KEY;
|
||||
const api_key = process.env.OPENAI_KEY;
|
||||
const payload = {
|
||||
"model": "gpt-4o-mini",
|
||||
"messages": [{ "role": "user",
|
||||
"content": JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction }]
|
||||
"messages": [{ "role": "user", "content": JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction }]
|
||||
}
|
||||
try {
|
||||
const apiResponse = await fetch(url, {
|
||||
|
||||
@@ -11,7 +11,7 @@ const aiFollowupQuestion = async (req, res) => {
|
||||
const database = client.db(dbName); // Replace with your database name
|
||||
const conversationsCollection = database.collection('conversations'); // Replace with your collection name
|
||||
|
||||
async function fetchOpenAICompletion(prompt, messages, model = "gpt-3.5-turbo-16k", max_tokens = 200) {
|
||||
async function fetchOpenAICompletion(prompt, messages, model = "gpt-3.5-turbo-16k", max_tokens = 600) {
|
||||
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -26,12 +26,13 @@ const aiFollowupQuestion = async (req, res) => {
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
return data.choices[0].message.content;
|
||||
return data;
|
||||
// return data.choices[0].message.content;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const { prompt, sessionId, model = "gpt-4o-mini", max_tokens = 200 } = req.body;
|
||||
const { prompt, sessionId, model = "gpt-4o-mini", max_tokens = 600 } = req.body;
|
||||
if (!conversationsCollection) {
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
@@ -48,9 +49,10 @@ const aiFollowupQuestion = async (req, res) => {
|
||||
conversationHistory: [
|
||||
{ role: 'system', content: 'You are a helpful assistant.' },
|
||||
// { role: 'user', content: prompt },
|
||||
{ role: 'user', content: req.body.score + " - is the students report card. " + req.body.instruction },
|
||||
{ role: 'user', content: JSON.stringify(req.body.score) + " - is the students report card. " + req.body.instruction },
|
||||
],
|
||||
};
|
||||
// console.log(req.body.score[0])
|
||||
await conversationsCollection.insertOne(conversation);
|
||||
} else {
|
||||
conversation = await conversationsCollection.findOne({ sessionId: sessionId });
|
||||
|
||||
@@ -21,11 +21,17 @@ const aiFollowupQuestion = async (req, res) => {
|
||||
body: JSON.stringify({
|
||||
model: model,
|
||||
messages: messages,
|
||||
// messages: [
|
||||
// { role: "system", content: "reply must not exceed 20 words" },
|
||||
// { role: "user", content: messages }
|
||||
// ],
|
||||
max_tokens: max_tokens,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
console.log(process.env.OPENAI_KEY)
|
||||
console.log(data)
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -46,7 +52,7 @@ const aiFollowupQuestion = async (req, res) => {
|
||||
conversation = {
|
||||
sessionId: newSessionId,
|
||||
conversationHistory: [
|
||||
{ role: 'system', content: 'answer within 50 words' },
|
||||
{ role: 'system', content: 'answer within 10 words' },
|
||||
{ role: 'user', content: prompt },
|
||||
],
|
||||
};
|
||||
|
||||
36
src/routes/api/getGalleryImage.js
Normal file
36
src/routes/api/getGalleryImage.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const GalleryImage = require('../../models/getGalleyImage');
|
||||
|
||||
const getGalleryImage = async (req, res) => {
|
||||
try {
|
||||
// Extract query parameters for filtering (if provided)
|
||||
const { gameName, userId, gameID} = req.query;
|
||||
|
||||
// Build a filter object based on the query parameters
|
||||
const filter = {};
|
||||
|
||||
if (gameName) {
|
||||
filter.gameName = gameName;
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
filter.userId = userId;
|
||||
}
|
||||
if (gameID) {
|
||||
filter.gameID = gameID;
|
||||
}
|
||||
|
||||
// Fetch gallery images with filters and selected fields
|
||||
const galleryImages = await GalleryImage.find(filter).select('gameName userId gameID screenshotUrl'); // Select only these fields
|
||||
|
||||
if (!galleryImages.length) {
|
||||
return res.status(404).json({ message: 'No images found' });
|
||||
}
|
||||
|
||||
return res.status(200).json(galleryImages); // Return the filtered gallery images with selected fields
|
||||
} catch (error) {
|
||||
console.error('Error fetching images:', error.message);
|
||||
return res.status(500).json({ error: 'Something went wrong' });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = getGalleryImage;
|
||||
136
src/routes/api/getGameInfo.js
Normal file
136
src/routes/api/getGameInfo.js
Normal file
@@ -0,0 +1,136 @@
|
||||
const mariadb = require('mariadb');
|
||||
|
||||
const gameInfo = async (req, res) => {
|
||||
|
||||
// Create a connection pool
|
||||
const pool = mariadb.createPool({
|
||||
host: process.env.MARIA_HOST,
|
||||
user: process.env.MARIA_USER,
|
||||
password: process.env.MARIA_PASS,
|
||||
database: process.env.MARIA_DBNM,
|
||||
connectionLimit: 5,
|
||||
});
|
||||
|
||||
const { schoolId, teacherId } = req.query;
|
||||
|
||||
if (!schoolId && !teacherId) {
|
||||
return res.status(400).send({ error: 'Either schoolId or teacherId is required in the query parameters.' });
|
||||
}
|
||||
|
||||
let connection;
|
||||
try {
|
||||
// Establish a connection to the database
|
||||
connection = await pool.getConnection();
|
||||
|
||||
let queryCondition;
|
||||
let queryValue;
|
||||
|
||||
// Determine the query condition based on the parameters provided
|
||||
if (schoolId) {
|
||||
queryCondition = 'schoolId = ?';
|
||||
queryValue = schoolId;
|
||||
} else {
|
||||
queryCondition = 'teacherId = ?';
|
||||
queryValue = teacherId;
|
||||
}
|
||||
|
||||
// Query both game1 and game2 tables
|
||||
const query1 = `SELECT * FROM game_drawing WHERE ${queryCondition}`;
|
||||
const query2 = `SELECT * FROM game_drawing_v2 WHERE ${queryCondition}`;
|
||||
const query3 = `SELECT * FROM game_drawing_v3 WHERE ${queryCondition}`;
|
||||
const query4 = `SELECT * FROM drawing_phonics WHERE ${queryCondition}`;
|
||||
const query5 = `SELECT * FROM game_tick_variant1 WHERE ${queryCondition}`;
|
||||
const query6 = `SELECT * FROM game_tick_variant2 WHERE ${queryCondition}`;
|
||||
const query7 = `SELECT * FROM game_tick_varient3 WHERE ${queryCondition}`;
|
||||
const query8 = `SELECT * FROM game_cross_varient1 WHERE ${queryCondition}`;
|
||||
const query9 = `SELECT * FROM game_cross_varient2 WHERE ${queryCondition}`;
|
||||
const query10 = `SELECT * FROM game_cross_varient3 WHERE ${queryCondition}`;
|
||||
const query11 = `SELECT * FROM game_drag WHERE ${queryCondition}`;
|
||||
const query12 = `SELECT * FROM game_drag_v2 WHERE ${queryCondition}`;
|
||||
const query13 = `SELECT * FROM game_drag_v4 WHERE ${queryCondition}`;
|
||||
const query14 = `SELECT * FROM game_tick_v3_phonics WHERE ${queryCondition}`;
|
||||
const query15 = `SELECT * FROM tick_phonics_option_6 WHERE ${queryCondition}`;
|
||||
const query16 = `SELECT * FROM tick_phonics_option_9 WHERE ${queryCondition}`;
|
||||
const query17 = `SELECT * FROM drag_drop_phonics WHERE ${queryCondition}`;
|
||||
const query18 = `SELECT * FROM drag_phonics WHERE ${queryCondition}`;
|
||||
const query19 = `SELECT * FROM cross_phonics_option_9 WHERE ${queryCondition}`;
|
||||
|
||||
const [game_drawing, game_drawing_v2, game_drawing_v3, drawing_phonics, game_tick_variant1, game_tick_variant2, game_tick_varient3, game_cross_varient1, game_cross_varient2, game_cross_varient3, game_drag, game_drag_v2, game_drag_v4, game_tick_v3_phonics, tick_phonics_option_6, tick_phonics_option_9, drag_drop_phonics, drag_phonics, cross_phonics_option_9 ] = await Promise.all([
|
||||
connection.query(query1, [queryValue]),
|
||||
connection.query(query2, [queryValue]),
|
||||
connection.query(query3, [queryValue]),
|
||||
connection.query(query4, [queryValue]),
|
||||
connection.query(query5, [queryValue]),
|
||||
connection.query(query6, [queryValue]),
|
||||
connection.query(query7, [queryValue]),
|
||||
connection.query(query8, [queryValue]),
|
||||
connection.query(query9, [queryValue]),
|
||||
connection.query(query10, [queryValue]),
|
||||
connection.query(query11, [queryValue]),
|
||||
connection.query(query12, [queryValue]),
|
||||
connection.query(query13, [queryValue]),
|
||||
connection.query(query14, [queryValue]),
|
||||
connection.query(query15, [queryValue]),
|
||||
connection.query(query16, [queryValue]),
|
||||
connection.query(query17, [queryValue]),
|
||||
connection.query(query18, [queryValue]),
|
||||
connection.query(query19, [queryValue])
|
||||
]);
|
||||
|
||||
// const domain = 'https://domain.com/gamelink/?id=';
|
||||
const domain = process.env.GAME_DOMAIN;
|
||||
|
||||
const formattedGame1 = game_drawing.map(game => ({ ...game, game_id: `game_drawing-${game.id}`, game_link: `${domain}/drawing/?id=${game.id}`, }));
|
||||
const formattedGame2 = game_drawing_v2.map(({ status, ...game }) => ({ ...game, game_id: `game_drawing_v2-${game.id}`, game_link: `${domain}/drawing/v2/?id=${game.id}`, }));
|
||||
const formattedGame3 = game_drawing_v3.map(({ status, ...game }) => ({ ...game, game_id: `game_drawing_v3-${game.id}`, game_link: `${domain}/drawing/v3/?id=${game.id}`, }));
|
||||
const formattedGame4 = drawing_phonics.map(({ status, ...game }) => ({ ...game, game_id: `drawing_phonics-${game.id}`, game_link: `${domain}/drawing/drawing_phonics/?id=${game.id}`, }));
|
||||
const formattedGame5 = game_tick_variant1.map(({ status, ...game }) => ({ ...game, game_id: `game_tick_variant1-${game.id}`, game_link: `${domain}/tick/v1/?id=${game.id}`, }));
|
||||
const formattedGame6 = game_tick_variant2.map(({ status, ...game }) => ({ ...game, game_id: `game_tick_variant2-${game.id}`, game_link: `${domain}/tick/v2/?id=${game.id}`, }));
|
||||
const formattedGame7 = game_tick_varient3.map(({ status, ...game }) => ({ ...game, game_id: `game_tick_varient3-${game.id}`, game_link: `${domain}/tick/v3/?id=${game.id}`, }));
|
||||
const formattedGame8 = game_cross_varient1.map(({ status, ...game }) => ({ ...game, game_id: `game_cross_varient1-${game.id}`, game_link: `${domain}/cross/v1/?id=${game.id}`, }));
|
||||
const formattedGame9 = game_cross_varient2.map(({ status, ...game }) => ({ ...game, game_id: `game_cross_varient2-${game.id}`, game_link: `${domain}/cross/v2/?id=${game.id}`, }));
|
||||
const formattedGame10 = game_cross_varient3.map(({ status, ...game }) => ({ ...game, game_id: `game_cross_varient3-${game.id}`, game_link: `${domain}/cross/v3/?id=${game.id}`, }));
|
||||
const formattedGame11 = game_drag.map(({ status, ...game }) => ({ ...game, game_id: `game_drag-${game.id}`, game_link: `${domain}/drag/?id=${game.id}`, }));
|
||||
const formattedGame12 = game_drag_v2.map(({ status, ...game }) => ({ ...game, game_id: `game_drag_v2-${game.id}`, game_link: `${domain}/drag/v2/?id=${game.id}`, }));
|
||||
const formattedGame13 = game_drag_v4.map(({ status, ...game }) => ({ ...game, game_id: `game_drag_v4-${game.id}`, game_link: `${domain}/drag/v4/?id=${game.id}`, }));
|
||||
const formattedGame14 = game_tick_v3_phonics.map(({ status, ...game }) => ({ ...game, game_id: `game_tick_v3_phonics-${game.id}`, game_link: `${domain}/tick/tick_phonics_v1/?id=${game.id}`, }));
|
||||
const formattedGame15 = tick_phonics_option_6.map(({ status, ...game }) => ({ ...game, game_id: `tick_phonics_option_6-${game.id}`, game_link: `${domain}/tick/tick_phonics_v2/?id=${game.id}`, }));
|
||||
const formattedGame16 = tick_phonics_option_9.map(({ status, ...game }) => ({ ...game, game_id: `tick_phonics_option_9-${game.id}`, game_link: `${domain}/tick/tick_phonics_v3/?id=${game.id}`, }));
|
||||
const formattedGame17 = drag_drop_phonics.map(({ status, ...game }) => ({ ...game, game_id: `drag_drop_phonics-${game.id}`, game_link: `${domain}/drag/dragdrop_phonics/?id=${game.id}`, }));
|
||||
const formattedGame18 = drag_phonics.map(({ status, ...game }) => ({ ...game, game_id: `drag_phonics-${game.id}`, game_link: `${domain}/drag/match_phonics/?id=${game.id}`, }));
|
||||
const formattedGame19 = cross_phonics_option_9.map(({ status, ...game }) => ({ ...game, game_id: `cross_phonics_option_9-${game.id}`, game_link: `${domain}/cross/cross_phonics_v2/?id=${game.id}`, }));
|
||||
|
||||
|
||||
const combinedResults = {
|
||||
game_drawing: formattedGame1,
|
||||
game_drawing_v2: formattedGame2,
|
||||
game_drawing_v3: formattedGame3,
|
||||
drawing_phonics: formattedGame4,
|
||||
game_tick_variant1: formattedGame5,
|
||||
game_tick_variant2: formattedGame6,
|
||||
game_tick_varient3: formattedGame7,
|
||||
game_cross_varient1: formattedGame8,
|
||||
game_cross_varient2: formattedGame9,
|
||||
game_cross_varient3: formattedGame10,
|
||||
game_drag: formattedGame11,
|
||||
game_drag_v2: formattedGame12,
|
||||
game_drag_v4: formattedGame13,
|
||||
game_tick_v3_phonics: formattedGame14,
|
||||
tick_phonics_option_6: formattedGame15,
|
||||
tick_phonics_option_9: formattedGame16,
|
||||
drag_drop_phonics: formattedGame17,
|
||||
drag_phonics: formattedGame18,
|
||||
cross_phonics_option_9: formattedGame19
|
||||
};
|
||||
|
||||
res.status(200).send(combinedResults);
|
||||
} catch (error) {
|
||||
console.error('Error querying game tables:', error);
|
||||
res.status(500).send({ error: 'An error occurred while fetching game data.' });
|
||||
} finally {
|
||||
// Release the connection back to the pool
|
||||
if (connection) connection.release();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = gameInfo;
|
||||
78
src/routes/api/saveGalleryImage.js
Normal file
78
src/routes/api/saveGalleryImage.js
Normal file
@@ -0,0 +1,78 @@
|
||||
const GalleryImage = require('../../models/imageGallery');
|
||||
const axios = require('axios');
|
||||
const FormData = require('form-data'); // Import form-data for Node.js
|
||||
|
||||
const saveGalleryImage = async (req, res) => {
|
||||
try {
|
||||
const { userId, gameName, gameID, screenShot } = req.body;
|
||||
|
||||
// Validate base64 format
|
||||
const isValidBase64 = validateBase64(screenShot);
|
||||
if (!isValidBase64) {
|
||||
return res.status(400).json({ error: 'Invalid base64 image data' });
|
||||
}
|
||||
|
||||
// Extract image details
|
||||
const imageData = extractImageDataFromBase64(screenShot);
|
||||
const contentType = imageData.contentType || 'image/jpeg'; // Default to JPEG
|
||||
|
||||
// Convert base64 to buffer
|
||||
const buffer = Buffer.from(screenShot.replace(/^data:image\/(png|jpg|jpeg);base64,/, ''), 'base64');
|
||||
|
||||
// Create FormData
|
||||
const formData = new FormData();
|
||||
formData.append('file1', buffer, { filename: 'screenshot.jpg', contentType });
|
||||
formData.append('folder', 'gameGallery');
|
||||
formData.append('bucket', 'polly-bs');
|
||||
|
||||
// Upload image to external API using axios
|
||||
const uploadResponse = await axios.post(
|
||||
'https://preschool-curriculum.in/api/one/v1/file/upload',
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
...formData.getHeaders(), // Add form-data headers like Content-Type boundary
|
||||
// Add any necessary authentication headers if required
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (uploadResponse.status !== 200) {
|
||||
throw new Error('Image upload failed: ' + uploadResponse.statusText);
|
||||
}
|
||||
|
||||
// Extract and store the uploaded image URL from the response
|
||||
const screenshotUrl = uploadResponse.data.urls[0];
|
||||
|
||||
// Create and save gallery image data
|
||||
const galleryImageData = new GalleryImage({
|
||||
userId,
|
||||
gameName,
|
||||
gameID,
|
||||
screenshotUrl,
|
||||
message: 'Image received',
|
||||
});
|
||||
await galleryImageData.save();
|
||||
|
||||
return res.status(200).json(galleryImageData);
|
||||
} catch (error) {
|
||||
console.error('Error:', error.message);
|
||||
return res.status(500).json({ error: 'Something went wrong' });
|
||||
}
|
||||
};
|
||||
|
||||
// Validate base64 image
|
||||
function validateBase64(base64String) {
|
||||
const regex = /^data:image\/(png|jpg|jpeg);base64,/;
|
||||
return regex.test(base64String);
|
||||
}
|
||||
|
||||
// Extract image data (like content type) from base64 string
|
||||
function extractImageDataFromBase64(base64String) {
|
||||
const matches = base64String.match(/^data:image\/(png|jpg|jpeg);base64,/);
|
||||
return {
|
||||
contentType: matches ? `image/${matches[1]}` : 'image/jpeg',
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = saveGalleryImage;
|
||||
@@ -31,7 +31,9 @@ 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 saveGalleryImage = require("../api/saveGalleryImage");
|
||||
const getGalleryImage = require("../api/getGalleryImage");
|
||||
|
||||
|
||||
const router = express.Router();
|
||||
@@ -190,8 +192,21 @@ router.get("/ping", (req, res) => {
|
||||
router.post("/aiEvaluateImageToStar", (req, res) => {
|
||||
aiEvaluateImageToStar(req, res);
|
||||
});
|
||||
|
||||
|
||||
// getGameInfo.
|
||||
router.get("/getGameInfo", (req, res) => {
|
||||
getGameInfo(req, res);
|
||||
});
|
||||
|
||||
// Save Drawing Game Gallery Image
|
||||
router.post("/saveGalleryImage", (req, res) => {
|
||||
saveGalleryImage(req, res);
|
||||
});
|
||||
|
||||
// Get Drawing Game Gallery Image
|
||||
router.get("/getGalleryImage", (req, res) => {
|
||||
getGalleryImage(req, res);
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user