Skip to content

Commit

Permalink
fix: downgrade to fix qq browser fetch & add network tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Feb 6, 2024
1 parent 70a5dfe commit 90a4040
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 10 additions & 9 deletions components/AiPrompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"typecheck": "vue-tsc --noEmit"
},
"dependencies": {
"ofetch": "1.2.1",
"wc-github-corners": "^0.1.6"
},
"devDependencies": {
Expand Down
14 changes: 11 additions & 3 deletions pnpm-lock.yaml

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

25 changes: 25 additions & 0 deletions utils/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { SprintFestivalCouplets } from '~/packages/ai/src'

Check failure on line 1 in utils/api.ts

View workflow job for this annotation

GitHub Actions / lint

'SprintFestivalCouplets' is defined but never used

/**
* 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,
上联: '网络出错网络差',
下联: '热门火爆排队多',
横批: '掉线断网',
总结: '寄',
}
}
}
1 change: 1 addition & 0 deletions utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './api'

0 comments on commit 90a4040

Please sign in to comment.