diff --git a/README.md b/README.md index 89f7035..37a8226 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,4 @@ pnpm dev ## FAQ - [Error when opening nuxt3 web link in China's QQ application](https://github.com/nuxt/nuxt/issues/24229) +- `ofetch` in QQ browser: [unjs/ofetch#294](https://github.com/unjs/ofetch/issues/294) diff --git a/components/AiPrompt.vue b/components/AiPrompt.vue index 8e9c98f..9e20eb6 100644 --- a/components/AiPrompt.vue +++ b/components/AiPrompt.vue @@ -3,27 +3,28 @@ import consola from 'consola' import { useMagicKeys } from '@vueuse/core' import { config } from '~/config' +import { apiGenerate } from '~/utils' const app = useAppStore() /** * generate sfc 春联 + * not use ofetch see https://github.com/unjs/ofetch/issues/294 */ async function generate() { if (app.loading) return app.loading = true - const data = await $fetch('/api/generate', { - query: { - prompt: app.prompt, - }, + // const data = await $fetch('/api/generate', { + // query: { + // prompt: app.prompt, + // }, + // }) + const data = await apiGenerate({ + prompt: app.prompt, }) - consola.info(data) - if (data) { - // TODO: add 生成失败提示 - app.setCoupletsData(data) - } + app.setCoupletsData(data) app.loading = false } diff --git a/package.json b/package.json index 5174ec8..e34ed05 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "typecheck": "vue-tsc --noEmit" }, "dependencies": { + "ofetch": "1.2.1", "wc-github-corners": "^0.1.6" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6633b93..3c01c72 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + ofetch: + specifier: 1.2.1 + version: 1.2.1 wc-github-corners: specifier: ^0.1.6 version: 0.1.6 @@ -5097,7 +5100,6 @@ packages: /destr@2.0.2: resolution: {integrity: sha512-65AlobnZMiCET00KaFFjUefxDX0khFA/E4myqZ7a6Sq1yZtR8+FVIvilVX66vF2uobSumxooYZChiRPCKNqhmg==} - dev: true /destroy@1.2.0: resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==} @@ -7813,7 +7815,6 @@ packages: /node-fetch-native@1.6.1: resolution: {integrity: sha512-bW9T/uJDPAJB2YNYEpWzE54U5O3MQidXsOyTfnbKYtTtFexRvGzb1waphBN4ZwP6EcIvYYEOwW0b72BpAqydTw==} - dev: true /node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} @@ -8177,6 +8178,14 @@ packages: object-keys: 1.1.1 dev: true + /ofetch@1.2.1: + resolution: {integrity: sha512-WEX1TEfGuAFJhzRW6Qv9RcxCyek+YogEeXlCWl1XoqBSW2fc6jU4LTk3VotwC1YfXv8Uz06LSofU6uW/ZIT+6g==} + dependencies: + destr: 2.0.2 + node-fetch-native: 1.6.1 + ufo: 1.3.2 + dev: false + /ofetch@1.3.3: resolution: {integrity: sha512-s1ZCMmQWXy4b5K/TW9i/DtiN8Ku+xCiHcjQ6/J/nDdssirrQNOoB165Zu8EqLMA2lln1JUth9a0aW9Ap2ctrUg==} dependencies: @@ -10009,7 +10018,6 @@ packages: /ufo@1.3.2: resolution: {integrity: sha512-o+ORpgGwaYQXgqGDwd+hkS4PuZ3QnmqMMxRuajK/a38L6fTpcE5GPIfrf+L/KemFzfUpeUQc1rRS1iDBozvnFA==} - dev: true /ultrahtml@1.5.2: resolution: {integrity: sha512-qh4mBffhlkiXwDAOxvSGxhL0QEQsTbnP9BozOK3OYPEGvPvdWzvAUaXNtUSMdNsKDtuyjEbyVUPFZ52SSLhLqw==} diff --git a/utils/api.ts b/utils/api.ts new file mode 100644 index 0000000..7f4fcea --- /dev/null +++ b/utils/api.ts @@ -0,0 +1,25 @@ +import type { SprintFestivalCouplets } from '~/packages/ai/src' + +/** + * generate couplets + */ +export async function apiGenerate(params: { + prompt: string +}) { + try { + const data = await $fetch('/api/generate', { + query: params, + }) + return data + } + catch (error: any) { + console.error('apiGenerate', error) + return { + error: error.message, + 上联: '网络出错网络差', + 下联: '热门火爆排队多', + 横批: '掉线断网', + 总结: '寄', + } + } +} diff --git a/utils/index.ts b/utils/index.ts new file mode 100644 index 0000000..3318fdb --- /dev/null +++ b/utils/index.ts @@ -0,0 +1 @@ +export * from './api'