mirror of
https://github.com/langgenius/dify.git
synced 2026-03-19 21:57:33 +08:00
Signed-off-by: yyh <yuanyouhuilyz@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: statxc <tyleradams93226@gmail.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import type {
|
|
TagKey,
|
|
} from './constants'
|
|
import type { Plugin } from './types'
|
|
|
|
import { API_PREFIX, MARKETPLACE_API_PREFIX } from '@/config'
|
|
import {
|
|
categoryKeys,
|
|
tagKeys,
|
|
} from './constants'
|
|
|
|
export const getValidTagKeys = (tags: TagKey[]) => {
|
|
return tags.filter(tag => tagKeys.includes(tag))
|
|
}
|
|
|
|
export const getValidCategoryKeys = (category?: string) => {
|
|
return categoryKeys.find(key => key === category)
|
|
}
|
|
|
|
const hasUrlProtocol = (value: string) => /^[a-z][a-z\d+.-]*:/i.test(value)
|
|
|
|
export const getPluginCardIconUrl = (
|
|
plugin: Pick<Plugin, 'from' | 'name' | 'org' | 'type'>,
|
|
icon: string | undefined,
|
|
tenantId: string,
|
|
) => {
|
|
if (!icon)
|
|
return ''
|
|
|
|
if (hasUrlProtocol(icon) || icon.startsWith('/'))
|
|
return icon
|
|
|
|
if (plugin.from === 'marketplace') {
|
|
const basePath = plugin.type === 'bundle' ? 'bundles' : 'plugins'
|
|
return `${MARKETPLACE_API_PREFIX}/${basePath}/${plugin.org}/${plugin.name}/icon`
|
|
}
|
|
|
|
if (!tenantId)
|
|
return icon
|
|
|
|
return `${API_PREFIX}/workspaces/current/plugin/icon?tenant_id=${tenantId}&filename=${icon}`
|
|
}
|