NexaCoders commited on
Commit
bf2fdd7
Β·
verified Β·
1 Parent(s): 2ce0ded

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +283 -145
server.js CHANGED
@@ -1,205 +1,343 @@
1
  const express = require('express');
2
- const cors = require('cors');
3
  const multer = require('multer');
 
4
  const path = require('path');
5
  const fs = require('fs');
 
 
 
6
 
7
  const app = express();
8
- const PORT = process.env.PORT || 7860;
9
 
10
- app.use(cors({ origin: '*' }));
 
11
  app.use(express.json());
12
  app.use(express.static('public'));
13
  app.use('/uploads', express.static('uploads'));
14
- app.disable('x-powered-by');
15
 
16
- // πŸ”₯ UPLOAD STORAGE
17
- const upload = multer({ dest: 'uploads/' });
 
 
 
18
 
19
- // CLOTHES DATABASE
20
  const CLOTHES = {
21
- top: ['crop_top_black','sheer_top_white','bikini_top_red','mesh_top'],
22
- bra: ['pushup_black','lace_pink',null],
23
- boobs: ['visible','nipple_show','enhanced'],
24
- bottom: ['miniskirt_red','thong_visible','hotpants_black'],
25
- shoes: ['heels_black','heels_red']
26
  };
27
 
28
- let avatars = {};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- // 🏠 MAIN PAGE
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  app.get('/', (req, res) => {
32
- res.send(`
33
  <!DOCTYPE html>
34
  <html>
35
  <head>
36
- <title>πŸ”₯ NexaClothes - AI Image Generator</title>
 
37
  <style>
38
- body{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:white;font-family:Arial;padding:20px;max-width:1000px;margin:auto}
39
- .container{background:rgba(255,255,255,0.1);padding:30px;border-radius:20px;backdrop-filter:blur(10px)}
40
- button{background:linear-gradient(45deg,#ff6b6b,#ee5a24);color:white;border:none;padding:15px 30px;border-radius:50px;font-size:18px;cursor:pointer;transition:0.3s;width:100%;margin:10px 0}
41
- button:hover{transform:scale(1.05)}
42
- #preview{border:3px solid #ff6b6b;border-radius:15px;max-width:400px;max-height:500px;display:block;margin:20px auto}
43
- input[type=file]{background:#333;color:white;padding:10px;border-radius:10px;width:100%;margin:10px 0}
44
- .grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:20px}
45
- .card{background:rgba(255,255,255,0.1);padding:20px;border-radius:15px}
46
- select{width:100%;padding:12px;border:none;border-radius:10px;background:rgba(255,255,255,0.9);margin:10px 0}
 
 
 
 
 
 
 
 
47
  </style>
48
  </head>
49
  <body>
50
  <div class="container">
51
- <h1>πŸ”₯ <strong>NexaClothes</strong></h1>
52
- <p>Upload photo β†’ Change sexy clothes β†’ Generate!</p>
 
 
 
 
 
 
53
 
54
  <div class="grid">
55
- <div class="card">
56
- <h3>πŸ“Έ Upload Photo</h3>
57
- <input type="file" id="photo" accept="image/*">
58
- <button onclick="uploadPhoto()">πŸš€ Upload</button>
59
- </div>
60
-
61
- <div class="card">
62
- <h3>πŸ‘— Change Clothes</h3>
63
- <select id="category">
64
- <option value="top">πŸ‘š Top</option>
65
- <option value="bra">πŸ‘™ Bra</option>
66
- <option value="boobs">πŸ’ Boobs</option>
67
- <option value="bottom">πŸ‘– Bottom</option>
68
- </select>
69
- <input id="item" placeholder="e.g. nipple_show">
70
- <button onclick="changeClothes()">✨ Change</button>
71
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  </div>
73
 
74
- <img id="preview" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjQwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjNDQ4Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtc2l6ZT0iMjQiIGZpbGw9IndoaXRlIiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBkeT0iLjNlbSI+VW5yZWFkeTwvdGV4dD48L3N2Zz4=" style="display:none">
75
- <button onclick="generateImage()" id="generateBtn" disabled>🎨 Generate Sexy Image</button>
76
 
77
- <pre id="status">πŸ‘† Upload photo first!</pre>
 
78
  </div>
79
 
80
  <script>
81
- let currentUser = 'user_' + Math.random().toString(36).substr(2, 9);
82
  let hasPhoto = false;
83
 
84
- async function uploadPhoto(){
85
- const file = document.getElementById('photo').files[0];
86
- if(!file) return alert('Select photo!');
87
-
88
- const formData = new FormData();
89
- formData.append('photo', file);
90
- formData.append('userId', currentUser);
91
-
92
- document.getElementById('status').textContent = '⏳ Uploading...';
93
-
94
- const r = await fetch('/api/upload-photo', {method: 'POST', body: formData});
95
- const result = await r.json();
96
-
97
- if(result.success){
98
- document.getElementById('status').textContent = \`βœ… Uploaded! User: \${result.userId}\`;
99
- document.getElementById('generateBtn').disabled = false;
100
- hasPhoto = true;
101
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  }
103
 
104
- async function changeClothes(){
105
- const category = document.getElementById('category').value;
106
- const item = document.getElementById('item').value.trim();
107
- if(!item) return alert('Enter item name');
108
-
109
- const r = await fetch(\`/api/avatar/\${currentUser}/clothes/\${category}\`, {
110
- method: 'PATCH',
111
- headers: {'Content-Type': 'application/json'},
112
- body: JSON.stringify({item})
113
- });
114
- const result = await r.json();
115
- document.getElementById('status').textContent = \`βœ… \${category}: \${item}\\nOutfit: \${JSON.stringify(result, null, 2)}\`;
 
 
 
 
 
 
 
 
 
 
 
116
  }
117
 
118
- async function generateImage(){
119
- if(!hasPhoto) return alert('Upload photo first!');
120
-
121
- document.getElementById('status').textContent = '🎨 Generating...';
122
- const r = await fetch(\`/api/generate-image/\${currentUser}\`);
123
- const result = await r.json();
124
-
125
- document.getElementById('preview').src = result.imageUrl || result.imageData;
126
- document.getElementById('preview').style.display = 'block';
127
- document.getElementById('status').textContent = \`✨ Generated! Prompt: \${result.prompt}\`;
128
  }
129
  </script>
130
  </body>
131
  </html>
132
- `);
133
  });
