Skip to content

Commit 90a4040

Browse files
committed
fix: downgrade to fix qq browser fetch & add network tooltip
1 parent 70a5dfe commit 90a4040

File tree

6 files changed

+49
-12
lines changed

6 files changed

+49
-12
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ pnpm dev
2929
## FAQ
3030

3131
- [Error when opening nuxt3 web link in China's QQ application](https://github.com/nuxt/nuxt/issues/24229)
32+
- `ofetch` in QQ browser: [unjs/ofetch#294](https://github.com/unjs/ofetch/issues/294)

components/AiPrompt.vue

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@ import consola from 'consola'
33
44
import { useMagicKeys } from '@vueuse/core'
55
import { config } from '~/config'
6+
import { apiGenerate } from '~/utils'
67
78
const app = useAppStore()
89
910
/**
1011
* generate sfc 春联
12+
* not use ofetch see https://github.com/unjs/ofetch/issues/294
1113
*/
1214
async function generate() {
1315
if (app.loading)
1416
return
1517
1618
app.loading = true
17-
const data = await $fetch('/api/generate', {
18-
query: {
19-
prompt: app.prompt,
20-
},
19+
// const data = await $fetch('/api/generate', {
20+
// query: {
21+
// prompt: app.prompt,
22+
// },
23+
// })
24+
const data = await apiGenerate({
25+
prompt: app.prompt,
2126
})
22-
consola.info(data)
23-
if (data) {
24-
// TODO: add 生成失败提示
25-
app.setCoupletsData(data)
26-
}
27+
app.setCoupletsData(data)
2728
2829
app.loading = false
2930
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"typecheck": "vue-tsc --noEmit"
1919
},
2020
"dependencies": {
21+
"ofetch": "1.2.1",
2122
"wc-github-corners": "^0.1.6"
2223
},
2324
"devDependencies": {

pnpm-lock.yaml

+11-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/api.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { SprintFestivalCouplets } from '~/packages/ai/src'
2+
3+
/**
4+
* generate couplets
5+
*/
6+
export async function apiGenerate(params: {
7+
prompt: string
8+
}) {
9+
try {
10+
const data = await $fetch('/api/generate', {
11+
query: params,
12+
})
13+
return data
14+
}
15+
catch (error: any) {
16+
console.error('apiGenerate', error)
17+
return {
18+
error: error.message,
19+
上联: '网络出错网络差',
20+
下联: '热门火爆排队多',
21+
横批: '掉线断网',
22+
总结: '寄',
23+
}
24+
}
25+
}

utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './api'

0 commit comments

Comments
 (0)