You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.ts 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import type { Plugin, PluginDeclaration, PluginManifestInMarket } from '../types'
  2. import type { GitHubUrlInfo } from '@/app/components/plugins/types'
  3. import { isEmpty } from 'lodash-es'
  4. export const pluginManifestToCardPluginProps = (pluginManifest: PluginDeclaration): Plugin => {
  5. return {
  6. plugin_id: pluginManifest.plugin_unique_identifier,
  7. type: pluginManifest.category,
  8. category: pluginManifest.category,
  9. name: pluginManifest.name,
  10. version: pluginManifest.version,
  11. latest_version: '',
  12. latest_package_identifier: '',
  13. org: pluginManifest.author,
  14. label: pluginManifest.label,
  15. brief: pluginManifest.description,
  16. icon: pluginManifest.icon,
  17. verified: pluginManifest.verified,
  18. introduction: '',
  19. repository: '',
  20. install_count: 0,
  21. endpoint: {
  22. settings: [],
  23. },
  24. tags: [],
  25. }
  26. }
  27. export const pluginManifestInMarketToPluginProps = (pluginManifest: PluginManifestInMarket): Plugin => {
  28. return {
  29. plugin_id: pluginManifest.plugin_unique_identifier,
  30. type: pluginManifest.category,
  31. category: pluginManifest.category,
  32. name: pluginManifest.name,
  33. version: pluginManifest.latest_version,
  34. latest_version: pluginManifest.latest_version,
  35. latest_package_identifier: '',
  36. org: pluginManifest.org,
  37. label: pluginManifest.label,
  38. brief: pluginManifest.brief,
  39. icon: pluginManifest.icon,
  40. verified: true,
  41. introduction: pluginManifest.introduction,
  42. repository: '',
  43. install_count: 0,
  44. endpoint: {
  45. settings: [],
  46. },
  47. tags: [],
  48. badges: pluginManifest.badges,
  49. verification: isEmpty(pluginManifest.verification) ? { authorized_category: 'langgenius' } : pluginManifest.verification,
  50. }
  51. }
  52. export const parseGitHubUrl = (url: string): GitHubUrlInfo => {
  53. const match = url.match(/^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/?$/)
  54. return match ? { isValid: true, owner: match[1], repo: match[2] } : { isValid: false }
  55. }
  56. export const convertRepoToUrl = (repo: string) => {
  57. return repo ? `https://github.com/${repo}` : ''
  58. }