assetUrl.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. const DEFAULT_ASSET_BASE_URL = 'https://transcend.ringzle.com/web/assets'
  2. const DEFAULT_PROFILE_IMAGE_BASE_URL = 'https://transcend.ringzle.com/xiaozhi-app/profile'
  3. const IMAGE_PATH = '/images/'
  4. function getAssetBaseUrl(env = process.env) {
  5. return String(env.VUE_APP_ASSET_BASE_URL || DEFAULT_ASSET_BASE_URL).replace(/\/+$/, '')
  6. }
  7. function imageUrl(filename, env = process.env) {
  8. const normalizedFilename = String(filename || '').replace(/^\/+/, '')
  9. return `${getAssetBaseUrl(env)}${IMAGE_PATH}${encodeURIComponent(normalizedFilename)}`
  10. }
  11. function htmlUrl(filename, env = process.env) {
  12. const normalizedFilename = String(filename || '').replace(/^\/+/, '')
  13. return `${getAssetBaseUrl(env)}/html/${encodeURIComponent(normalizedFilename)}`
  14. }
  15. function getProfileImageUrl(filename, env = process.env) {
  16. const normalizedFilename = String(filename || '').replace(/^\/+/, '')
  17. const baseUrl = String(env.VUE_APP_PROFILE_IMAGE_BASE_URL || DEFAULT_PROFILE_IMAGE_BASE_URL).replace(/\/+$/, '')
  18. return `${baseUrl}/${normalizedFilename}`
  19. }
  20. module.exports = {
  21. DEFAULT_ASSET_BASE_URL,
  22. DEFAULT_PROFILE_IMAGE_BASE_URL,
  23. getAssetBaseUrl,
  24. getProfileImageUrl,
  25. htmlUrl,
  26. imageUrl
  27. }