Update plugins/fluxai.js
Browse files- plugins/fluxai.js +35 -13
plugins/fluxai.js
CHANGED
@@ -32,35 +32,57 @@ async function schellwithflux(args) {
|
|
32 |
* @swagger
|
33 |
* tags:
|
34 |
* name: FLUX
|
35 |
-
* description:
|
36 |
*/
|
37 |
|
38 |
/**
|
39 |
* @swagger
|
40 |
-
* /api/v1/
|
41 |
-
*
|
42 |
-
* summary:
|
43 |
* tags: [FLUX]
|
44 |
-
* description: This endpoint interacts with
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
*/
|
46 |
FluxRoutes.post("/api/v1/fluxai-ai", async (req, res) => {
|
47 |
try {
|
48 |
const query = req.body.query;
|
49 |
-
const imageBytes = await schellwithflux(query);
|
50 |
if (!query) {
|
51 |
-
|
52 |
}
|
|
|
|
|
53 |
if (!imageBytes) {
|
54 |
return res.status(500).json({ error: "Failed to fetch image bytes" });
|
55 |
}
|
|
|
56 |
const buffer = Buffer.isBuffer(imageBytes) ? imageBytes : Buffer.from(imageBytes);
|
57 |
-
|
58 |
-
const processedImage = await sharp(buffer)
|
59 |
-
|
60 |
-
.toBuffer();
|
61 |
res.set("Content-Type", "image/jpeg");
|
62 |
-
|
63 |
-
stream.pipe(res);
|
64 |
} catch (error) {
|
65 |
console.error("Error processing image:", error.message);
|
66 |
res.status(500).json({ error: "Internal server error" });
|
|
|
32 |
* @swagger
|
33 |
* tags:
|
34 |
* name: FLUX
|
35 |
+
* description: Flux AI image generation endpoints.
|
36 |
*/
|
37 |
|
38 |
/**
|
39 |
* @swagger
|
40 |
+
* /api/v1/fluxai-ai:
|
41 |
+
* post:
|
42 |
+
* summary: Generate an image using Flux AI.
|
43 |
* tags: [FLUX]
|
44 |
+
* description: This endpoint interacts with Flux AI to generate an image based on the query.
|
45 |
+
* requestBody:
|
46 |
+
* required: true
|
47 |
+
* content:
|
48 |
+
* application/json:
|
49 |
+
* schema:
|
50 |
+
* type: object
|
51 |
+
* properties:
|
52 |
+
* query:
|
53 |
+
* type: string
|
54 |
+
* description: The input query for image generation.
|
55 |
+
* responses:
|
56 |
+
* 200:
|
57 |
+
* description: A successfully processed image.
|
58 |
+
* content:
|
59 |
+
* image/jpeg:
|
60 |
+
* schema:
|
61 |
+
* type: string
|
62 |
+
* format: binary
|
63 |
+
* 400:
|
64 |
+
* description: Missing query parameter.
|
65 |
+
* 500:
|
66 |
+
* description: Internal server error.
|
67 |
*/
|
68 |
FluxRoutes.post("/api/v1/fluxai-ai", async (req, res) => {
|
69 |
try {
|
70 |
const query = req.body.query;
|
|
|
71 |
if (!query) {
|
72 |
+
return res.status(400).send("Query parameter is missing");
|
73 |
}
|
74 |
+
|
75 |
+
const imageBytes = await schellwithflux(query);
|
76 |
if (!imageBytes) {
|
77 |
return res.status(500).json({ error: "Failed to fetch image bytes" });
|
78 |
}
|
79 |
+
|
80 |
const buffer = Buffer.isBuffer(imageBytes) ? imageBytes : Buffer.from(imageBytes);
|
81 |
+
|
82 |
+
const processedImage = await sharp(buffer).jpeg().toBuffer();
|
83 |
+
|
|
|
84 |
res.set("Content-Type", "image/jpeg");
|
85 |
+
Readable.from(processedImage).pipe(res);
|
|
|
86 |
} catch (error) {
|
87 |
console.error("Error processing image:", error.message);
|
88 |
res.status(500).json({ error: "Internal server error" });
|