Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric committed Apr 28, 2023
1 parent c2777de commit ae04c21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# ---- Production ----
FROM node:18-alpine AS production
WORKDIR /dist
COPY .next .
COPY public .
COPY package*.json .
COPY next.config.js .

COPY .next ./.next
COPY public ./public
COPY package*.json ./
COPY next.config.js ./next.config.js
# use npm ci for production
RUN npm install --omit=dev
# Expose the port the app will run on
EXPOSE 3000
Expand Down
38 changes: 21 additions & 17 deletions request/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { MJMessage } from "midjourney";

const streamFetch = (url: string, body: string ,loading?: (uri: MJMessage) => void) => {
const streamFetch = (
url: string,
body: string,
loading?: (uri: MJMessage) => void
) => {
return fetch(url, {
method: 'POST',
method: "POST",
headers: {
'Content-type': 'application/json',
"Content-type": "application/json",
},
body,
}) .then(async (response) => {
}).then(async (response) => {
const reader = response.body?.getReader();
if (reader) {
console.log('Response body is not null');
// console.log('Response body is not null');
while (true) {
const { done, value } = await reader.read();
if (done) {
Expand All @@ -19,22 +23,22 @@ const streamFetch = (url: string, body: string ,loading?: (uri: MJMessage) => vo
//Uint8Array to string
const str = new TextDecoder("utf-8").decode(value);
console.log(str);
loading &&loading(JSON.parse(str))
loading && loading(JSON.parse(str));
}
} else {
console.log('Response body is null');
console.log("Response body is null");
}
});
}
};

export const Imagine = (body: string,loading?: (uri: MJMessage) => void) =>{
return streamFetch('api/imagine',body,loading)
}
export const Imagine = (body: string, loading?: (uri: MJMessage) => void) => {
return streamFetch("api/imagine", body, loading);
};

export const Upscale = (body: string,loading?: (uri: MJMessage) => void) =>{
return streamFetch('api/upscale',body,loading)
}
export const Upscale = (body: string, loading?: (uri: MJMessage) => void) => {
return streamFetch("api/upscale", body, loading);
};

export const Variation = (body: string,loading?: (uri: MJMessage) => void) =>{
return streamFetch('api/upscale',body,loading)
}
export const Variation = (body: string, loading?: (uri: MJMessage) => void) => {
return streamFetch("api/upscale", body, loading);
};

1 comment on commit ae04c21

@vercel
Copy link

@vercel vercel bot commented on ae04c21 Apr 28, 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.