-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: fix agents market locale fallback to english (#382)
* 🐛 fix: fix market locale url
- Loading branch information
Showing
5 changed files
with
57 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { DEFAULT_LANG } from '@/const/locale'; | ||
import { getAgentJSON } from '@/const/url'; | ||
|
||
export const runtime = 'edge'; | ||
|
||
export const GET = async (req: Request, { params }: { params: { id: string } }) => { | ||
const { searchParams } = new URL(req.url); | ||
|
||
const locale = searchParams.get('locale'); | ||
|
||
let res: Response; | ||
|
||
res = await fetch(getAgentJSON(params.id, locale as any)); | ||
if (res.status === 404) { | ||
res = await fetch(getAgentJSON(params.id, DEFAULT_LANG)); | ||
} | ||
|
||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DEFAULT_LANG } from '@/const/locale'; | ||
import { getAgentIndexJSON } from '@/const/url'; | ||
|
||
export const runtime = 'edge'; | ||
|
||
export const GET = async (req: Request) => { | ||
const locale = new URL(req.url).searchParams.get('locale'); | ||
|
||
let res: Response; | ||
|
||
res = await fetch(getAgentIndexJSON(locale as any)); | ||
|
||
if (res.status === 404) { | ||
res = await fetch(getAgentIndexJSON(DEFAULT_LANG)); | ||
} | ||
|
||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export const URLS = { | ||
market: '/api/market', | ||
plugins: '/api/plugins', | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,21 @@ | ||
import { getAgentIndexJSON, getAgentJSON } from '@/const/url'; | ||
import { getCurrentLanguage } from '@/store/global/helpers'; | ||
import { URLS } from '@/services/_url'; | ||
import { LobeChatAgentsMarketIndex } from '@/types/market'; | ||
|
||
/** | ||
* 请求助手列表 | ||
*/ | ||
export const getAgentList = async () => { | ||
let res: Response; | ||
export const getAgentList = async (locale: string): Promise<LobeChatAgentsMarketIndex> => { | ||
const res = await fetch(`${URLS.market}?locale=${locale}`); | ||
|
||
res = await fetch(getAgentIndexJSON(getCurrentLanguage())); | ||
|
||
if (res.status === 404) { | ||
res = await fetch(getAgentIndexJSON('en-US')); | ||
} | ||
|
||
const data: LobeChatAgentsMarketIndex = await res.json(); | ||
|
||
return data; | ||
return res.json(); | ||
}; | ||
|
||
/** | ||
* 请求助手 manifest | ||
*/ | ||
export const getAgentManifest = async (identifier?: string) => { | ||
export const getAgentManifest = async (identifier: string, locale: string) => { | ||
if (!identifier) return; | ||
const res = await fetch(getAgentJSON(identifier, getCurrentLanguage())); | ||
const res = await fetch(`${URLS.market}/${identifier}?locale=${locale}`); | ||
|
||
return res.json(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters