Files
probo/pkg/server/api/compliancepage/markdown_handler.go
Bryan Frimin 3e4a9be7c0 Remove tenant service pattern
Signed-off-by: Bryan Frimin <bryan@probo.com>
2026-05-20 16:51:15 -07:00

89 lines
2.7 KiB
Go

// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"net/http"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/trust"
)
type Handler struct {
trustService *trust.Service
}
func NewHandler(trustService *trust.Service) *Handler {
return &Handler{trustService: trustService}
}
func (h *Handler) HandleLLMsTxt(w http.ResponseWriter, r *http.Request) {
tc := CompliancePageFromContext(r.Context())
if tc == nil {
http.Error(w, "not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
scope := coredata.NewScopeFromObjectID(tc.ID)
if err := h.trustService.RenderCompliancePageMarkdown(r.Context(), w, tc.ID, scope); err != nil {
http.Error(w, "internal server error", http.StatusInternalServerError)
}
}
func (h *Handler) HandleRobotsTxt(w http.ResponseWriter, r *http.Request) {
tc := CompliancePageFromContext(r.Context())
if tc == nil {
http.Error(w, "not found", http.StatusNotFound)
return
}
baseURL := CompliancePageBaseURLFromContext(r.Context())
if baseURL == nil {
http.Error(w, "not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
if err := h.trustService.RenderRobotsTxt(r.Context(), w, tc.SearchEngineIndexing, *baseURL); err != nil {
http.Error(w, "internal server error", http.StatusInternalServerError)
}
}
func (h *Handler) HandleSitemap(w http.ResponseWriter, r *http.Request) {
tc := CompliancePageFromContext(r.Context())
if tc == nil {
http.Error(w, "not found", http.StatusNotFound)
return
}
baseURL := CompliancePageBaseURLFromContext(r.Context())
if baseURL == nil {
http.Error(w, "not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
scope := coredata.NewScopeFromObjectID(tc.ID)
if err := h.trustService.RenderSitemap(r.Context(), w, tc.ID, scope, *baseURL); err != nil {
http.Error(w, "internal server error", http.StatusInternalServerError)
}
}