Skip to content

Commit

Permalink
fix: add log and fix 400 error in GET /image (GPTGenius#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvqq authored and author committed May 18, 2023
1 parent aad975c commit 3ff6875
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 95 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"markdown-it": "^13.0.1",
"markdown-it-highlightjs": "^4.0.1",
"markdown-it-kbd": "^2.2.2",
"midjourney-fetch": "0.1.2",
"midjourney-fetch": "0.1.3",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"replicate-fetch": "^0.1.1",
Expand Down
155 changes: 71 additions & 84 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/modules/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { FC, useContext, useEffect, useState } from 'react';
import MessageBox from '@components/MessageBox';
import { Message, ReactSetState } from '@interfaces';
Expand Down Expand Up @@ -240,16 +241,19 @@ const Content: FC<ContentProps> = ({ setActiveSetting }) => {
await new Promise((resp) =>
setTimeout(resp, midjourneyConfigs.interval)
);
const message: MessageItem = await (
const message: MessageItem & { msg?: string } = await (
await fetch(
`/api/images?model=Midjourney&prompt=${content}&serverId=${configs.discordServerId}&channelId=${configs.discordChannelId}&token=${configs.discordToken}`
)
).json();
if (message && !isInProgress(message)) {
console.log(count, JSON.stringify(message));
// msg means error message
if (message && !message.msg && !isInProgress(message)) {
[image] = message.attachments;
break;
}
} catch {
} catch (e) {
console.log(count, e.message || e.stack || e);
continue;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/pages/api/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import type { APIRoute } from 'astro';
import { loadBalancer } from '@utils/server';
import { createOpenjourney } from 'replicate-fetch';
import { SupportedImageModels } from '@configs';
import { withPriceModel } from '@utils/priceModel';

import { Midjourney, findMessageByPrompt } from 'midjourney-fetch';
import {
apiKeyStrategy,
Expand All @@ -19,14 +17,14 @@ import {

export { config };

export const get: APIRoute = withPriceModel(async ({ request }) => {
export const get: APIRoute = async ({ request }) => {
const { url } = request;
const params = new URL(url).searchParams;

const model = params.get('model') as SupportedImageModels;
const serverId = params.get('serverId') ?? dicordServerId;
const channelId = params.get('channelId') ?? discordChannelId;
const token = params.get('token') ?? discordToken;
const token = params.get('discordToken') ?? discordToken;
const prompt = params.get('prompt');

if (model === 'Midjourney') {
Expand Down Expand Up @@ -68,9 +66,9 @@ export const get: APIRoute = withPriceModel(async ({ request }) => {
}

return new Response(JSON.stringify({ data: {} }), { status: 200 });
});
};

export const post: APIRoute = withPriceModel(async ({ request }) => {
export const post: APIRoute = async ({ request }) => {
const body = await request.json();
const {
prompt,
Expand Down Expand Up @@ -204,4 +202,6 @@ export const post: APIRoute = withPriceModel(async ({ request }) => {
status: 500,
});
}
});
};

export const post = withPriceModel(originalPost);

0 comments on commit 3ff6875

Please sign in to comment.