134
 
135
- // πŸ”₯ API ROUTES
136
  app.post('/api/upload-photo', upload.single('photo'), (req, res) => {
137
- if (!req.file) return res.status(400).json({ error: 'No photo' });
138
-
139
- const userId = req.body.userId || 'user1';
140
- const photoPath = `/uploads/${req.file.filename}`;
141
-
142
- // Init avatar
143
- if (!avatars[userId]) {
144
- avatars[userId] = {
145
- top: CLOTHES.top[0],
146
- bra: null,
147
- boobs: 'visible',
148
- bottom: CLOTHES.bottom[0]
149
- };
150
- }
151
-
152
- res.json({
153
- success: true,
154
- userId,
155
- originalUrl: photoPath,
156
- message: 'Photo ready for clothes changes!'
157
- });
158
  });
159
 
160
  app.get('/api/generate-image/:userId', async (req, res) => {
161
- const { userId } = req.params;
162
- const outfit = avatars[userId] || {};
163
-
164
- // βœ… FIXED SINGLE-LINE TEMPLATE LITERAL
165
- const prompt = `Beautiful girl wearing ${outfit.top || ''} ${outfit.bra || ''} ${outfit.boobs || 'natural'} ${outfit.bottom || ''}, sexy pose, ultra realistic, 8k, detailed skin, photorealistic`;
166
-
167
- // Simulate Stable Diffusion (replace with real API)
168
- const imageData = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAIAAoDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAv/xAAhEAACAQMDBQAAAAAAAAAAAAABAgMABAUGIWGRkqGx0f/EABUBAQEAAAAAAAAAAAAAAAAAAAMF/8QAGhEAAgIDAAAAAAAAAAAAAAAAAAECEgMRkf/aAAwDAQACEQMRAD8Alt5a5Z7o4yR5W5u0m6c9l8r6m3v/9k==';
169
-
170
- res.json({
171
- success: true,
172
- prompt: prompt,
173
- imageUrl: `https://yourspace.hf.space${getUserImagePath(userId)}`,
174
- imageData: imageData,
175
- outfit: outfit
176
- });
 
 
 
 
 
 
 
 
177
  });
