randydev commited on
Commit
1536d2b
·
verified ·
1 Parent(s): a2cef8a

Update plugins/fluxai.js

Browse files
Files changed (1) hide show
  1. plugins/fluxai.js +58 -1
plugins/fluxai.js CHANGED
@@ -1,5 +1,6 @@
1
  import fetch from "node-fetch";
2
  import * as config from './config.js';
 
3
 
4
  /**
5
  * @param {string} args - The input string
@@ -27,4 +28,60 @@ async function schellwithflux(args) {
27
  }
28
  }
29
 
30
- export { schellwithflux };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import fetch from "node-fetch";
2
  import * as config from './config.js';
3
+ const FluxRoutes = express.Router();
4
 
5
  /**
6
  * @param {string} args - The input string
 
28
  }
29
  }
30
 
31
+ /**
32
+ * @swagger
33
+ * tags:
34
+ * name: FLUX
35
+ * description: etc
36
+ */
37
+
38
+ /**
39
+ * @swagger
40
+ * /api/v1/flux-ai:
41
+ * get:
42
+ * summary: Get a generator image from Flux AI image
43
+ * tags: [FLUX]
44
+ * description: This endpoint interacts with the Flux AI
45
+ * parameters:
46
+ * - in: query
47
+ * name: query
48
+ * required: true
49
+ * description: The query to be processed by the Flux AI.
50
+ * schema:
51
+ * type: string
52
+ * 500:
53
+ * description: Internal server error.
54
+ * content:
55
+ * application/json:
56
+ * schema:
57
+ * type: object
58
+ * properties:
59
+ * error:
60
+ * type: string
61
+ * description: Error message.
62
+ */
63
+ FluxRoutes.post("/api/v1/fluxai-ai", async (req, res) => {
64
+ try {
65
+ const query = req.body.query;
66
+ const imageBytes = await schellwithflux(query);
67
+ if (!query) {
68
+ return res.status(400).send('Query parameter is missing');
69
+ }
70
+ if (!imageBytes) {
71
+ return res.status(500).json({ error: "Failed to fetch image bytes" });
72
+ }
73
+ const buffer = Buffer.isBuffer(imageBytes) ? imageBytes : Buffer.from(imageBytes);
74
+
75
+ const processedImage = await sharp(buffer)
76
+ .jpeg()
77
+ .toBuffer();
78
+ res.set("Content-Type", "image/jpeg");
79
+ const stream = Readable.from(processedImage);
80
+ stream.pipe(res);
81
+ } catch (error) {
82
+ console.error("Error processing image:", error.message);
83
+ res.status(500).json({ error: "Internal server error" });
84
+ }
85
+ });
86
+
87
+ export { FluxRoutes };