Merge branch 'feat/plugins' into dev/plugin-deploy

pull/12372/head
twwu 1 year ago
commit 44989ae97c

@ -44,7 +44,7 @@ const Card = ({
const locale = localeFromProps ? getLanguage(localeFromProps) : defaultLocale const locale = localeFromProps ? getLanguage(localeFromProps) : defaultLocale
const { categoriesMap } = useCategories() const { categoriesMap } = useCategories()
const { type, category, name, org, label, brief, icon, verified } = payload const { type, category, name, org, label, brief, icon, verified } = payload
const cornerMark = type !== 'plugin' ? categoriesMap.bundle?.label : categoriesMap[category]?.label const cornerMark = !['plugin', 'model', 'tool', 'extension'].includes(type) ? categoriesMap.bundle?.label : categoriesMap[category]?.label
const getLocalizedText = (obj: Record<string, string> | undefined) => const getLocalizedText = (obj: Record<string, string> | undefined) =>
obj?.[locale] || obj?.['en-US'] || obj?.en_US || '' obj?.[locale] || obj?.['en-US'] || obj?.en_US || ''

@ -2,23 +2,35 @@ import Toast, { type IToastProps } from '@/app/components/base/toast'
import { uploadGitHub } from '@/service/plugins' import { uploadGitHub } from '@/service/plugins'
import { compareVersion, getLatestVersion } from '@/utils/semver' import { compareVersion, getLatestVersion } from '@/utils/semver'
import type { GitHubRepoReleaseResponse } from '../types' import type { GitHubRepoReleaseResponse } from '../types'
import { GITHUB_ACCESS_TOKEN } from '@/config'
export const useGitHubReleases = () => { const formatReleases = (releases: any) => {
const fetchReleases = async (owner: string, repo: string) => { return releases.map((release: any) => ({
try {
const res = await fetch(`/repos/${owner}/${repo}/releases`)
const bodyJson = await res.json()
if (bodyJson.status !== 200) throw new Error(bodyJson.data.message)
const formattedReleases = bodyJson.data.map((release: any) => ({
tag_name: release.tag_name, tag_name: release.tag_name,
assets: release.assets.map((asset: any) => ({ assets: release.assets.map((asset: any) => ({
browser_download_url: asset.browser_download_url, browser_download_url: asset.browser_download_url,
name: asset.name, name: asset.name,
})), })),
})) }))
}
return formattedReleases export const useGitHubReleases = () => {
const fetchReleases = async (owner: string, repo: string) => {
try {
if (!GITHUB_ACCESS_TOKEN) {
// Fetch releases without authentication from client
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/releases`)
if (!res.ok) throw new Error('Failed to fetch repository releases')
const data = await res.json()
return formatReleases(data)
}
else {
// Fetch releases with authentication from server
const res = await fetch(`/repos/${owner}/${repo}/releases`)
const bodyJson = await res.json()
if (bodyJson.status !== 200) throw new Error(bodyJson.data.message)
return formatReleases(bodyJson.data)
}
} }
catch (error) { catch (error) {
if (error instanceof Error) { if (error instanceof Error) {

@ -45,6 +45,7 @@ const Installed: FC<Props> = ({
useEffect(() => { useEffect(() => {
if (hasInstalled && uniqueIdentifier === installedInfoPayload.uniqueIdentifier) if (hasInstalled && uniqueIdentifier === installedInfoPayload.uniqueIdentifier)
onInstalled() onInstalled()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasInstalled]) }, [hasInstalled])
const [isInstalling, setIsInstalling] = React.useState(false) const [isInstalling, setIsInstalling] = React.useState(false)

@ -107,7 +107,7 @@ export type PluginDetail = {
} }
export type Plugin = { export type Plugin = {
type: 'plugin' | 'bundle' type: 'plugin' | 'bundle' | 'model' | 'extension' | 'tool'
org: string org: string
author?: string author?: string
name: string name: string

@ -45,7 +45,6 @@ const LocaleLayout = ({
data-public-maintenance-notice={process.env.NEXT_PUBLIC_MAINTENANCE_NOTICE} data-public-maintenance-notice={process.env.NEXT_PUBLIC_MAINTENANCE_NOTICE}
data-public-site-about={process.env.NEXT_PUBLIC_SITE_ABOUT} data-public-site-about={process.env.NEXT_PUBLIC_SITE_ABOUT}
data-public-text-generation-timeout-ms={process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS} data-public-text-generation-timeout-ms={process.env.NEXT_PUBLIC_TEXT_GENERATION_TIMEOUT_MS}
data-public-github-access-token={process.env.NEXT_PUBLIC_GITHUB_ACCESS_TOKEN}
> >
<BrowserInitor> <BrowserInitor>
<SentryInitor> <SentryInitor>

@ -272,6 +272,6 @@ export const TEXT_GENERATION_TIMEOUT_MS = textGenerationTimeoutMs
export const DISABLE_UPLOAD_IMAGE_AS_ICON = process.env.NEXT_PUBLIC_DISABLE_UPLOAD_IMAGE_AS_ICON === 'true' export const DISABLE_UPLOAD_IMAGE_AS_ICON = process.env.NEXT_PUBLIC_DISABLE_UPLOAD_IMAGE_AS_ICON === 'true'
export const GITHUB_ACCESS_TOKEN = process.env.NEXT_PUBLIC_GITHUB_ACCESS_TOKEN || globalThis.document?.body?.getAttribute('data-public-github-access-token') || '' export const GITHUB_ACCESS_TOKEN = process.env.NEXT_PUBLIC_GITHUB_ACCESS_TOKEN || ''
export const SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS = '.difypkg,.difybndl' export const SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS = '.difypkg,.difybndl'

Loading…
Cancel
Save