Compare commits
28 Commits
branch2
...
37316ff794
| Author | SHA1 | Date | |
|---|---|---|---|
| 37316ff794 | |||
| f6835d9417 | |||
| 3cba906217 | |||
| 9f3f904a3a | |||
| 0038ee1b25 | |||
| b9d2e682c5 | |||
| ec27c1b366 | |||
| d3212fadbc | |||
| 9b9f841b12 | |||
|
|
e12308e8bb | ||
|
|
cdee582951 | ||
|
|
dc6194f7e7 | ||
|
|
6d380c6cbb | ||
|
|
8e0cce2465 | ||
|
|
0735a91450 | ||
|
|
1576fa92c1 | ||
|
|
319bc33d4a | ||
|
|
b7da294a17 | ||
|
|
0d4323df9e | ||
|
|
5da7710af1 | ||
| 76e503c4a9 | |||
| 91b73215be | |||
| 40eda82022 | |||
| 2150d52b9d | |||
| fb21f179e6 | |||
| 5777ee5131 | |||
| f96a50b7f4 | |||
| 3f944eb49e |
33
Dockerfile
33
Dockerfile
@@ -1,21 +1,26 @@
|
||||
ARG NODE_VERSION=18
|
||||
# Use an official Node.js runtime as a parent image
|
||||
FROM node:20-alpine
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV production
|
||||
# Copy package files and set ownership
|
||||
COPY --chown=node:node package*.json ./
|
||||
|
||||
RUN mkdir -p /usr/src/iimtt_api && chown -R node:node /usr/src/iimtt_api
|
||||
|
||||
WORKDIR /usr/src/iimtt_api
|
||||
|
||||
COPY package.json yarn.lock ./
|
||||
|
||||
USER node
|
||||
|
||||
RUN yarn install --pure-lockfile
|
||||
# Install dependencies
|
||||
RUN npm install --omit=dev
|
||||
|
||||
# Copy the rest of the app's source code with correct ownership
|
||||
COPY --chown=node:node . .
|
||||
|
||||
EXPOSE 5174
|
||||
# Use a non-root user for better security
|
||||
USER node
|
||||
|
||||
CMD yarn start
|
||||
# Expose the application port
|
||||
EXPOSE 3000
|
||||
|
||||
# Set environment variables (optional)
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# Start the application
|
||||
CMD ["npm", "run", "start"]
|
||||
|
||||
629
package-lock.json
generated
629
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
@@ -22,8 +22,7 @@
|
||||
"prettier:fix": "prettier --write **/*.js",
|
||||
"docker:prod": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up",
|
||||
"docker:dev": "docker-compose -f docker-compose.yml -f docker-compose.dev.yml up",
|
||||
"docker:test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up",
|
||||
"prepare": "husky install"
|
||||
"docker:test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up"
|
||||
},
|
||||
"keywords": [
|
||||
"node",
|
||||
@@ -49,18 +48,19 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"aws-sdk": "^2.1669.0",
|
||||
"axios": "^1.7.7",
|
||||
"axios": "^1.8.2",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"body-parser": "^1.20.2",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
"cross-env": "^7.0.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.1",
|
||||
"express": "^4.21.2",
|
||||
"express-mongo-sanitize": "^2.0.0",
|
||||
"express-rate-limit": "^5.0.0",
|
||||
"form-data": "^4.0.1",
|
||||
"form-data": "^4.0.2",
|
||||
"formdata-node": "^6.0.3",
|
||||
"fs": "^0.0.1-security",
|
||||
"helmet": "^4.1.0",
|
||||
"http-status": "^1.4.0",
|
||||
"install": "^0.13.0",
|
||||
@@ -76,7 +76,9 @@
|
||||
"npm": "^11.0.0",
|
||||
"passport": "^0.4.0",
|
||||
"passport-jwt": "^4.0.0",
|
||||
"path": "^0.12.7",
|
||||
"pm2": "^5.1.0",
|
||||
"puppeteer": "^24.4.0",
|
||||
"swagger-jsdoc": "^6.0.8",
|
||||
"swagger-ui-express": "^4.1.6",
|
||||
"validator": "^13.0.0",
|
||||
@@ -93,7 +95,6 @@
|
||||
"eslint-plugin-prettier": "^3.1.1",
|
||||
"eslint-plugin-security": "^1.4.0",
|
||||
"faker": "^5.1.0",
|
||||
"husky": "7.0.4",
|
||||
"jest": "^26.0.1",
|
||||
"lint-staged": "^11.0.0",
|
||||
"node-mocks-http": "^1.8.0",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 payload = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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.OPENAI_KEY;
|
||||
const payload = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const aiFollowupQuestion = async (req, res) => {
|
||||
|
||||
const { MongoClient } = require('mongodb');
|
||||
const fetch = require('node-fetch');
|
||||
// const fetch = require('node-fetch');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const url = process.env.MONGODB_URL;
|
||||
const dbName = process.env.MONGO_DB_NAME;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const aiFollowupQuestion = async (req, res) => {
|
||||
|
||||
const { MongoClient } = require('mongodb');
|
||||
const fetch = require('node-fetch');
|
||||
// const fetch = require('node-fetch');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const url = process.env.MONGODB_URL;
|
||||
const dbName = process.env.MONGO_DB_NAME;
|
||||
|
||||
@@ -2,7 +2,7 @@ const aiMarkDrawing = async (req, res) => {
|
||||
|
||||
|
||||
const express = require('express');
|
||||
const fetch = require('node-fetch'); // For making HTTP requests
|
||||
// const fetch = require('node-fetch'); // For making HTTP requests
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const aiFollowupQuestion = async (req, res) => {
|
||||
const { MongoClient } = require('mongodb');
|
||||
const fetch = require('node-fetch');
|
||||
// const fetch = require('node-fetch');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const url = process.env.MONGODB_URL;
|
||||
const dbName = process.env.MONGO_DB_NAME;
|
||||
|
||||
147
src/routes/api/getGameData.js
Normal file
147
src/routes/api/getGameData.js
Normal file
@@ -0,0 +1,147 @@
|
||||
require("dotenv").config();
|
||||
const express = require("express");
|
||||
const mariadb = require("mariadb");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Create MariaDB 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 getGameData = async (req, res) => {
|
||||
let conn;
|
||||
let items = 'ws2gamelink';
|
||||
try {
|
||||
const { wsname } = req.query;
|
||||
if (!items || !wsname) {
|
||||
return res.status(400).json({ error: "Missing items or wsname parameter" });
|
||||
}
|
||||
|
||||
console.log("Fetching game data from table:", items);
|
||||
|
||||
conn = await pool.getConnection();
|
||||
|
||||
// Fetching the first dataset
|
||||
const ws2gamelinkQuery = `SELECT * FROM \`${items}\` WHERE wsname = ?`;
|
||||
const rows = await conn.query(ws2gamelinkQuery, [wsname]);
|
||||
|
||||
if (!rows.length) {
|
||||
return res.status(404).json({ error: "No data found" });
|
||||
}
|
||||
|
||||
let gamelinkArray = rows[0].gamelink;
|
||||
|
||||
// Ensure gamelinkArray is an array
|
||||
if (typeof gamelinkArray === "string") {
|
||||
gamelinkArray = [gamelinkArray]; // Convert to array if it's a string
|
||||
}
|
||||
if (!Array.isArray(gamelinkArray)) {
|
||||
return res.status(500).json({ error: "Invalid gamelink data format" });
|
||||
}
|
||||
|
||||
const gameDataResults = [];
|
||||
|
||||
for (const link of gamelinkArray) {
|
||||
const gameLinkParts = link.split('/');
|
||||
let gameNameFromUrl = '';
|
||||
let gameIdData = '';
|
||||
let gameTableName = '';
|
||||
let gameVersion = '';
|
||||
|
||||
if (gameLinkParts.length === 5) {
|
||||
gameNameFromUrl = gameLinkParts[3];
|
||||
gameIdData = gameLinkParts[4].split('=')[1]; // Extracting ID
|
||||
} else if (gameLinkParts.length === 6) {
|
||||
gameNameFromUrl = gameLinkParts[3];
|
||||
gameVersion = gameLinkParts[4];
|
||||
gameIdData = gameLinkParts[5].split('=')[1]; // Extracting ID
|
||||
}
|
||||
|
||||
if (gameNameFromUrl === 'drawing' && gameVersion === 'v2') {
|
||||
gameTableName = 'game_drawing_v2';
|
||||
} else if (gameNameFromUrl === 'drawing' && gameVersion === 'v3') {
|
||||
gameTableName = 'game_drawing_v3';
|
||||
} else if (gameNameFromUrl === 'drawing' && gameVersion === 'drawing_writo') {
|
||||
gameTableName = 'drawing_writo';
|
||||
} else if (gameNameFromUrl === 'drawing' && gameVersion === 'drawing_phonics') {
|
||||
gameTableName = 'drawing_phonics';
|
||||
} else if (gameNameFromUrl === 'drawing') {
|
||||
gameTableName = 'game_drawing'; // General case, only if no version is specified
|
||||
} else if (gameNameFromUrl === 'drag' && gameVersion === 'v2') {
|
||||
gameTableName = 'game_drag_v2';
|
||||
} else if (gameNameFromUrl === 'drag' && gameVersion === 'v4') {
|
||||
gameTableName = 'game_drag_v4';
|
||||
} else if (gameNameFromUrl === 'drag' && gameVersion === 'dragdrop_phonics') {
|
||||
gameTableName = 'drag_drop_phonics';
|
||||
} else if (gameNameFromUrl === 'drag' && gameVersion === 'match_phonics') {
|
||||
gameTableName = 'drag_phonics';
|
||||
} else if (gameNameFromUrl === 'drag') {
|
||||
gameTableName = 'game_drag'; // General case for "drag"
|
||||
} else if (gameNameFromUrl === 'tick' && gameVersion === 'tick_phonics_v1') {
|
||||
gameTableName = 'tick_phonics_option_6';
|
||||
} else if (gameNameFromUrl === 'tick' && gameVersion === 'tick_phonics_v2') {
|
||||
gameTableName = 'tick_phonics_option_9';
|
||||
} else if (gameNameFromUrl === 'tick' && gameVersion === 'tick_phonics_v3') {
|
||||
gameTableName = 'game_tick_v3_phonics';
|
||||
} else if (gameNameFromUrl === 'tick' && gameVersion === 'v1') {
|
||||
gameTableName = 'game_tick_variant1';
|
||||
} else if (gameNameFromUrl === 'tick' && gameVersion === 'v2') {
|
||||
gameTableName = 'game_tick_variant2';
|
||||
} else if (gameNameFromUrl === 'tick' && gameVersion === 'v3') {
|
||||
gameTableName = 'game_tick_varient3';
|
||||
} else if (gameNameFromUrl === 'cross' && gameVersion === 'cross_phonics_v1') {
|
||||
gameTableName = 'cross_phonics_option_6';
|
||||
} else if (gameNameFromUrl === 'cross' && gameVersion === 'cross_phonics_v2') {
|
||||
gameTableName = 'cross_phonics_option_9';
|
||||
} else if (gameNameFromUrl === 'cross' && gameVersion === 'v1') {
|
||||
gameTableName = 'game_cross_varient1';
|
||||
} else if (gameNameFromUrl === 'cross' && gameVersion === 'v2') {
|
||||
gameTableName = 'game_cross_varient2';
|
||||
} else if (gameNameFromUrl === 'cross' && gameVersion === 'v3') {
|
||||
gameTableName = 'game_cross_varient3';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// else if (gameNameFromUrl === 'cross' && gameVersion === 'v2') {
|
||||
// gameTableName = 'game_cross_varient2';
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// console.log('Game Info:', { gameTableName, gameVersion, gameIdData });
|
||||
|
||||
if (gameTableName && gameIdData) {
|
||||
let gameConn;
|
||||
try {
|
||||
gameConn = await pool.getConnection();
|
||||
const gameDataQuery = `SELECT * FROM \`${gameTableName}\` WHERE id = ?`;
|
||||
const gameDataRows = await gameConn.query(gameDataQuery, [gameIdData]);
|
||||
gameDataResults.push({ link, data: gameDataRows });
|
||||
} catch (gameError) {
|
||||
console.error("Error fetching game data:", gameError);
|
||||
} finally {
|
||||
if (gameConn) gameConn.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ wsData: rows, gameData: gameDataResults });
|
||||
} catch (err) {
|
||||
console.error("Database error:", err);
|
||||
res.status(500).json({ error: "Database error" });
|
||||
} finally {
|
||||
if (conn) conn.release();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = getGameData;
|
||||
92
src/routes/api/takeSnap.js
Normal file
92
src/routes/api/takeSnap.js
Normal file
@@ -0,0 +1,92 @@
|
||||
const { execSync } = require("child_process");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const axios = require("axios");
|
||||
|
||||
const gameIds = ['128',
|
||||
'129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140', '141', '142',
|
||||
'143', '144', '145', '146', '147', '148', '149', '150', '151', '152', '153', '154', '155', '156',
|
||||
'157', '158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '170',
|
||||
'171', '172', '173', '174', '175', '176', '177'
|
||||
];
|
||||
|
||||
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/drawing/v3?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_drawing_v3/";
|
||||
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;
|
||||
@@ -34,6 +34,8 @@ const aiEvaluateImageToStar = require("../api/aiEvaluateImageToStar");
|
||||
const getGameInfo = require("../api/getGameInfo");
|
||||
const saveGalleryImage = require("../api/saveGalleryImage");
|
||||
const getGalleryImage = require("../api/getGalleryImage");
|
||||
const getGameData = require("../api/getGameData");
|
||||
const takeSnap = require("../api/takeSnap");
|
||||
// const aiTest = require("../api/aiTest");
|
||||
|
||||
|
||||
@@ -209,6 +211,14 @@ router.get("/ping", (req, res) => {
|
||||
getGalleryImage(req, res);
|
||||
});
|
||||
|
||||
router.get("/getGameData", (req, res) => {
|
||||
getGameData(req, res);
|
||||
});
|
||||
|
||||
router.get("/takeSnap", (req, res) => {
|
||||
takeSnap(req, res);
|
||||
});
|
||||
|
||||
// Get Drawing Game Gallery Image
|
||||
// router.post("/aiTest", (req, res) => {
|
||||
// aiTest(req, res);
|
||||
|
||||
Reference in New Issue
Block a user