uniderp-mcp
Version:
> A plug-and-play MCP tool server to **send ETH**, **transfer ERC-20 tokens**, **deploy tokens**, and **interact with smart contracts** on the **UNICHAIN** — built for **Claude Desktop**, **AI agents**, and **developers.**
45 lines (44 loc) • 1.62 kB
JavaScript
import sharp from "sharp";
async function resizeBase64Image({ base64Image, width, height, }) {
const imageData = base64Image;
const imgBuffer = Buffer.from(imageData, "base64");
const resizedImageBuffer = await sharp(imgBuffer)
.resize(width ?? 256, height ?? 256)
.toBuffer();
return resizedImageBuffer.toString("base64");
}
export async function genImg(prompt) {
const CLOUDFLARE_API_TOKEN = "fj5Zy0HsyHseigLBmP1fIAdlsN9LqFthvK1x9f4_";
const CLOUDFLARE_ACCOUNT_ID = "98cf0ec0bca1bd6038bba13df097d5a8";
const MODEL = "@cf/black-forest-labs/flux-1-schnell";
const url = `https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/run/${MODEL}`;
const headers = {
Authorization: `Bearer ${CLOUDFLARE_API_TOKEN}`,
"Content-Type": "application/json",
};
const body = JSON.stringify({
prompt,
// height: 256,
// width: 256,
});
// @cf/black-forest-labs/flux-1-schnell
const data = await fetch(url, {
method: "POST",
headers,
body,
}).then((res) => res.json());
return resizeBase64Image({ base64Image: data.result.image });
// @cf/stabilityai/stable-diffusion-xl-base-1.0
// const response = await fetch(url, {
// method: "POST",
// headers,
// body,
// });
// const arrayBuffer = await response.arrayBuffer();
// const base64String = btoa(
// String.fromCharCode(...new Uint8Array(arrayBuffer))
// );
// const dataUrl = `data:image/png;base64,${base64String}`;
// console.log(dataUrl);
// return dataUrl;
}