add api-less 404 checking

This commit is contained in:
Arya Kiran
2023-02-08 16:55:50 +05:30
parent 4e3bb59c41
commit dca78ff062
+15 -7
View File
@@ -2,16 +2,16 @@ package pages
import (
"codeberg.org/gothub/gothub/utils"
"context"
"github.com/carlmjohnson/requests"
"github.com/gocolly/colly"
"github.com/gofiber/fiber/v2"
"github.com/gomarkdown/markdown"
"github.com/microcosm-cc/bluemonday"
"log"
"strconv"
"context"
"net/http"
"regexp"
"strconv"
"strings"
)
@@ -39,7 +39,15 @@ type Ratelimit struct {
func HandleUser(c *fiber.Ctx) error {
// Declare Array used for displaying data
var userArray []User
resp, err := http.Get("https://github.com/" + c.Params("user"))
if err != nil {
log.Println(err)
}
if resp.StatusCode == 404 {
return c.Status(404).Render("error", fiber.Map{
"error": "User " + c.Params("user") + " not found",
})
}
// API
user := utils.GetRequest("https://api.github.com/users/" + c.Params("user"))
if user.Get("message").String() == "Not Found" {
@@ -83,18 +91,18 @@ func HandleUser(c *fiber.Ctx) error {
// User README
var readmee string
err := requests.
err0 := requests.
URL("https://raw.githubusercontent.com/" + c.Params("user") + "/" + c.Params("user") + "/master/README.md").
ToString(&readmee).
Fetch(context.Background())
if err != nil {
if err0 != nil {
err2 := requests.
URL("https://raw.githubusercontent.com/" + c.Params("user") + "/.github/master/profile/README.md").
ToString(&readmee).
Fetch(context.Background())
if err2 != nil {
readmee = ""
log.Println(err)
log.Println(err0)
}
}
mightBeUnsafe := markdown.ToHTML([]byte(readmee), nil, nil)