Update app.js
Browse files
app.js
CHANGED
|
@@ -68,7 +68,7 @@ function extractImagePrompt(text) {
|
|
| 68 |
|
| 69 |
// --- ONBOARDING ENDPOINTS ---
|
| 70 |
/**
|
| 71 |
-
* 1. ANALYZE
|
| 72 |
*/
|
| 73 |
app.post('/onboarding/analyze', validateRequest, async (req, res) => {
|
| 74 |
const { description } = req.body;
|
|
@@ -78,15 +78,12 @@ app.post('/onboarding/analyze', validateRequest, async (req, res) => {
|
|
| 78 |
console.log(`[Onboarding] Analyzing idea...`);
|
| 79 |
const result = await AIEngine.generateEntryQuestions(description);
|
| 80 |
|
| 81 |
-
// CHECK 1: Immediate Rejection
|
| 82 |
if (result.status === "REJECTED") {
|
| 83 |
return res.json({
|
| 84 |
rejected: true,
|
| 85 |
reason: result.reason || "Idea violates TOS or guidelines."
|
| 86 |
});
|
| 87 |
}
|
| 88 |
-
|
| 89 |
-
// If Accepted, send questions
|
| 90 |
res.json({ questions: result.questions });
|
| 91 |
} catch (err) {
|
| 92 |
console.error(err);
|
|
@@ -95,7 +92,7 @@ app.post('/onboarding/analyze', validateRequest, async (req, res) => {
|
|
| 95 |
});
|
| 96 |
|
| 97 |
/**
|
| 98 |
-
* 2. CREATE
|
| 99 |
*/
|
| 100 |
app.post('/onboarding/create', validateRequest, async (req, res) => {
|
| 101 |
const { userId, description, answers } = req.body;
|
|
@@ -104,21 +101,24 @@ app.post('/onboarding/create', validateRequest, async (req, res) => {
|
|
| 104 |
try {
|
| 105 |
console.log(`[Onboarding] Grading Project ${projectId}...`);
|
| 106 |
|
| 107 |
-
// STEP 1: GRADE
|
| 108 |
const grading = await AIEngine.gradeProject(description, answers);
|
| 109 |
|
| 110 |
-
// STEP 2: CHECK FAIL CONDITIONS
|
| 111 |
-
//
|
| 112 |
-
const isFailure = grading.feasibility <
|
| 113 |
|
| 114 |
let thumbnailBase64 = null;
|
| 115 |
|
| 116 |
if (isFailure) {
|
| 117 |
console.log(`[Onboarding] ❌ Project Failed Grading (${grading.rating}). Skipping Image.`);
|
| 118 |
} else {
|
| 119 |
-
// STEP 3: GENERATE IMAGE ONLY IF PASSED
|
| 120 |
console.log(`[Onboarding] ✅ Passed. Generating Thumbnail...`);
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
const projectData = {
|
|
@@ -133,10 +133,8 @@ app.post('/onboarding/create', validateRequest, async (req, res) => {
|
|
| 133 |
status: isFailure ? "rejected" : "initialized"
|
| 134 |
};
|
| 135 |
|
| 136 |
-
// Save (even failed ones, for history, or you can skip)
|
| 137 |
if (db) await db.ref(`projects/${projectId}`).set(projectData);
|
| 138 |
|
| 139 |
-
// Only load into memory if it passed
|
| 140 |
if (!isFailure) {
|
| 141 |
await StateManager.updateProject(projectId, {
|
| 142 |
...projectData,
|
|
@@ -147,7 +145,7 @@ app.post('/onboarding/create', validateRequest, async (req, res) => {
|
|
| 147 |
}
|
| 148 |
|
| 149 |
res.json({
|
| 150 |
-
success: !isFailure,
|
| 151 |
projectId,
|
| 152 |
stats: grading,
|
| 153 |
title: projectData.title,
|
|
@@ -160,6 +158,7 @@ app.post('/onboarding/create', validateRequest, async (req, res) => {
|
|
| 160 |
}
|
| 161 |
});
|
| 162 |
|
|
|
|
| 163 |
// --- CORE WORKFLOW ENDPOINTS ---
|
| 164 |
|
| 165 |
/**
|
|
|
|
| 68 |
|
| 69 |
// --- ONBOARDING ENDPOINTS ---
|
| 70 |
/**
|
| 71 |
+
* 1. ANALYZE
|
| 72 |
*/
|
| 73 |
app.post('/onboarding/analyze', validateRequest, async (req, res) => {
|
| 74 |
const { description } = req.body;
|
|
|
|
| 78 |
console.log(`[Onboarding] Analyzing idea...`);
|
| 79 |
const result = await AIEngine.generateEntryQuestions(description);
|
| 80 |
|
|
|
|
| 81 |
if (result.status === "REJECTED") {
|
| 82 |
return res.json({
|
| 83 |
rejected: true,
|
| 84 |
reason: result.reason || "Idea violates TOS or guidelines."
|
| 85 |
});
|
| 86 |
}
|
|
|
|
|
|
|
| 87 |
res.json({ questions: result.questions });
|
| 88 |
} catch (err) {
|
| 89 |
console.error(err);
|
|
|
|
| 92 |
});
|
| 93 |
|
| 94 |
/**
|
| 95 |
+
* 2. CREATE
|
| 96 |
*/
|
| 97 |
app.post('/onboarding/create', validateRequest, async (req, res) => {
|
| 98 |
const { userId, description, answers } = req.body;
|
|
|
|
| 101 |
try {
|
| 102 |
console.log(`[Onboarding] Grading Project ${projectId}...`);
|
| 103 |
|
| 104 |
+
// STEP 1: GRADE
|
| 105 |
const grading = await AIEngine.gradeProject(description, answers);
|
| 106 |
|
| 107 |
+
// STEP 2: CHECK FAIL CONDITIONS (Relaxed)
|
| 108 |
+
// Only fail if Feasibility is extremely low (< 30) or Rating is F
|
| 109 |
+
const isFailure = grading.feasibility < 30 || grading.rating === 'F';
|
| 110 |
|
| 111 |
let thumbnailBase64 = null;
|
| 112 |
|
| 113 |
if (isFailure) {
|
| 114 |
console.log(`[Onboarding] ❌ Project Failed Grading (${grading.rating}). Skipping Image.`);
|
| 115 |
} else {
|
|
|
|
| 116 |
console.log(`[Onboarding] ✅ Passed. Generating Thumbnail...`);
|
| 117 |
+
|
| 118 |
+
// --- CRITICAL FIX HERE ---
|
| 119 |
+
// We MUST send the description so the AI knows what to draw.
|
| 120 |
+
const imagePrompt = `Game Title: ${grading.title}. Core Concept: ${description}`;
|
| 121 |
+
thumbnailBase64 = await AIEngine.generateImage(imagePrompt);
|
| 122 |
}
|
| 123 |
|
| 124 |
const projectData = {
|
|
|
|
| 133 |
status: isFailure ? "rejected" : "initialized"
|
| 134 |
};
|
| 135 |
|
|
|
|
| 136 |
if (db) await db.ref(`projects/${projectId}`).set(projectData);
|
| 137 |
|
|
|
|
| 138 |
if (!isFailure) {
|
| 139 |
await StateManager.updateProject(projectId, {
|
| 140 |
...projectData,
|
|
|
|
| 145 |
}
|
| 146 |
|
| 147 |
res.json({
|
| 148 |
+
success: !isFailure,
|
| 149 |
projectId,
|
| 150 |
stats: grading,
|
| 151 |
title: projectData.title,
|
|
|
|
| 158 |
}
|
| 159 |
});
|
| 160 |
|
| 161 |
+
|
| 162 |
// --- CORE WORKFLOW ENDPOINTS ---
|
| 163 |
|
| 164 |
/**
|