From 3ff68753eee7522895b979c2e87d895fb33de328 Mon Sep 17 00:00:00 2001 From: chlorine Date: Tue, 16 May 2023 23:52:39 +0800 Subject: [PATCH] fix: add log and fix 400 error in GET /image (#53) --- package.json | 2 +- pnpm-lock.yaml | 155 ++++++++++++++++------------------ src/modules/Content/index.tsx | 10 ++- src/pages/api/images.ts | 14 +-- 4 files changed, 86 insertions(+), 95 deletions(-) diff --git a/package.json b/package.json index 7da49fb..b664857 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8f2ca0f..a6e7e19 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,87 +1,74 @@ -lockfileVersion: '6.0' +lockfileVersion: 5.4 + +specifiers: + '@astrojs/node': ^5.1.1 + '@astrojs/react': ^2.1.0 + '@astrojs/solid-js': ^2.1.0 + '@astrojs/tailwind': ^3.1.1 + '@astrojs/vercel': ^3.2.1 + '@esbuild/darwin-arm64': ^0.16.17 + '@tailwindcss/typography': ^0.5.9 + '@types/lodash-es': ^4.17.7 + '@types/node': ^18.15.3 + '@types/react': ^18.0.28 + '@types/react-dom': ^18.0.11 + '@typescript-eslint/eslint-plugin': ^5.55.0 + '@typescript-eslint/parser': ^5.55.0 + antd: ^5.3.2 + astro: ^2.1.3 + astro-eslint-parser: ^0.12.0 + cross-env: ^7.0.3 + dayjs: ^1.11.7 + eslint: ^8.36.0 + eslint-config-airbnb-base: ^15.0.0 + eslint-config-prettier: ^8.7.0 + eslint-plugin-astro: ^0.25.0 + eslint-plugin-import: ^2.27.5 + eslint-plugin-prettier: ^4.2.1 + eslint-plugin-react: ^7.32.2 + eslint-plugin-react-hooks: ^4.6.0 + eventsource-parser: ^1.0.0 + highlight.js: ^11.7.0 + katex: ^0.16.4 + lint-staged: ^13.2.0 + lodash-es: ^4.17.21 + markdown-it: ^13.0.1 + markdown-it-highlightjs: ^4.0.1 + markdown-it-kbd: ^2.2.2 + midjourney-fetch: 0.1.3 + prettier: ^2.8.4 + prettier-plugin-astro: ^0.8.0 + punycode: ^2.3.0 + react: ^18.0.0 + react-dom: ^18.0.0 + replicate-fetch: ^0.1.1 + simple-git-hooks: ^2.8.1 + solid-js: ^1.6.15 + tailwindcss: ^3.2.7 + typescript: ^4.9.5 + vite-plugin-checker: ^0.5.6 dependencies: - '@ant-design/cssinjs': - specifier: ^1.9.1 - version: 1.9.1(react-dom@18.2.0)(react@18.2.0) - '@astrojs/node': - specifier: ^5.1.1 - version: 5.1.1(astro@2.1.3) - '@astrojs/react': - specifier: ^2.1.0 - version: 2.1.0(@types/react-dom@18.0.11)(@types/react@18.0.28)(react-dom@18.2.0)(react@18.2.0) - '@astrojs/solid-js': - specifier: ^2.1.0 - version: 2.1.0(@babel/core@7.21.3)(solid-js@1.6.15)(vite@4.1.4) - '@astrojs/tailwind': - specifier: ^3.1.1 - version: 3.1.1(astro@2.1.3)(tailwindcss@3.2.7) - '@astrojs/vercel': - specifier: ^3.2.1 - version: 3.2.1(astro@2.1.3)(react@18.2.0) - '@supabase/auth-helpers-nextjs': - specifier: ^0.6.1 - version: 0.6.1(@supabase/supabase-js@2.21.0) - '@supabase/supabase-js': - specifier: ^2.21.0 - version: 2.21.0 - antd: - specifier: ^5.3.2 - version: 5.3.2(react-dom@18.2.0)(react@18.2.0) - astro: - specifier: ^2.1.3 - version: 2.1.3(@types/node@18.15.3) - dayjs: - specifier: ^1.11.7 - version: 1.11.7 - event-target-polyfill: - specifier: ^0.0.3 - version: 0.0.3 - eventsource-parser: - specifier: ^1.0.0 - version: 1.0.0 - gpt3-tokenizer: - specifier: ^1.1.5 - version: 1.1.5 - highlight.js: - specifier: ^11.7.0 - version: 11.7.0 - katex: - specifier: ^0.16.4 - version: 0.16.4 - lodash-es: - specifier: ^4.17.21 - version: 4.17.21 - markdown-it: - specifier: ^13.0.1 - version: 13.0.1 - markdown-it-highlightjs: - specifier: ^4.0.1 - version: 4.0.1 - markdown-it-kbd: - specifier: ^2.2.2 - version: 2.2.2 - midjourney-fetch: - specifier: 0.1.2 - version: 0.1.2 - react: - specifier: ^18.0.0 - version: 18.2.0 - react-dom: - specifier: ^18.0.0 - version: 18.2.0(react@18.2.0) - replicate-fetch: - specifier: ^0.1.1 - version: 0.1.1 - solid-js: - specifier: ^1.6.15 - version: 1.6.15 - stripe: - specifier: ^12.3.0 - version: 12.3.0 - swr: - specifier: ^2.1.5 - version: 2.1.5(react@18.2.0) + '@astrojs/node': 5.1.1_astro@2.1.3 + '@astrojs/react': 2.1.0_3xleytyzprlgycb2ded54tx72i + '@astrojs/solid-js': 2.1.0_7uigyi4tkcw6gykyu6d63dasc4 + '@astrojs/tailwind': 3.1.1_2l4ywwlgzw2satesmi43zum3jy + '@astrojs/vercel': 3.2.1_astro@2.1.3+react@18.2.0 + antd: 5.3.2_biqbaboplfbrettd7655fr4n2y + astro: 2.1.3_@types+node@18.15.3 + dayjs: 1.11.7 + eventsource-parser: 1.0.0 + highlight.js: 11.7.0 + katex: 0.16.4 + lodash-es: 4.17.21 + markdown-it: 13.0.1 + markdown-it-highlightjs: 4.0.1 + markdown-it-kbd: 2.2.2 + midjourney-fetch: 0.1.3 + react: 18.2.0 + react-dom: 18.2.0_react@18.2.0 + replicate-fetch: 0.1.1 + solid-js: 1.6.15 devDependencies: '@esbuild/darwin-arm64': @@ -4272,8 +4259,8 @@ packages: braces: 3.0.2 picomatch: 2.3.1 - /midjourney-fetch@0.1.2: - resolution: {integrity: sha512-iORjqkMckpdS79YCNVSQc0Z89fBGgYFU3CCFUNrYaKQea3304A6iCO4KnPQsY7a6XgGNbKHi0m+L2ROJqVVyRA==} + /midjourney-fetch/0.1.3: + resolution: {integrity: sha512-2MqBCGZH7ay4I1b+7RQkhRIxWs+YyN5umP/WJy84MzJtTc+Vf18uENYYK7KK4/fx1G3tCvYA1yncJ9jCjzv6JA==} engines: {node: '>=18', pnpm: '>=8'} dev: false diff --git a/src/modules/Content/index.tsx b/src/modules/Content/index.tsx index bda4c88..be40f6a 100644 --- a/src/modules/Content/index.tsx +++ b/src/modules/Content/index.tsx @@ -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'; @@ -240,16 +241,19 @@ const Content: FC = ({ 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; } } diff --git a/src/pages/api/images.ts b/src/pages/api/images.ts index 59d6c32..325a480 100644 --- a/src/pages/api/images.ts +++ b/src/pages/api/images.ts @@ -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, @@ -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') { @@ -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, @@ -204,4 +202,6 @@ export const post: APIRoute = withPriceModel(async ({ request }) => { status: 500, }); } -}); +}; + +export const post = withPriceModel(originalPost);