Spaces:
Sleeping
Sleeping
Update app.js
Browse files
app.js
CHANGED
|
@@ -5,6 +5,7 @@ import { StateManager, initDB } from './stateManager.js'; // Import initDB
|
|
| 5 |
import { AIEngine } from './aiEngine.js';
|
| 6 |
import fs from 'fs';
|
| 7 |
import admin from 'firebase-admin';
|
|
|
|
| 8 |
|
| 9 |
// --- FIREBASE SETUP ---
|
| 10 |
let db = null;
|
|
@@ -104,7 +105,16 @@ app.post('/onboarding/analyze', validateRequest, async (req, res) => {
|
|
| 104 |
|
| 105 |
app.post('/onboarding/create', validateRequest, async (req, res) => {
|
| 106 |
const { userId, description, answers } = req.body;
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
try {
|
| 110 |
console.log(`[Onboarding] Grading Project ${projectId}...`);
|
|
|
|
| 5 |
import { AIEngine } from './aiEngine.js';
|
| 6 |
import fs from 'fs';
|
| 7 |
import admin from 'firebase-admin';
|
| 8 |
+
import crypto from "crypto";
|
| 9 |
|
| 10 |
// --- FIREBASE SETUP ---
|
| 11 |
let db = null;
|
|
|
|
| 105 |
|
| 106 |
app.post('/onboarding/create', validateRequest, async (req, res) => {
|
| 107 |
const { userId, description, answers } = req.body;
|
| 108 |
+
|
| 109 |
+
// helper: random hex of N chars (N can be 6 or 7)
|
| 110 |
+
const randomHex = (n = 6) => {
|
| 111 |
+
const bytes = Math.ceil(n / 2);
|
| 112 |
+
return crypto.randomBytes(bytes).toString("hex").slice(0, n);
|
| 113 |
+
};
|
| 114 |
+
|
| 115 |
+
// example usage (choose 6 or 7 hex chars)
|
| 116 |
+
const projectId = `proj_${Date.now()}_${randomHex(7)}`;
|
| 117 |
+
// const projectId = "proj_" + Date.now();
|
| 118 |
|
| 119 |
try {
|
| 120 |
console.log(`[Onboarding] Grading Project ${projectId}...`);
|