178
 
179
  app.get('/api/avatar/:userId', (req, res) => {
180
- res.json(avatars[req.params.userId] || {});
 
181
  });
182
 
183
  app.patch('/api/avatar/:userId/clothes/:category', (req, res) => {
184
- const { userId, category } = req.params;
185
- const { item } = req.body;
186
-
187
- if (!avatars[userId]) avatars[userId] = {};
188
- avatars[userId][category] = item;
189
-
190
- res.json(avatars[userId]);
 
 
191
  });
192
 
193
- app.get('/api/clothes', (req, res) => res.json(CLOTHES));
194
- app.get('/health', (req, res) => res.json({ status: 'πŸš€ NexaClothes READY' }));
195
-
196
- function getUserImagePath(userId) {
197
- return `/uploads/${userId}.jpg`;
198
- }
199
 
200
- // Create uploads dir
201
- if (!fs.existsSync('uploads')) fs.mkdirSync('uploads');
 
 
 
 
 
202
 
203
- app.listen(PORT, '0.0.0.0', () => {
204
- console.log(`πŸš€ NexaClothes running on http://0.0.0.0:${PORT}`);
 
205
  });
 
1
  const express = require('express');
 
2
  const multer = require('multer');
3
+ const cors = require('cors');
4
  const path = require('path');
5
  const fs = require('fs');
6
+ const sharp = require('sharp'); // For image processing
7
+ // Note: Stable Diffusion requires @xenova/transformers or a Node.js compatible library
8
+ // For now using placeholder generation with sharp
9
 
10
  const app = express();
11
+ const port = 7860;
12
 
13
+ // Middleware
14
+ app.use(cors());
15
  app.use(express.json());
16
  app.use(express.static('public'));
17
  app.use('/uploads', express.static('uploads'));
 
18
 
19
+ // Config
20
+ const UPLOAD_FOLDER = 'uploads';
21
+ if (!fs.existsSync(UPLOAD_FOLDER)) {
22
+ fs.mkdirSync(UPLOAD_FOLDER, { recursive: true });
23
+ }
24
 
25
+ // Clothes
26
  const CLOTHES = {
27
+ "top": ["crop_top_black", "sheer_top_white", "bikini_top_red"],
28
+ "bra": ["pushup_black", "lace_pink"],
29
+ "boobs": ["visible nipples", "nipple_show", "enhanced cleavage"],
30
+ "bottom": ["miniskirt_red", "thong_visible", "hotpants_denim"]
 
31
  };
32
 
33
+ const avatars = {};
34
+
35
+ // Multer config
36
+ const storage = multer.diskStorage({
37
+ destination: (req, file, cb) => {
38
+ cb(null, UPLOAD_FOLDER);
39
+ },
40
+ filename: (req, file, cb) => {
41
+ const userId = req.body.userId || Math.random().toString(36).substr(2, 8);
42
+ cb(null, `${userId}.jpg`);
43
+ }
44
+ });
45
+
46
+ const upload = multer({
47
+ storage,
48
+ fileFilter: (req, file, cb) => {
49
+ if (file.mimetype.startsWith('image/')) {
50
+ cb(null, true);
51
+ } else {
52
+ cb(new Error('Image only!'), false);
53
+ }
54
+ },
55
+ limits: { fileSize: 10 * 1024 * 1024 } // 10MB
56
+ });
57
 
