image-mapping.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * 图片映射配置文件
  3. *
  4. * @author 系统开发团队
  5. * @date 2023-05-15
  6. * @version 1.0.0
  7. * @description
  8. * 该配置文件用于定义特定图片URL的映射规则。
  9. * 可以为特定的远程图片URL指定本地路径,优先级高于通用映射规则。
  10. * 主要用于处理特殊情况,如需要将某些图片映射到特定的本地路径。
  11. */
  12. /**
  13. * 图片映射配置
  14. * 可以为特定的远程图片URL指定本地路径
  15. *
  16. * @example
  17. * {
  18. * 'http://example.com/image1.jpg': '/local-images/special/image1.jpg',
  19. * 'http://example.com/image2.jpg': '/local-images/special/image2.jpg'
  20. * }
  21. */
  22. export const imageMapping: Record<string, string> = {
  23. // 远程URL: 本地路径
  24. // 示例:
  25. // 'http://localhost:48081/admin-api/infra/file/1/get/example.jpg': '/local-images/custom/special-example.jpg',
  26. // 可以添加更多映射...
  27. }
  28. /**
  29. * 获取映射的本地路径
  30. * @param url 远程图片URL
  31. * @returns 映射的本地路径,如果没有映射则返回null
  32. *
  33. * @example
  34. * // 如果有映射,返回映射的本地路径
  35. * getMappedImagePath('http://example.com/image1.jpg') // 返回: '/local-images/special/image1.jpg'
  36. *
  37. * @example
  38. * // 如果没有映射,返回null
  39. * getMappedImagePath('http://example.com/no-mapping.jpg') // 返回: null
  40. */
  41. export const getMappedImagePath = (url: string): string | null => {
  42. return imageMapping[url] || null
  43. }