diff options
author | FChannel <> | 2022-05-22 14:08:36 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | a66b676481d273508927e64a22e388dc302890ba (patch) | |
tree | 7c67b04dd8b39125526567ae6f08a39d0346d260 /routes/api.go | |
parent | 6a0f664b565716ad08301e7699d6c0393dbba977 (diff) |
route organization
Diffstat (limited to 'routes/api.go')
-rw-r--r-- | routes/api.go | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/routes/api.go b/routes/api.go deleted file mode 100644 index 080d88d..0000000 --- a/routes/api.go +++ /dev/null @@ -1,55 +0,0 @@ -package routes - -import ( - "io/ioutil" - "net/http" - "time" - - "github.com/FChannel0/FChannel-Server/config" - "github.com/FChannel0/FChannel-Server/util" - "github.com/gofiber/fiber/v2" -) - -func Media(c *fiber.Ctx) error { - if c.Query("hash") != "" { - return RouteImages(c, c.Query("hash")) - } - - return c.SendStatus(404) -} - -func RouteImages(ctx *fiber.Ctx, media string) error { - req, err := http.NewRequest("GET", config.MediaHashs[media], nil) - if err != nil { - return util.MakeError(err, "RouteImages") - } - - client := http.Client{ - Timeout: 5 * time.Second, - } - - resp, err := client.Do(req) - if err != nil { - return util.MakeError(err, "RouteImages") - } - defer resp.Body.Close() - - if resp.StatusCode != 200 { - fileBytes, err := ioutil.ReadFile("./static/notfound.png") - if err != nil { - return util.MakeError(err, "RouteImages") - } - - _, err = ctx.Write(fileBytes) - return util.MakeError(err, "RouteImages") - } - - body, _ := ioutil.ReadAll(resp.Body) - for name, values := range resp.Header { - for _, value := range values { - ctx.Append(name, value) - } - } - - return ctx.Send(body) -} |