Spaces:
Running
Running
Removed save file bug
Browse files- next.config.js +1 -11
- pages/api/generate.js +3 -25
- pages/index.js +2 -3
- public/gemini-image-1742315750413.png +3 -0
next.config.js
CHANGED
@@ -1,17 +1,7 @@
|
|
1 |
/** @type {import('next').NextConfig} */
|
2 |
const nextConfig = {
|
3 |
reactStrictMode: true,
|
4 |
-
output: 'standalone'
|
5 |
-
// Ensure no file system writes for image handling
|
6 |
-
images: {
|
7 |
-
unoptimized: true, // Disable Next.js automatic image optimization which writes to disk
|
8 |
-
domains: [], // No external image domains needed as we're using base64
|
9 |
-
remotePatterns: [] // No remote patterns needed
|
10 |
-
},
|
11 |
-
// Additional security measures
|
12 |
-
experimental: {
|
13 |
-
serverComponentsExternalPackages: [] // No external packages that might do file I/O
|
14 |
-
}
|
15 |
};
|
16 |
|
17 |
module.exports = nextConfig;
|
|
|
1 |
/** @type {import('next').NextConfig} */
|
2 |
const nextConfig = {
|
3 |
reactStrictMode: true,
|
4 |
+
output: 'standalone'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
};
|
6 |
|
7 |
module.exports = nextConfig;
|
pages/api/generate.js
CHANGED
@@ -1,6 +1,4 @@
|
|
1 |
import { GoogleGenerativeAI } from "@google/generative-ai";
|
2 |
-
import fs from 'node:fs';
|
3 |
-
import path from 'node:path';
|
4 |
|
5 |
export default async function handler(req, res) {
|
6 |
// Only allow POST requests
|
@@ -9,15 +7,14 @@ export default async function handler(req, res) {
|
|
9 |
}
|
10 |
|
11 |
// Get prompt and drawing from request body
|
12 |
-
const { prompt, drawingData
|
13 |
|
14 |
// Log request details (truncating drawingData for brevity)
|
15 |
console.log("API Request:", {
|
16 |
prompt,
|
17 |
hasDrawingData: !!drawingData,
|
18 |
drawingDataLength: drawingData ? drawingData.length : 0,
|
19 |
-
drawingDataSample: drawingData ? `${drawingData.substring(0, 50)}... (truncated)` : null
|
20 |
-
saveToFile
|
21 |
});
|
22 |
|
23 |
if (!prompt) {
|
@@ -80,26 +77,7 @@ export default async function handler(req, res) {
|
|
80 |
const imageData = part.inlineData.data;
|
81 |
console.log("Received image data, length:", imageData.length);
|
82 |
|
83 |
-
//
|
84 |
-
if (saveToFile) {
|
85 |
-
const publicDir = path.join(process.cwd(), 'public');
|
86 |
-
const fileName = `gemini-image-${Date.now()}.png`;
|
87 |
-
const filePath = path.join(publicDir, fileName);
|
88 |
-
|
89 |
-
// Ensure the directory exists
|
90 |
-
if (!fs.existsSync(publicDir)) {
|
91 |
-
fs.mkdirSync(publicDir, { recursive: true });
|
92 |
-
}
|
93 |
-
|
94 |
-
const buffer = Buffer.from(imageData, 'base64');
|
95 |
-
fs.writeFileSync(filePath, buffer);
|
96 |
-
|
97 |
-
result.fileName = fileName;
|
98 |
-
result.filePath = `/public/${fileName}`;
|
99 |
-
console.log("Saved image to:", filePath);
|
100 |
-
}
|
101 |
-
|
102 |
-
// Always include the base64 data in the response
|
103 |
result.imageData = imageData;
|
104 |
}
|
105 |
}
|
|
|
1 |
import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
|
|
|
2 |
|
3 |
export default async function handler(req, res) {
|
4 |
// Only allow POST requests
|
|
|
7 |
}
|
8 |
|
9 |
// Get prompt and drawing from request body
|
10 |
+
const { prompt, drawingData } = req.body;
|
11 |
|
12 |
// Log request details (truncating drawingData for brevity)
|
13 |
console.log("API Request:", {
|
14 |
prompt,
|
15 |
hasDrawingData: !!drawingData,
|
16 |
drawingDataLength: drawingData ? drawingData.length : 0,
|
17 |
+
drawingDataSample: drawingData ? `${drawingData.substring(0, 50)}... (truncated)` : null
|
|
|
18 |
});
|
19 |
|
20 |
if (!prompt) {
|
|
|
77 |
const imageData = part.inlineData.data;
|
78 |
console.log("Received image data, length:", imageData.length);
|
79 |
|
80 |
+
// Include the base64 data in the response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
result.imageData = imageData;
|
82 |
}
|
83 |
}
|
pages/index.js
CHANGED
@@ -162,8 +162,7 @@ export default function Home() {
|
|
162 |
// Create request payload
|
163 |
const requestPayload = {
|
164 |
prompt,
|
165 |
-
drawingData
|
166 |
-
saveToFile: true
|
167 |
};
|
168 |
|
169 |
// Log the request payload (without the full image data for brevity)
|
@@ -280,7 +279,7 @@ export default function Home() {
|
|
280 |
type="text"
|
281 |
value={prompt}
|
282 |
onChange={(e) => setPrompt(e.target.value)}
|
283 |
-
placeholder="
|
284 |
className="w-full p-3 sm:p-4 pr-12 sm:pr-14 text-sm sm:text-base border-2 border-black bg-white text-gray-800 shadow-sm focus:ring-2 focus:ring-gray-200 focus:outline-none transition-all font-mono"
|
285 |
required
|
286 |
/>
|
|
|
162 |
// Create request payload
|
163 |
const requestPayload = {
|
164 |
prompt,
|
165 |
+
drawingData
|
|
|
166 |
};
|
167 |
|
168 |
// Log the request payload (without the full image data for brevity)
|
|
|
279 |
type="text"
|
280 |
value={prompt}
|
281 |
onChange={(e) => setPrompt(e.target.value)}
|
282 |
+
placeholder="Add your change..."
|
283 |
className="w-full p-3 sm:p-4 pr-12 sm:pr-14 text-sm sm:text-base border-2 border-black bg-white text-gray-800 shadow-sm focus:ring-2 focus:ring-gray-200 focus:outline-none transition-all font-mono"
|
284 |
required
|
285 |
/>
|
public/gemini-image-1742315750413.png
ADDED
![]() |
Git LFS Details
|