utils.ts 1.8 KB

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