chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { onTestFinished } from 'vite-plus/test'
|
||||
import GithubStar from '../index'
|
||||
|
||||
const renderStars = () => {
|
||||
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
||||
onTestFinished(() => client.clear())
|
||||
return render(
|
||||
<QueryClientProvider client={client}>
|
||||
<GithubStar className="" />
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
}
|
||||
|
||||
afterEach(() => vi.restoreAllMocks())
|
||||
|
||||
it('shows the fetched star count after the request completes', async () => {
|
||||
let resolve!: (response: Response) => void
|
||||
const fetch = vi.spyOn(globalThis, 'fetch').mockReturnValue(
|
||||
new Promise((done) => {
|
||||
resolve = done
|
||||
}),
|
||||
)
|
||||
renderStars()
|
||||
expect(screen.queryByText(/^[\d,]+$/)).not.toBeInTheDocument()
|
||||
|
||||
resolve(Response.json({ repo: { stars: 123456 } }))
|
||||
|
||||
expect(await screen.findByText('123,456')).toBeInTheDocument()
|
||||
expect(fetch).toHaveBeenCalledWith('https://ungh.cc/repos/langgenius/dify')
|
||||
})
|
||||
|
||||
it('keeps a numeric fallback visible when the star request fails', async () => {
|
||||
vi.spyOn(globalThis, 'fetch').mockResolvedValue(new Response(null, { status: 500 }))
|
||||
renderStars()
|
||||
expect(await screen.findByText(/^[\d,]+$/)).toBeInTheDocument()
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
type GithubStarResponse = {
|
||||
repo: {
|
||||
stars: number
|
||||
}
|
||||
}
|
||||
|
||||
const defaultData: GithubStarResponse = {
|
||||
repo: { stars: 110918 },
|
||||
}
|
||||
|
||||
const getStar = async () => {
|
||||
const res = await fetch('https://ungh.cc/repos/langgenius/dify')
|
||||
|
||||
if (!res.ok) throw new Error('Failed to fetch github star')
|
||||
|
||||
return res.json()
|
||||
}
|
||||
|
||||
const GithubStar: FC<{ className: string }> = (props) => {
|
||||
const { isFetching, isError, data } = useQuery<GithubStarResponse>({
|
||||
queryKey: ['github-star'],
|
||||
queryFn: getStar,
|
||||
retry: false,
|
||||
placeholderData: defaultData,
|
||||
})
|
||||
|
||||
if (isFetching)
|
||||
return <span className="i-ri-loader-2-line size-3 shrink-0 animate-spin text-text-tertiary" />
|
||||
|
||||
if (isError) return <span {...props}>{defaultData.repo.stars.toLocaleString()}</span>
|
||||
|
||||
return <span {...props}>{data?.repo.stars.toLocaleString()}</span>
|
||||
}
|
||||
|
||||
export default GithubStar
|
||||
Reference in new issue
Block a user