Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e741897c5 | |||
| 37316ff794 | |||
| f6835d9417 | |||
| 3cba906217 | |||
| 9f3f904a3a | |||
| 0038ee1b25 | |||
| b9d2e682c5 | |||
| ec27c1b366 | |||
| d3212fadbc | |||
| 9b9f841b12 | |||
|
|
e12308e8bb | ||
|
|
cdee582951 | ||
|
|
dc6194f7e7 | ||
|
|
6d380c6cbb | ||
|
|
8e0cce2465 | ||
|
|
0735a91450 | ||
|
|
1576fa92c1 | ||
|
|
319bc33d4a | ||
|
|
b7da294a17 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
|||||||
# Dependencies
|
# Dependencies
|
||||||
node_modules
|
node_modules
|
||||||
bs_gamedu_backup.sql
|
|
||||||
# yarn error logs
|
# yarn error logs
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
|||||||
199320
bs_gamedu_backup.sql
199320
bs_gamedu_backup.sql
File diff suppressed because one or more lines are too long
612
package-lock.json
generated
612
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -48,18 +48,19 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"aws-sdk": "^2.1669.0",
|
"aws-sdk": "^2.1669.0",
|
||||||
"axios": "^1.7.7",
|
"axios": "^1.8.2",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cross-env": "^7.0.0",
|
"cross-env": "^7.0.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.21.2",
|
||||||
"express-mongo-sanitize": "^2.0.0",
|
"express-mongo-sanitize": "^2.0.0",
|
||||||
"express-rate-limit": "^5.0.0",
|
"express-rate-limit": "^5.0.0",
|
||||||
"form-data": "^4.0.1",
|
"form-data": "^4.0.2",
|
||||||
"formdata-node": "^6.0.3",
|
"formdata-node": "^6.0.3",
|
||||||
|
"fs": "^0.0.1-security",
|
||||||
"helmet": "^4.1.0",
|
"helmet": "^4.1.0",
|
||||||
"http-status": "^1.4.0",
|
"http-status": "^1.4.0",
|
||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
@@ -75,7 +76,9 @@
|
|||||||
"npm": "^11.0.0",
|
"npm": "^11.0.0",
|
||||||
"passport": "^0.4.0",
|
"passport": "^0.4.0",
|
||||||
"passport-jwt": "^4.0.0",
|
"passport-jwt": "^4.0.0",
|
||||||
|
"path": "^0.12.7",
|
||||||
"pm2": "^5.1.0",
|
"pm2": "^5.1.0",
|
||||||
|
"puppeteer": "^24.4.0",
|
||||||
"swagger-jsdoc": "^6.0.8",
|
"swagger-jsdoc": "^6.0.8",
|
||||||
"swagger-ui-express": "^4.1.6",
|
"swagger-ui-express": "^4.1.6",
|
||||||
"validator": "^13.0.0",
|
"validator": "^13.0.0",
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ app.use(mongoSanitize());
|
|||||||
app.use(compression());
|
app.use(compression());
|
||||||
|
|
||||||
// enable cors
|
// enable cors
|
||||||
// app.use(cors());
|
app.use(cors());
|
||||||
// app.options('*', cors());
|
app.options('*', cors());
|
||||||
|
|
||||||
//# Need to implement
|
//# Need to implement
|
||||||
// const allowedOrigins = process.env.CORS_ALLOWED_ORIGINS.split(',');
|
// const allowedOrigins = process.env.CORS_ALLOWED_ORIGINS.split(',');
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const aiFollowupQuestion = async (req, res) => {
|
|||||||
conversation = {
|
conversation = {
|
||||||
sessionId: newSessionId,
|
sessionId: newSessionId,
|
||||||
conversationHistory: [
|
conversationHistory: [
|
||||||
{ role: 'system', content: 'Reply to the questions asked by a kindergarten child, Sound excited to answer and encourage the child to ask more questions in 30 words' },
|
{ role: 'system', content: 'answer within 10 words' },
|
||||||
{ role: 'user', content: prompt },
|
{ role: 'user', content: prompt },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
const AWS = require('aws-sdk');
|
|
||||||
const axios = require('axios');
|
|
||||||
const mongoose = require('mongoose');
|
|
||||||
const FormData = require('form-data');
|
|
||||||
const Game = require('../../models/gameModel');
|
|
||||||
const aiEvaluateImageToStar = async (req, res) => {
|
|
||||||
try {
|
|
||||||
const { childId, gameName, gameID, gameTime, gameStar, screenShot } = req.body;
|
|
||||||
if (!screenShot) {
|
|
||||||
return res.status(400).json({ error: 'Screenshot is required' });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upload screenshot
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('image', screenShot);
|
|
||||||
|
|
||||||
const screenshotUploadResponse = await axios.post('https://teachertrainingchennai.in/api/uploadBase64/', formData, {
|
|
||||||
headers: {
|
|
||||||
...formData.getHeaders(),
|
|
||||||
},
|
|
||||||
httpsAgent: new (require('https').Agent)({
|
|
||||||
rejectUnauthorized: false
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
const screenshotUrl = screenshotUploadResponse.data.filePath;
|
|
||||||
|
|
||||||
// Generate random score between 1 to 10
|
|
||||||
const randomScore = Math.floor(Math.random() * 10) + 1; // 1-10 range
|
|
||||||
|
|
||||||
const gameData = new Game({
|
|
||||||
gameName,
|
|
||||||
childId,
|
|
||||||
gameID,
|
|
||||||
gameTime,
|
|
||||||
gameStar: randomScore,
|
|
||||||
screenshotUrl,
|
|
||||||
});
|
|
||||||
|
|
||||||
await gameData.save();
|
|
||||||
|
|
||||||
return res.status(200).json({
|
|
||||||
message: 'Game data saved successfully',
|
|
||||||
gameStar: randomScore,
|
|
||||||
screenshotUrl: screenshotUrl,
|
|
||||||
data: gameData,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error:', error.message);
|
|
||||||
return res.status(500).json({ error: error.message || 'Something went wrong' });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = aiEvaluateImageToStar;
|
|
||||||
99
src/routes/api/takeSnap.js
Normal file
99
src/routes/api/takeSnap.js
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
const { execSync } = require("child_process");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
const gameIds = [
|
||||||
|
'1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
|
||||||
|
'11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
|
||||||
|
'21', '22', '23', '24', '25', '26', '27', '28', '29', '30',
|
||||||
|
'31', '32', '33', '34', '35', '36', '37', '38', '39', '40',
|
||||||
|
'41', '42', '43', '44', '45', '46', '47', '48', '49', '50',
|
||||||
|
'51', '52', '53', '54', '55', '56', '57', '58', '59', '60',
|
||||||
|
'61', '62', '63', '64', '65', '66', '67', '68', '69', '70',
|
||||||
|
'71', '72', '73', '74', '75', '76', '77', '78', '79', '80',
|
||||||
|
'81', '82', '83', '84', '85', '86', '87', '88', '89', '90',
|
||||||
|
'91', '92', '93', '94', '95', '96', '97', '98', '99', '100',
|
||||||
|
'101', '102', '103', '104', '105', '114'
|
||||||
|
];
|
||||||
|
|
||||||
|
const SCREENSHOT_FOLDER = path.join(__dirname, "game-screen/drawing");
|
||||||
|
if (!fs.existsSync(SCREENSHOT_FOLDER)) {
|
||||||
|
fs.mkdirSync(SCREENSHOT_FOLDER, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
const DIRECTUS_API_URL = "https://game-du.teachertrainingkolkata.in/files";
|
||||||
|
|
||||||
|
async function takeSnap(req, res) {
|
||||||
|
for (const id of gameIds) {
|
||||||
|
try {
|
||||||
|
const url = `https://interaktogames.beanstalkedu.com/tick/v1?id=${id}`;
|
||||||
|
console.log(`📸 Taking screenshot for Game ID: ${id}`);
|
||||||
|
const command = `url2jpg ${url}`;
|
||||||
|
execSync(command, { stdio: "inherit", shell: true });
|
||||||
|
const files = fs.readdirSync(process.cwd()).filter(f => f.endsWith(".jpg"));
|
||||||
|
if (files.length === 0) throw new Error("No screenshot found!");
|
||||||
|
|
||||||
|
const latestFile = files.reduce((a, b) =>
|
||||||
|
fs.statSync(b).mtimeMs > fs.statSync(a).mtimeMs ? b : a
|
||||||
|
);
|
||||||
|
const newPath = path.join(SCREENSHOT_FOLDER, `${id}.jpg`);
|
||||||
|
fs.renameSync(latestFile, newPath);
|
||||||
|
console.log(`✅ Screenshot saved: ${newPath}`);
|
||||||
|
const fileId = await uploadToDirectus(newPath);
|
||||||
|
if (fileId) {
|
||||||
|
console.log(`📤 Uploaded to Directus. File ID: ${fileId}`);
|
||||||
|
await updateThumbnail(id, fileId);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`❌ Error processing Game ID ${id}:`, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({ message: "All screenshots processed successfully!" });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadToDirectus(filePath) {
|
||||||
|
try {
|
||||||
|
const fileData = fs.createReadStream(filePath);
|
||||||
|
|
||||||
|
const response = await axios.post(
|
||||||
|
DIRECTUS_API_URL,
|
||||||
|
{ file: fileData },
|
||||||
|
{
|
||||||
|
headers: { "Content-Type": "multipart/form-data" },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return response.data.data.id;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ Failed to upload screenshot to Directus:", error.message);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function updateThumbnail(gameId, fileId) {
|
||||||
|
const UPDATE_THUMBNAIL_URL = "https://game-du.teachertrainingkolkata.in/items/game_tick_variant1/";
|
||||||
|
try {
|
||||||
|
const response = await axios.patch(
|
||||||
|
`${UPDATE_THUMBNAIL_URL}${gameId}`,
|
||||||
|
{ thumbnail: fileId }, // ✅ No need for "data" wrapper in REST API
|
||||||
|
{ headers: { "Content-Type": "application/json" } }
|
||||||
|
);
|
||||||
|
console.log(`✅ Thumbnail updated for Game ID ${gameId}:`, response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`❌ Failed to update thumbnail for Game ID ${gameId}`);
|
||||||
|
if (error.response) {
|
||||||
|
console.error("Response Data:", error.response.data);
|
||||||
|
console.error("Status Code:", error.response.status);
|
||||||
|
} else {
|
||||||
|
console.error("Error Message:", error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = takeSnap;
|
||||||
@@ -35,7 +35,7 @@ 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");
|
||||||
const getGameData = require("../api/getGameData");
|
const getGameData = require("../api/getGameData");
|
||||||
const imageToStar = require("../api/imageToStar");
|
const takeSnap = require("../api/takeSnap");
|
||||||
// const aiTest = require("../api/aiTest");
|
// const aiTest = require("../api/aiTest");
|
||||||
|
|
||||||
|
|
||||||
@@ -215,11 +215,10 @@ router.get("/ping", (req, res) => {
|
|||||||
getGameData(req, res);
|
getGameData(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Image to Star
|
router.get("/takeSnap", (req, res) => {
|
||||||
router.post("/imageToStar", (req, res) => {
|
takeSnap(req, res);
|
||||||
imageToStar(req, res);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get Drawing Game Gallery Image
|
// Get Drawing Game Gallery Image
|
||||||
// router.post("/aiTest", (req, res) => {
|
// router.post("/aiTest", (req, res) => {
|
||||||
// aiTest(req, res);
|
// aiTest(req, res);
|
||||||
|
|||||||
Reference in New Issue
Block a user