Spaces:
Running
Running
Update app.js
Browse files
app.js
CHANGED
|
@@ -113,44 +113,77 @@ app.post('/onboarding/create', validateRequest, async (req, res) => {
|
|
| 113 |
let thumbnailBase64 = null;
|
| 114 |
|
| 115 |
if (isFailure) {
|
| 116 |
-
console.log(`[Onboarding] ❌ Project Failed Grading
|
| 117 |
} else {
|
| 118 |
console.log(`[Onboarding] ✅ Passed. Generating Thumbnail...`);
|
| 119 |
const imagePrompt = `Game Title: ${grading.title}. Core Concept: ${description}`;
|
| 120 |
thumbnailBase64 = await AIEngine.generateImage(imagePrompt);
|
| 121 |
}
|
| 122 |
|
| 123 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
id: projectId,
|
| 125 |
userId,
|
| 126 |
title: grading.title || "Untitled Project",
|
| 127 |
description,
|
| 128 |
answers,
|
| 129 |
stats: grading,
|
| 130 |
-
thumbnail: thumbnailBase64
|
| 131 |
-
createdAt:
|
| 132 |
-
status
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
};
|
| 134 |
|
| 135 |
-
//
|
| 136 |
-
if (
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
workerHistory: [],
|
| 140 |
pmHistory: [],
|
|
|
|
| 141 |
failureCount: 0
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
}
|
| 147 |
|
| 148 |
res.json({
|
| 149 |
success: !isFailure,
|
| 150 |
projectId,
|
| 151 |
stats: grading,
|
| 152 |
-
title:
|
| 153 |
-
thumbnail:
|
| 154 |
});
|
| 155 |
|
| 156 |
} catch (err) {
|
|
|
|
| 113 |
let thumbnailBase64 = null;
|
| 114 |
|
| 115 |
if (isFailure) {
|
| 116 |
+
console.log(`[Onboarding] ❌ Project Failed Grading. Skipping Image.`);
|
| 117 |
} else {
|
| 118 |
console.log(`[Onboarding] ✅ Passed. Generating Thumbnail...`);
|
| 119 |
const imagePrompt = `Game Title: ${grading.title}. Core Concept: ${description}`;
|
| 120 |
thumbnailBase64 = await AIEngine.generateImage(imagePrompt);
|
| 121 |
}
|
| 122 |
|
| 123 |
+
const timestamp = Date.now();
|
| 124 |
+
const status = isFailure ? "rejected" : "initialized";
|
| 125 |
+
|
| 126 |
+
// 1. Prepare Memory Object (Flat for easy internal usage)
|
| 127 |
+
const memoryObject = {
|
| 128 |
id: projectId,
|
| 129 |
userId,
|
| 130 |
title: grading.title || "Untitled Project",
|
| 131 |
description,
|
| 132 |
answers,
|
| 133 |
stats: grading,
|
| 134 |
+
thumbnail: thumbnailBase64, // ? `data:image/png;base64,${thumbnailBase64}` : null,
|
| 135 |
+
createdAt: timestamp,
|
| 136 |
+
status,
|
| 137 |
+
workerHistory: [],
|
| 138 |
+
pmHistory: [],
|
| 139 |
+
commandQueue: [],
|
| 140 |
+
failureCount: 0
|
| 141 |
};
|
| 142 |
|
| 143 |
+
// 2. Prepare Database Object (Nested for performance)
|
| 144 |
+
if (db) {
|
| 145 |
+
const updates = {};
|
| 146 |
+
|
| 147 |
+
// Bucket 1: Info (Lightweight)
|
| 148 |
+
updates[`projects/${projectId}/info`] = {
|
| 149 |
+
id: projectId,
|
| 150 |
+
userId,
|
| 151 |
+
title: grading.title || "Untitled Project",
|
| 152 |
+
description,
|
| 153 |
+
answers,
|
| 154 |
+
stats: grading,
|
| 155 |
+
createdAt: timestamp,
|
| 156 |
+
status
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
// Bucket 2: Thumbnail (Heavy - Isolated)
|
| 160 |
+
if (thumbnailBase64) {
|
| 161 |
+
updates[`projects/${projectId}/thumbnail`] = thumbnailBase64;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
// Bucket 3: State (History)
|
| 165 |
+
updates[`projects/${projectId}/state`] = {
|
| 166 |
workerHistory: [],
|
| 167 |
pmHistory: [],
|
| 168 |
+
commandQueue: [],
|
| 169 |
failureCount: 0
|
| 170 |
+
};
|
| 171 |
+
|
| 172 |
+
// Atomic multi-path update
|
| 173 |
+
await db.ref().update(updates);
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
// 3. Update Memory
|
| 177 |
+
if (!isFailure) {
|
| 178 |
+
await StateManager.updateProject(projectId, memoryObject);
|
| 179 |
}
|
| 180 |
|
| 181 |
res.json({
|
| 182 |
success: !isFailure,
|
| 183 |
projectId,
|
| 184 |
stats: grading,
|
| 185 |
+
title: grading.title || "Untitled Project",
|
| 186 |
+
thumbnail: memoryObject.thumbnail
|
| 187 |
});
|
| 188 |
|
| 189 |
} catch (err) {
|