68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package services
|
|
|
|
import (
|
|
"fmt"
|
|
"html"
|
|
"net"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/sujit-baniya/fiber-boilerplate/app"
|
|
)
|
|
|
|
// getAppURL devuelve la URL base absoluta (sin slash final).
|
|
// Si APP_URL es http://localhost sin puerto, añade APP_PORT para enlaces en desarrollo.
|
|
func getAppURL() string {
|
|
u := strings.TrimRight(app.Http.Server.Url, "/")
|
|
if u == "" {
|
|
return fmt.Sprintf("http://localhost:%s", app.Http.Server.Port)
|
|
}
|
|
|
|
parsed, err := url.Parse(u)
|
|
if err != nil || parsed.Host == "" {
|
|
return u
|
|
}
|
|
|
|
host := parsed.Hostname()
|
|
if parsed.Port() == "" && app.Http.Server.Port != "" {
|
|
if host == "localhost" || host == "127.0.0.1" {
|
|
parsed.Host = net.JoinHostPort(host, app.Http.Server.Port)
|
|
return strings.TrimRight(parsed.String(), "/")
|
|
}
|
|
}
|
|
return u
|
|
}
|
|
|
|
// absAppURL convierte una ruta relativa en URL absoluta para correo/Telegram.
|
|
func absAppURL(path string) string {
|
|
if path == "" {
|
|
return getAppURL()
|
|
}
|
|
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
|
|
return path
|
|
}
|
|
if !strings.HasPrefix(path, "/") {
|
|
path = "/" + path
|
|
}
|
|
return getAppURL() + path
|
|
}
|
|
|
|
func adminTicketPath(ticketID uint) string {
|
|
return fmt.Sprintf("/app/tickets?ticket=%d", ticketID)
|
|
}
|
|
|
|
func portalTicketPath(proyectoSlug string, ticketID uint) string {
|
|
if proyectoSlug == "" {
|
|
return "/portal/dashboard"
|
|
}
|
|
return fmt.Sprintf("/portal/proyecto/%s?tab=Tickets&ticket=%d", url.PathEscape(proyectoSlug), ticketID)
|
|
}
|
|
|
|
func escapeTelegramHTML(s string) string {
|
|
return html.EscapeString(s)
|
|
}
|
|
|
|
func telegramHTMLLink(absURL, label string) string {
|
|
return fmt.Sprintf(`<a href="%s">%s</a>`, escapeTelegramHTML(absURL), escapeTelegramHTML(label))
|
|
}
|