mirror of
https://codeberg.org/gothub/gothub
synced 2024-12-06 19:16:24 +01:00
add api-less 404 checking
This commit is contained in:
+15
-7
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user