mirror of
https://github.com/langgenius/dify.git
synced 2026-03-21 06:18:27 +08:00
Added a utility function to generate plugin card icon URLs based on the plugin's source and workspace context. Updated the Card component to utilize this function for determining the correct icon source. Enhanced unit tests to verify the correct URL generation for both marketplace and package icons.
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}`
|
|
}
|