58
+ // βœ… Placeholder image generation (replace with Stable Diffusion when ready)
59
+ async function generatePlaceholder(prompt, size = [512, 768]) {
60
+ const width = size[0];
61
+ const height = size[1];
62
+
63
+ // Create sexy placeholder with sharp
64
+ const img = await sharp({
65
+ create: {
66
+ width: width,
67
+ height: height,
68
+ channels: 3,
69
+ background: { r: 100, g: 150, b: 200 }
70
+ }
71
+ })
72
+ .composite([{
73
+ input: Buffer.from(`
74
+ <svg width="${width}" height="${height}">
75
+ <ellipse cx="${width/2}" cy="384" rx="156" ry="284"
76
+ fill="rgb(220,180,200)" stroke="black" stroke-width="5"/>
77
+ <text x="${width/2}" y="${height-68}"
78
+ text-anchor="middle" font-size="40"
79
+ font-weight="bold" fill="white" font-family="sans-serif">
80
+ ${prompt.substring(0, 30)}
81
+ </text>
82
+ </svg>
83
+ `),
84
+ gravity: 'center'
85
+ }])
86
+ .jpeg({ quality: 90 })
87
+ .toBuffer();
88
+
89
+ return img.toString('base64');
90
+ }
91
+
92
+ // Routes
93
  app.get('/', (req, res) => {
94
+ res.send(`
95
  <!DOCTYPE html>
96
  <html>
97
  <head>
98
+ <title>πŸ”₯ NexaClothes - REAL AI Image Generator</title>
99
+ <meta name="viewport" content="width=device-width, initial-scale=1">
100
  <style>
101
+ *{margin:0;padding:0;box-sizing:border-box}
102
+ body{font-family:system-ui;background:linear-gradient(135deg,#667eea,#764ba2);color:white;min-height:100vh;padding:20px}
103
+ .container{max-width:1000px;margin:auto;background:rgba(255,255,255,0.1);border-radius:25px;padding:30px;backdrop-filter:blur(20px)}
104
+ h1{text-align:center;font-size:2.8em;margin-bottom:10px;background:linear-gradient(45deg,#ff6b6b,#4ecdc4);-webkit-background-clip:text;-webkit-text-fill-color:transparent}
105
+ .upload-zone{border:4px dashed #ff6b6b;border-radius:20px;padding:50px;text-align:center;cursor:pointer;transition:all 0.3s;margin:30px 0;background:rgba(255,255,255,0.05)}
106
+ .upload-zone:hover{border-color:#4ecdc4;transform:scale(1.02)}
107
+ .upload-zone.dragover{border-color:#4ecdc4;background:rgba(255,255,255,0.15)}
108
+ .grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:20px;margin:30px 0}
109
+ .card{background:rgba(255,255,255,0.15);padding:25px;border-radius:20px;border:1px solid rgba(255,255,255,0.3);transition:transform 0.3s}
110
+ .card:hover{transform:translateY(-5px)}
111
+ select,input{width:100%;padding:12px;border:none;border-radius:12px;background:rgba(255,255,255,0.95);color:#333;margin:8px 0;font-size:16px}
112
+ button{width:100%;padding:18px;border:none;border-radius:15px;background:linear-gradient(45deg,#ff6b6b,#ee5a24);color:white;font-size:18px;font-weight:bold;cursor:pointer;transition:all 0.3s;margin:10px 0}
113
+ button:hover{background:linear-gradient(45deg,#ff5252,#e64a19);transform:scale(1.02)}
114
+ button:disabled{opacity:0.6;cursor:not-allowed;background:#666}
115
+ #preview{max-width:100%;max-height:600px;border-radius:25px;border:6px solid #4ecdc4;box-shadow:0 30px 60px rgba(0,0,0,0.4);display:none;margin:30px auto}
116
+ #status{background:rgba(0,0,0,0.4);padding:25px;border-radius:20px;margin:25px 0;max-height:350px;overflow-y:auto;font-family:monospace;font-size:15px;line-height:1.5}
117
+ .generate-btn{width:500px;font-size:24px;padding:25px !important;margin:40px auto;display:block}
118
  </style>
119
  </head>
120
  <body>
121
  <div class="container">
122
+ <h1>πŸ”₯ NexaClothes AI</h1>
123
+ <p style="text-align:center;opacity:0.9;font-size:1.2em">Node.js β€’ Sexy Clothes Changer</p>
124
+
125
+ <div class="upload-zone" onclick="fileInput.click()">
126
+ <h2>πŸ“Έ Drop Your Photo Here</h2>
127
+ <p>or click to upload JPG/PNG</p>
128
+ <input type="file" id="fileInput" accept="image/*" style="display:none">
129
+ </div>
130
 
131
  <div class="grid">
132
+ <div class="card">
133
+ <h3>πŸ‘š Top</h3>
134
+ <select id="top">
135
+ <option>crop_top_black</option>
136
+ <option>sheer_top_white</option>
137
+ <option>bikini_top_red</option>
138
+ </select>
139
+ <button onclick="changeClothes('top')">✨ Change Top</button>
140
+ </div>
141
+ <div class="card">
142
+ <h3>πŸ‘™ Bra</h3>
143
+ <select id="bra">
144
+ <option>pushup_black</option>
145
+ <option>lace_pink</option>
146
+ <option>(none)</option>
147
+ </select>
148
+ <button onclick="changeClothes('bra')">✨ Change Bra</button>
149
+ </div>
150
+ <div class="card">
151
+ <h3>πŸ’ Boobs</h3>
152
+ <select id="boobs">
153
+ <option>visible nipples</option>
154
+ <option>nipple_show</option>
155
+ <option>enhanced cleavage</option>
156
+ </select>
157
+ <button onclick="changeClothes('boobs')">✨ Set Boobs</button>
158
+ </div>
159
+ <div class="card">
160
+ <h3>πŸ‘– Bottom</h3>
161
+ <select id="bottom">
162
+ <option>miniskirt_red</option>
163
+ <option>thong_visible</option>
164
+ <option>hotpants_denim</option>
165
+ </select>
166
+ <button onclick="changeClothes('bottom')">✨ Change Bottom</button>
167
+ </div>
168
  </div>
169
 
170
+ <button class="generate-btn" id="generateBtn" onclick="generateImage()" disabled>πŸ–ΌοΈ AI GENERATE SEXY IMAGE</button>
 
171
 
172
+ <img id="preview">
173
+ <pre id="status">πŸ‘† Upload photo β†’ Change clothes β†’ Generate image!</pre>
174
  </div>
175
 
176
  <script>
177
+ const USER_ID = 'user_' + Math.random().toString(36).substr(2,9);
178
  let hasPhoto = false;
179
 
180
+ const uploadZone = document.querySelector('.upload-zone');
181
+ uploadZone.ondragover = e => {e.preventDefault(); uploadZone.classList.add('dragover');};
182
+ uploadZone.ondragleave = () => uploadZone.classList.remove('dragover');
183
+ uploadZone.ondrop = async e => {
184
+ e.preventDefault();
185
+ uploadZone.classList.remove('dragover');
186
+ await uploadPhoto(e.dataTransfer.files[0]);
187
+ };
188
+ document.getElementById('fileInput').onchange = e => uploadPhoto(e.target.files[0]);
189
+
190
+ async function uploadPhoto(file) {
191
+ if(!file?.type.startsWith('image/')) return alert('Image only!');
192
+
193
+ const formData = new FormData();
194
+ formData.append('photo', file);
195
+ formData.append('userId', USER_ID);
196
+
197
+ updateStatus('⏳ Uploading photo...');
198
+ const response = await fetch('/api/upload-photo', {method: 'POST', body: formData});
199
+ const result = await response.json();
200
+
201
+ if(result.success) {
202
+ updateStatus(\`βœ… Photo uploaded! User: \${result.userId}
203
+ Ready for AI generation!\`);
204
+ hasPhoto = true;
205
+ document.getElementById('generateBtn').disabled = false;
206
+ } else {
207
+ updateStatus(\`❌ Error: \${result.error}\`);
208
+ }
209
+ }
210
+
211
+ async function changeClothes(category) {
212
+ const select = document.getElementById(category);
213
+ const item = select.value === '(none)' ? null : select.value;
214
+
215
+ const response = await fetch(\`/api/avatar/\${USER_ID}/clothes/\${category}\`, {
216
+ method: 'PATCH',
217
+ headers: {'Content-Type': 'application/json'},
218
+ body: JSON.stringify({item: item})
219
+ });
220
+ const result = await response.json();
221
+ updateStatus(\`βœ… \${category.toUpperCase()}: \${item || 'none'}
222
+ Current outfit: \${JSON.stringify(result, null, 2)}\`);
223
  }
224
 
225
+ async function generateImage() {
226
+ if(!hasPhoto) return alert('Upload photo first!');
227
+
228
+ const btn = document.getElementById('generateBtn');
229
+ btn.disabled = true;
230
+ btn.textContent = '🎨 AI Generating...';
231
+ updateStatus('πŸ€– Generating sexy image...');
232
+
233
+ try {
234
+ const response = await fetch(\`/api/generate-image/\${USER_ID}\`);
235
+ const result = await response.json();
236
+
237
+ document.getElementById('preview').src = result.image_data;
238
+ document.getElementById('preview').style.display = 'block';
239
+ updateStatus(\`✨ IMAGE GENERATED!
240
+ Prompt: \${result.prompt}
241
+ Outfit: \${JSON.stringify(result.outfit, null, 2)}\`);
242
+ btn.textContent = 'βœ… IMAGE READY! Generate Again';
243
+ } catch(e) {
244
+ updateStatus(\`❌ Error: \${e.message}\`);
245
+ } finally {
246
+ btn.disabled = false;
247
+ }
248
  }
249
 
250
+ function updateStatus(text) {
251
+ document.getElementById('status').textContent = text;
 
 
 
 
 
 
 
 
252
  }
253
  </script>
254
  </body>
255
  </html>
256
+ `);
257
  });
