File size: 2,091 Bytes
2eb85f7 8a5ae92 1536d2b 2eb85f7 4192ae2 5a03baf 4192ae2 2eb85f7 235ac5c 2eb85f7 235ac5c 2eb85f7 7d77877 2eb85f7 902ac08 1536d2b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import fetch from "node-fetch";
import * as config from './config.js';
const FluxRoutes = express.Router();
/**
* @param {string} args - The input string
*/
async function schellwithflux(args) {
const EncodeBaseUrl = "aHR0cHM6Ly9hcGktaW5mZXJlbmNlLmh1Z2dpbmdmYWNlLmNvL21vZGVscy9ibGFjay1mb3Jlc3QtbGFicy9GTFVYLjEtc2NobmVsbA==";
try {
const response = await fetch(atob(EncodeBaseUrl), {
method: "POST",
headers: {
"Authorization": `Bearer ${config.HUGGING_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ inputs: args }),
});
if (!response.ok) {
console.error(`API Error: ${response.status}`);
return null;
}
return await response.arrayBuffer();
} catch (error) {
console.error("Error fetching data:", error.message);
return null;
}
}
/**
* @swagger
* tags:
* name: FLUX
* description: etc
*/
/**
* @swagger
* /api/v1/flux-ai:
* get:
* summary: Get a generator image from Flux AI image
* tags: [FLUX]
* description: This endpoint interacts with the Flux AI
*/
FluxRoutes.post("/api/v1/fluxai-ai", async (req, res) => {
try {
const query = req.body.query;
const imageBytes = await schellwithflux(query);
if (!query) {
return res.status(400).send('Query parameter is missing');
}
if (!imageBytes) {
return res.status(500).json({ error: "Failed to fetch image bytes" });
}
const buffer = Buffer.isBuffer(imageBytes) ? imageBytes : Buffer.from(imageBytes);
const processedImage = await sharp(buffer)
.jpeg()
.toBuffer();
res.set("Content-Type", "image/jpeg");
const stream = Readable.from(processedImage);
stream.pipe(res);
} catch (error) {
console.error("Error processing image:", error.message);
res.status(500).json({ error: "Internal server error" });
}
});
export { FluxRoutes }; |