Compare commits
No commits in common. "master" and "suvo-patch-1" have entirely different histories.
master
...
suvo-patch
29
Dockerfile
29
Dockerfile
|
@ -1,26 +1,21 @@
|
||||||
# Use an official Node.js runtime as a parent image
|
ARG NODE_VERSION=18
|
||||||
FROM node:20-alpine
|
|
||||||
|
|
||||||
# Set the working directory inside the container
|
FROM node:${NODE_VERSION}-alpine
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy package files and set ownership
|
ENV NODE_ENV production
|
||||||
COPY --chown=node:node package*.json ./
|
|
||||||
|
|
||||||
# Install dependencies
|
RUN mkdir -p /usr/src/iimtt_api && chown -R node:node /usr/src/iimtt_api
|
||||||
RUN npm install --omit=dev
|
|
||||||
|
|
||||||
# Copy the rest of the app's source code with correct ownership
|
WORKDIR /usr/src/iimtt_api
|
||||||
COPY --chown=node:node . .
|
|
||||||
|
COPY package.json yarn.lock ./
|
||||||
|
|
||||||
# Use a non-root user for better security
|
|
||||||
USER node
|
USER node
|
||||||
|
|
||||||
# Expose the application port
|
RUN yarn install --pure-lockfile
|
||||||
EXPOSE 3000
|
|
||||||
|
|
||||||
# Set environment variables (optional)
|
COPY --chown=node:node . .
|
||||||
ENV NODE_ENV=production
|
|
||||||
|
|
||||||
# Start the application
|
EXPOSE 5174
|
||||||
CMD ["npm", "run", "start"]
|
|
||||||
|
CMD yarn start
|
|
@ -57,6 +57,7 @@
|
||||||
"eslint-plugin-prettier": "^3.1.1",
|
"eslint-plugin-prettier": "^3.1.1",
|
||||||
"eslint-plugin-security": "^1.4.0",
|
"eslint-plugin-security": "^1.4.0",
|
||||||
"faker": "^5.1.0",
|
"faker": "^5.1.0",
|
||||||
|
"husky": "7.0.4",
|
||||||
"jest": "^26.0.1",
|
"jest": "^26.0.1",
|
||||||
"lint-staged": "^11.0.0",
|
"lint-staged": "^11.0.0",
|
||||||
"node-mocks-http": "^1.8.0",
|
"node-mocks-http": "^1.8.0",
|
||||||
|
@ -6182,6 +6183,22 @@
|
||||||
"node": ">=8.12.0"
|
"node": ">=8.12.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/husky": {
|
||||||
|
"version": "7.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/husky/-/husky-7.0.4.tgz",
|
||||||
|
"integrity": "sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"husky": "lib/bin.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/typicode"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/iconv-lite": {
|
"node_modules/iconv-lite": {
|
||||||
"version": "0.4.24",
|
"version": "0.4.24",
|
||||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
"prettier:fix": "prettier --write **/*.js",
|
"prettier:fix": "prettier --write **/*.js",
|
||||||
"docker:prod": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up",
|
"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: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"
|
"docker:test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up",
|
||||||
|
"prepare": "husky install"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"node",
|
"node",
|
||||||
|
@ -92,6 +93,7 @@
|
||||||
"eslint-plugin-prettier": "^3.1.1",
|
"eslint-plugin-prettier": "^3.1.1",
|
||||||
"eslint-plugin-security": "^1.4.0",
|
"eslint-plugin-security": "^1.4.0",
|
||||||
"faker": "^5.1.0",
|
"faker": "^5.1.0",
|
||||||
|
"husky": "7.0.4",
|
||||||
"jest": "^26.0.1",
|
"jest": "^26.0.1",
|
||||||
"lint-staged": "^11.0.0",
|
"lint-staged": "^11.0.0",
|
||||||
"node-mocks-http": "^1.8.0",
|
"node-mocks-http": "^1.8.0",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const aiFeedbackOnReport = async (req, res) => {
|
const aiFeedbackOnReport = async (req, res) => {
|
||||||
// const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const url = process.env.AI_API_ENDOINT;
|
const url = process.env.AI_API_ENDOINT;
|
||||||
const api_key = process.env.AI_API_KEY;
|
const api_key = process.env.AI_API_KEY;
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const aiFeedbackOnReport = async (req, res) => {
|
const aiFeedbackOnReport = async (req, res) => {
|
||||||
// const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const url = process.env.AI_API_ENDOINT;
|
const url = process.env.AI_API_ENDOINT;
|
||||||
const api_key = process.env.OPENAI_KEY;
|
const api_key = process.env.OPENAI_KEY;
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const aiFollowupQuestion = async (req, res) => {
|
const aiFollowupQuestion = async (req, res) => {
|
||||||
|
|
||||||
const { MongoClient } = require('mongodb');
|
const { MongoClient } = require('mongodb');
|
||||||
// const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
const url = process.env.MONGODB_URL;
|
const url = process.env.MONGODB_URL;
|
||||||
const dbName = process.env.MONGO_DB_NAME;
|
const dbName = process.env.MONGO_DB_NAME;
|
||||||
|
|
|
@ -1,32 +1,7 @@
|
||||||
const aiFollowupQuestion = async (req, res) => {
|
const aiFollowupQuestion = async (req, res) => {
|
||||||
// curl -X POST http://localhost:3000/your-endpoint-path \
|
|
||||||
// -H "Content-Type: application/json" \
|
|
||||||
// -d '{
|
|
||||||
// "prompt": "Why is the sky blue?",
|
|
||||||
// "sessionId": "",
|
|
||||||
// "model": "gpt-3.5-turbo-16k",
|
|
||||||
// "max_tokens": 200
|
|
||||||
// }'
|
|
||||||
|
|
||||||
// curl -X POST http://localhost:5174/api/aiFollowupQuestion \
|
|
||||||
// -H "Content-Type: application/json" \
|
|
||||||
// -d '{
|
|
||||||
// "prompt": "Why is the sky blue?",
|
|
||||||
// "sessionId": "",
|
|
||||||
// "model": "gpt-3.5-turbo-16k",
|
|
||||||
// "sessionId" : "8c641aca-582d-4ea7-8e56-4f94318efe74",
|
|
||||||
// "max_tokens": 200
|
|
||||||
// }'
|
|
||||||
|
|
||||||
// {
|
|
||||||
// "success": true,
|
|
||||||
// "data": "The sky looks blue because of how sunlight scatters in the air. Great question! Ask me more!",
|
|
||||||
// "total_tokens": 45,
|
|
||||||
// "sessionId": "2a3b3cc4-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
||||||
// }
|
|
||||||
|
|
||||||
const { MongoClient } = require('mongodb');
|
const { MongoClient } = require('mongodb');
|
||||||
// const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
const url = process.env.MONGODB_URL;
|
const url = process.env.MONGODB_URL;
|
||||||
const dbName = process.env.MONGO_DB_NAME;
|
const dbName = process.env.MONGO_DB_NAME;
|
||||||
|
@ -36,11 +11,11 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
const database = client.db(dbName);
|
const database = client.db(dbName);
|
||||||
const conversationsCollection = database.collection('conversations');
|
const conversationsCollection = database.collection('conversations');
|
||||||
|
|
||||||
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 = 200) {
|
||||||
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
const response = await fetch('https://api.openai.com/v1/chat/completions', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${process.env.OPENAI_KEY}`,
|
'Authorization': `Bearer ${process.env.OPENAI_KEY}`,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -60,8 +35,9 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { prompt, sessionId, model = 'gpt-3.5-turbo-16k', max_tokens = 200 } = req.body;
|
const { prompt, sessionId, model = "gpt-3.5-turbo-16k", max_tokens = 200 } = req.body;
|
||||||
if (!conversationsCollection) {
|
if (!conversationsCollection) {
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -76,11 +52,7 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
conversation = {
|
conversation = {
|
||||||
sessionId: newSessionId,
|
sessionId: newSessionId,
|
||||||
conversationHistory: [
|
conversationHistory: [
|
||||||
{
|
{ role: 'system', content: 'answer within 10 words' },
|
||||||
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: 'user', content: prompt },
|
{ role: 'user', content: prompt },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -118,6 +90,8 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
error: 'Something went wrong. Please try again later.',
|
error: 'Something went wrong. Please try again later.',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = aiFollowupQuestion;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = aiFollowupQuestion;
|
|
@ -2,7 +2,7 @@ const aiMarkDrawing = async (req, res) => {
|
||||||
|
|
||||||
|
|
||||||
const express = require('express');
|
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 path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const aiFollowupQuestion = async (req, res) => {
|
const aiFollowupQuestion = async (req, res) => {
|
||||||
const { MongoClient } = require('mongodb');
|
const { MongoClient } = require('mongodb');
|
||||||
// const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
const url = process.env.MONGODB_URL;
|
const url = process.env.MONGODB_URL;
|
||||||
const dbName = process.env.MONGO_DB_NAME;
|
const dbName = process.env.MONGO_DB_NAME;
|
||||||
|
@ -56,7 +56,7 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const { prompt, sessionId, provider, model = "gpt-4o-mini", key, system } = req.body;
|
const { prompt, sessionId, provider, model = "gpt-4o-mini", key } = req.body;
|
||||||
|
|
||||||
if (!key || !PROVIDER_KEYS.includes(key)) {
|
if (!key || !PROVIDER_KEYS.includes(key)) {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
|
@ -101,7 +101,7 @@ const aiFollowupQuestion = async (req, res) => {
|
||||||
conversation = {
|
conversation = {
|
||||||
sessionId: newSessionId,
|
sessionId: newSessionId,
|
||||||
conversationHistory: [
|
conversationHistory: [
|
||||||
{ role: 'system', content: system },
|
{ role: 'system', content: 'answer within 10 words' },
|
||||||
{ role: 'user', content: prompt },
|
{ role: 'user', content: prompt },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,15 +3,6 @@ const AWS = require('aws-sdk');
|
||||||
const FormData = require('form-data');
|
const FormData = require('form-data');
|
||||||
|
|
||||||
const aiTextToSpeech = async (req, res) => {
|
const aiTextToSpeech = async (req, res) => {
|
||||||
// curl -X POST http://localhost:5174/api/aiTextToSpeech \
|
|
||||||
// -H "Content-Type: application/json" \
|
|
||||||
// -d '{
|
|
||||||
// "text": "Hello, this is a sample speech.",
|
|
||||||
// "voiceId": "Ava"
|
|
||||||
// }'
|
|
||||||
|
|
||||||
// {"message":"Speech generated and saved successfully","fileUrls":["https://polly-bs.s3.ap-south-1.amazonaws.com/file_MpNpWluxR7R70BA-dzju_U3C94bPmC-n-speech.mp3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAQ35B6OYR6T5MGH7Q%2F20250814%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20250814T163252Z&X-Amz-Expires=86400&X-Amz-Signature=12dd2feaf73564d6c843b0dc975fdedb35c430d316f4f09fcdf41e247d1ea63c&X-Amz-SignedHeaders=host","https://polly-bs.s3.ap-south-1.amazonaws.com/file_SXmwHWwlcSBlI9LNoZ1PcLEdMD7D1PWO-text.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAQ35B6OYR6T5MGH7Q%2F20250814%2Fap-south-1%2Fs3%2Faws4_request&X-Amz-Date=20250814T163252Z&X-Amz-Expires=86400&X-Amz-Signature=d96eb4fe7cabfab93ce0ffe8fc74a8e722a2064d904652d47ad361f2f3667ec7&X-Amz-SignedHeaders=host"],"fileKeys":{"file1":"file_MpNpWluxR7R70BA-dzju_U3C94bPmC-n-speech.mp3","file2":"file_SXmwHWwlcSBlI9LNoZ1PcLEdMD7D1PWO-text.txt"}}
|
|
||||||
|
|
||||||
AWS.config.update({
|
AWS.config.update({
|
||||||
region: 'ap-south-1',
|
region: 'ap-south-1',
|
||||||
accessKeyId: process.env.AWS_polly2_ACCESS_KEY_ID,
|
accessKeyId: process.env.AWS_polly2_ACCESS_KEY_ID,
|
||||||
|
@ -20,12 +11,12 @@ const aiTextToSpeech = async (req, res) => {
|
||||||
|
|
||||||
const polly = new AWS.Polly();
|
const polly = new AWS.Polly();
|
||||||
const voiceIdMap = {
|
const voiceIdMap = {
|
||||||
Ava: 'Ivy',
|
"Ava": "Ivy",
|
||||||
Monstero: 'Justin',
|
"Monstero": "Justin",
|
||||||
Dax: 'Kevin',
|
"Dax": "Kevin",
|
||||||
Kai: 'Danielle',
|
"Kai": "Danielle",
|
||||||
Arlo: 'Ruth',
|
"Arlo": "Ruth",
|
||||||
Yara: 'Salli',
|
"Yara": "Salli"
|
||||||
};
|
};
|
||||||
|
|
||||||
const { text, voiceId: frontendVoiceId } = req.body;
|
const { text, voiceId: frontendVoiceId } = req.body;
|
||||||
|
@ -50,9 +41,7 @@ const aiTextToSpeech = async (req, res) => {
|
||||||
function generateTimestampWithRandomDigits() {
|
function generateTimestampWithRandomDigits() {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const formattedDate = now.toISOString().replace('T', '_').replace(/\..+/, '').replace(/:/g, '-');
|
const formattedDate = now.toISOString().replace('T', '_').replace(/\..+/, '').replace(/:/g, '-');
|
||||||
const randomDigits = Math.floor(Math.random() * 10000)
|
const randomDigits = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
|
||||||
.toString()
|
|
||||||
.padStart(4, '0');
|
|
||||||
return `${formattedDate}_${randomDigits}`;
|
return `${formattedDate}_${randomDigits}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,18 +59,23 @@ const aiTextToSpeech = async (req, res) => {
|
||||||
// formData.append('folder', folderName); // Send folder name
|
// formData.append('folder', folderName); // Send folder name
|
||||||
formData.append('bucket', 'polly-bs'); // Adjust bucket
|
formData.append('bucket', 'polly-bs'); // Adjust bucket
|
||||||
|
|
||||||
const response = await axios.post('https://preschool-curriculum.in/api/one/v1/file/upload', formData, {
|
const response = await axios.post(
|
||||||
|
'https://preschool-curriculum.in/api/one/v1/file/upload',
|
||||||
|
formData,
|
||||||
|
{
|
||||||
headers: {
|
headers: {
|
||||||
// 'Authorization': `Bearer ${process.env.BEARER_TOKEN}`,
|
// 'Authorization': `Bearer ${process.env.BEARER_TOKEN}`,
|
||||||
...formData.getHeaders(), // Ensure FormData headers are included
|
...formData.getHeaders() // Ensure FormData headers are included
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
message: 'Speech generated and saved successfully',
|
message: 'Speech generated and saved successfully',
|
||||||
fileUrls: response.data.urls,
|
fileUrls: response.data.urls,
|
||||||
fileKeys: response.data.data,
|
fileKeys: response.data.data
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error generating speech or uploading files:', error);
|
console.error('Error generating speech or uploading files:', error);
|
||||||
res.status(500).json({ error: 'Error generating speech or uploading files' });
|
res.status(500).json({ error: 'Error generating speech or uploading files' });
|
||||||
|
|
|
@ -1,147 +0,0 @@
|
||||||
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;
|
|
|
@ -34,7 +34,6 @@ 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");
|
||||||
const getGameData = require("../api/getGameData");
|
|
||||||
// const aiTest = require("../api/aiTest");
|
// const aiTest = require("../api/aiTest");
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,10 +209,6 @@ router.get("/ping", (req, res) => {
|
||||||
getGalleryImage(req, res);
|
getGalleryImage(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/getGameData", (req, res) => {
|
|
||||||
getGameData(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);
|
||||||
|
|
Loading…
Reference in New Issue