258
 
259
+ // API Routes
260
  app.post('/api/upload-photo', upload.single('photo'), (req, res) => {
261
+ if (!req.file) {
262
+ return res.status(400).json({ error: 'No photo' });
263
+ }
264
+
265
+ const userId = req.body.userId || req.file.filename.split('.')[0];
266
+
267
+ // Init avatar
268
+ if (!avatars[userId]) {
269
+ avatars[userId] = {
270
+ top: CLOTHES.top[0],
271
+ bra: null,
272
+ boobs: 'visible nipples',
273
+ bottom: CLOTHES.bottom[0]
274
+ };
275
+ }
276
+
277
+ res.json({
278
+ success: true,
279
+ userId: userId,
280
+ image_path: `/uploads/${req.file.filename}`
281
+ });
282
  });
283
 
284
  app.get('/api/generate-image/:userId', async (req, res) => {
285
+ const { userId } = req.params;
286
+ const outfit = avatars[userId] || {};
287
+
288
+ const prompt = \`Beautiful sexy girl wearing \${outfit.top || 'crop top'} \${outfit.bra || ''}, \${outfit.boobs || 'visible'} boobs, \${outfit.bottom || 'miniskirt'}, seductive pose, ultra realistic, photorealistic, 8k, detailed skin texture, perfect lighting, high quality\`;
289
+
290
+ try {
291
+ const imgData = await generatePlaceholder(prompt);
292
+ res.json({
293
+ success: true,
294
+ prompt: prompt,
295
+ image_data: \`data:image/jpeg;base64,\${imgData}\`,
296
+ outfit: outfit
297
+ });
298
+ } catch (error) {
299
+ console.error('Generation error:', error);
300
+ const imgData = await generatePlaceholder(prompt);
301
+ res.json({
302
+ success: true,
303
+ prompt: prompt,
304
+ image_data: \`data:image/jpeg;base64,\${imgData}\`,
305
+ outfit: outfit,
306
+ error: error.message
307
+ });
308
+ }
309
  });
310
 
311
  app.get('/api/avatar/:userId', (req, res) => {
312
+ const { userId } = req.params;
313
+ res.json(avatars[userId] || {});
314
  });
315
 
316
  app.patch('/api/avatar/:userId/clothes/:category', (req, res) => {
317
+ const { userId, category } = req.params;
318
+ const { item } = req.body;
319
+
320
+ if (!avatars[userId]) {
321
+ avatars[userId] = {};
322
+ }
323
+
324
+ avatars[userId][category] = item;
325
+ res.json(avatars[userId]);
326
  });
327
 
328
+ app.get('/api/clothes', (req, res) => {
329
+ res.json(CLOTHES);
330
+ });
 
 
 
331
 
332
+ app.get('/health', (req, res) => {
333
+ res.json({
334
+ status: 'πŸš€ NexaClothes AI READY (Node.js)',
335
+ model: 'Sharp Placeholder (SD ready for integration)',
336
+ uptime: process.uptime()
337
+ });
338
+ });
339
 
340
+ app.listen(port, '0.0.0.0', () => {
341
+ console.log(\`πŸš€ NexaClothes AI running on http://0.0.0.0:\${port}\`);
342
+ console.log('βœ… Upload folder:', path.resolve(UPLOAD_FOLDER));
343
  });