-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from artemptushkin/feature/migrate-to-api-4
Migrate to midjourney-api v.4
- Loading branch information
Showing
7 changed files
with
1,090 additions
and
1,221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,56 @@ | ||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | ||
import { Midjourney } from "midjourney"; | ||
import { ResponseError } from "../../interfaces"; | ||
import {Midjourney} from "midjourney"; | ||
import {ResponseError} from "../../interfaces"; | ||
import {Upscale} from "../../request"; | ||
|
||
export const config = { | ||
runtime: "edge", | ||
runtime: "edge", | ||
}; | ||
|
||
export default async function handler(req: Request) { | ||
const { content, index, msgId, msgHash } = await req.json(); | ||
console.log("upscale.handler", content); | ||
const client = new Midjourney({ | ||
ServerId: <string>process.env.SERVER_ID, | ||
ChannelId: <string>process.env.CHANNEL_ID, | ||
SalaiToken: <string>process.env.SALAI_TOKEN, | ||
HuggingFaceToken: <string>process.env.HUGGINGFACE_TOKEN, | ||
Debug: true, | ||
Ws: process.env.WS === "true", | ||
}); | ||
await client.init(); | ||
const encoder = new TextEncoder(); | ||
const readable = new ReadableStream({ | ||
start(controller) { | ||
console.log("upscale.start", content); | ||
client | ||
.Upscale( | ||
content, | ||
index, | ||
msgId, | ||
msgHash, | ||
(uri: string, progress: string) => { | ||
console.log("upscale.loading", uri); | ||
controller.enqueue( | ||
encoder.encode(JSON.stringify({ uri, progress })) | ||
); | ||
} | ||
) | ||
.then((msg) => { | ||
console.log("upscale.done", msg); | ||
controller.enqueue(encoder.encode(JSON.stringify(msg))); | ||
client.Close(); | ||
controller.close(); | ||
}) | ||
.catch((err: ResponseError) => { | ||
console.log("upscale.error", err); | ||
client.Close(); | ||
controller.close(); | ||
}); | ||
}, | ||
}); | ||
return new Response(readable, {}); | ||
const {content, index, msgId, msgHash, flags} = await req.json(); | ||
console.log("upscale.handler", content); | ||
const client = new Midjourney({ | ||
ServerId: <string>process.env.SERVER_ID, | ||
ChannelId: <string>process.env.CHANNEL_ID, | ||
SalaiToken: <string>process.env.SALAI_TOKEN, | ||
HuggingFaceToken: <string>process.env.HUGGINGFACE_TOKEN, | ||
Debug: true, | ||
Ws: process.env.WS === "true", | ||
}); | ||
await client.init(); | ||
const encoder = new TextEncoder(); | ||
const readable = new ReadableStream({ | ||
start(controller) { | ||
console.log("upscale.start", content); | ||
client | ||
.Upscale( | ||
{ | ||
index, | ||
msgId, | ||
hash: msgHash, | ||
content, | ||
flags, | ||
...(uri: string, progress: string) => { | ||
console.log("upscale.loading", uri); | ||
controller.enqueue( | ||
encoder.encode(JSON.stringify({uri, progress})) | ||
); | ||
} | ||
} | ||
) | ||
.then((msg) => { | ||
console.log("upscale.done", msg); | ||
controller.enqueue(encoder.encode(JSON.stringify(msg))); | ||
client.Close(); | ||
controller.close(); | ||
}) | ||
.catch((err: ResponseError) => { | ||
console.log("upscale.error", err); | ||
client.Close(); | ||
controller.close(); | ||
}); | ||
}, | ||
}); | ||
return new Response(readable, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
31b23f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
midjourney-ui – ./
midjourney-ui.vercel.app
midjourney-ui-erictik.vercel.app
midjourney-ui-git-main-erictik.vercel.app
midjourney.baochi.xin