Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric committed Apr 29, 2023
1 parent 26021ea commit f451f22
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions pages/api/imagine.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { Midjourney } from "midjourney";
import type { NextApiRequest, NextApiResponse } from "next";
import { ResponseError } from "../../interfaces";
import { Readable } from "stream";

export const config = {
runtime: "edge",
};
Expand All @@ -12,14 +9,14 @@ const client = new Midjourney(
<string>process.env.CHANNEL_ID,
<string>process.env.SALAI_TOKEN
);
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { prompt } = req.body;
const handler = async (req: Request) => {
const { prompt } = await req.json();
console.log("imagine.handler", prompt);
const encoder = new TextEncoder();
const readable = new ReadableStream({
start(controller) {
console.log("imagine.start", prompt);
console.log("ReadableStream", ReadableStream);
client
.Imagine(prompt, (uri: string) => {
console.log("imagine.loading", uri);
Expand All @@ -37,4 +34,5 @@ export default async function handler(
},
});
return new Response(readable, {});
}
};
export default handler;

1 comment on commit f451f22

@vercel
Copy link

@vercel vercel bot commented on f451f22 Apr 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.