diff --git a/web/app/components/plugins/install-plugin/hooks.ts b/web/app/components/plugins/install-plugin/hooks.ts index b2a5af4a2f..b0021f76b7 100644 --- a/web/app/components/plugins/install-plugin/hooks.ts +++ b/web/app/components/plugins/install-plugin/hooks.ts @@ -2,13 +2,24 @@ import Toast, { type IToastProps } from '@/app/components/base/toast' import { uploadGitHub } from '@/service/plugins' import { compareVersion, getLatestVersion } from '@/utils/semver' import type { GitHubRepoReleaseResponse } from '../types' +import { GITHUB_ACCESS_TOKEN } from '@/config' export const useGitHubReleases = () => { const fetchReleases = async (owner: string, repo: string) => { try { - const res = await fetch(`/repos/${owner}/${repo}/releases`) - const bodyJson = await res.json() - if (bodyJson.status !== 200) throw new Error(bodyJson.data.message) + let res, bodyJson + if (!GITHUB_ACCESS_TOKEN) { + // Fetch releases without authentication from client + res = await fetch(`https://api.github.com/repos/${owner}/${repo}/releases`) + if (!res.ok) throw new Error('Failed to fetch releases') + bodyJson = await res.json() + } + else { + // Fetch releases with authentication from server + res = await fetch(`/repos/${owner}/${repo}/releases`) + 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, diff --git a/web/app/layout.tsx b/web/app/layout.tsx index 8fa7f92851..0fc56c4509 100644 --- a/web/app/layout.tsx +++ b/web/app/layout.tsx @@ -45,7 +45,6 @@ const LocaleLayout = ({ data-public-maintenance-notice={process.env.NEXT_PUBLIC_MAINTENANCE_NOTICE} 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-github-access-token={process.env.NEXT_PUBLIC_GITHUB_ACCESS_TOKEN} > diff --git a/web/config/index.ts b/web/config/index.ts index c3f03c1235..52acd2e9fc 100644 --- a/web/config/index.ts +++ b/web/config/index.ts @@ -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 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'