Files
extrovert/api/ai.go
Gustavo "Guz" L. de Mello 2686a045fd chore: initial setup
2024-06-24 11:50:06 -03:00

31 lines
833 B
Go

package api
import (
"io"
"net/http"
"extrovert/internals"
)
func AiTxt(w http.ResponseWriter, r *http.Request) {
error := internals.HttpErrorHelper(w)
aiList, err := http.Get("https://raw.githubusercontent.com/ai-robots-txt/ai.robots.txt/main/ai.txt")
if error("Error trying to fetch ai block list", err, http.StatusInternalServerError) {
return
}
bytes, err := io.ReadAll(aiList.Body)
if error("Error trying to read ai block list", err, http.StatusInternalServerError) {
return
}
_, err = w.Write(bytes)
if error("Error trying to write ai block list", err, http.StatusInternalServerError) {
return
}
w.Header().Add("Cache-Control", "max-age=604800, stale-while-revalidate=86400, stale-if-error=86400")
w.Header().Add("CDN-Cache-Control", "max-age=604800")
w.Header().Add("Content-Type", "text/plain")
}