config.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. # @Author : YY
  3. import os
  4. from ruoyi_common.ruoyi.config import CONFIG_CACHE
  5. from ruoyi_common.base.snippet import classproperty
  6. class RuoYiConfig:
  7. """
  8. 系统相关配置
  9. 设计为类属性访问方式,与 Java 版 RuoYi 一致:
  10. RuoYiConfig.profile
  11. RuoYiConfig.upload_path
  12. RuoYiConfig.download_path
  13. """
  14. @classproperty
  15. def profile(cls) -> str:
  16. """
  17. 基础配置路径,从配置缓存中实时读取,避免在模块导入时
  18. CONFIG_CACHE 还未初始化导致为 None 的问题。
  19. 对应 app.yml 中的 ruoyi.profile,通常是一个绝对路径,
  20. 与 Java 版 RuoYi 保持一致,例如:G:/ruoyi/uploadPath
  21. """
  22. return CONFIG_CACHE.get("ruoyi.profile", "")
  23. @classproperty
  24. def upload_path(cls) -> str:
  25. """
  26. 获取上传路径
  27. Returns:
  28. str: 上传路径(profile/upload),与 Java 版 RuoYi 行为一致
  29. """
  30. # profile 一般为绝对路径,这里直接在其下拼接 upload 目录
  31. return os.path.join(cls.profile, "upload")
  32. @classproperty
  33. def download_path(cls) -> str:
  34. """
  35. 获取下载路径
  36. Returns:
  37. str: 下载路径(profile/download),与 Java 版 RuoYi 行为一致
  38. """
  39. return os.path.join(cls.profile, "download")
  40. @classproperty
  41. def avatar_path(cls) -> str:
  42. """
  43. 获取头像路径
  44. Returns:
  45. str: 头像路径(profile/avatar),与 Java 版 RuoYi 行为一致
  46. """
  47. return os.path.join(cls.profile, "avatar")
  48. @classproperty
  49. def import_path(cls) -> str:
  50. """
  51. 获取导入路径
  52. Returns:
  53. str: 导入路径(profile/import),与 Java 版 RuoYi 行为一致
  54. """
  55. return os.path.join(cls.profile, "import")