replicate-flux-mcp
Version:
MCP for Replicate Flux Model
34 lines (33 loc) • 963 B
JavaScript
export function mimeFor(format) {
return format === "jpg" ? "image/jpeg" : `image/${format}`;
}
async function fetchWithAuth(url) {
return fetch(url, {
headers: { Authorization: `Bearer ${process.env.REPLICATE_API_TOKEN}` },
});
}
export async function outputToBase64(output) {
const blob = await output.blob();
const buffer = Buffer.from(await blob.arrayBuffer());
return buffer.toString("base64");
}
export async function urlToSvg(url) {
try {
const response = await fetchWithAuth(url);
return response.text();
}
catch {
throw new Error("Error fetching svg");
}
}
export async function urlToBase64(url) {
try {
const response = await fetchWithAuth(url);
const blob = await response.blob();
const buffer = Buffer.from(await blob.arrayBuffer());
return buffer.toString("base64");
}
catch {
throw new Error("Error fetching image");
}
}