url.go 666 B

123456789101112131415161718192021
  1. package common
  2. import "strings"
  3. // EnsureURLScheme prepends https:// to a URL that carries no scheme, so
  4. // subscription apps and browsers don't resolve it relative to the panel's own
  5. // domain (e.g. "t.me/support" turning into "https://panel.example/t.me/support").
  6. // Values with an explicit scheme (https://, tg://, mailto:, tel:) and empty
  7. // strings pass through untouched.
  8. func EnsureURLScheme(raw string) string {
  9. trimmed := strings.TrimSpace(raw)
  10. if trimmed == "" {
  11. return ""
  12. }
  13. if strings.Contains(trimmed, "://") ||
  14. strings.HasPrefix(trimmed, "mailto:") ||
  15. strings.HasPrefix(trimmed, "tel:") {
  16. return trimmed
  17. }
  18. return "https://" + trimmed
  19. }