From 1542878d6646b53cd5df6042f786e35a90ebdd71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Tue, 9 Nov 2021 16:03:04 +0800 Subject: [PATCH] :art: format code --- server/down.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/server/down.go b/server/down.go index 956d5816..258302e4 100644 --- a/server/down.go +++ b/server/down.go @@ -12,12 +12,12 @@ import ( ) func Down(ctx *fiber.Ctx) error { - rawPath, err:= url.PathUnescape(ctx.Params("*")) + rawPath, err := url.PathUnescape(ctx.Params("*")) if err != nil { - return ErrorResp(ctx,err,500) + return ErrorResp(ctx, err, 500) } rawPath = utils.ParsePath(rawPath) - log.Debugf("down: %s",rawPath) + log.Debugf("down: %s", rawPath) account, path, driver, err := ParsePath(rawPath) if err != nil { return ErrorResp(ctx, err, 500) @@ -34,18 +34,18 @@ func Down(ctx *fiber.Ctx) error { } func Proxy(ctx *fiber.Ctx) error { - rawPath, err:= url.PathUnescape(ctx.Params("*")) + rawPath, err := url.PathUnescape(ctx.Params("*")) if err != nil { - return ErrorResp(ctx,err,500) + return ErrorResp(ctx, err, 500) } rawPath = utils.ParsePath(rawPath) - log.Debugf("proxy: %s",rawPath) + log.Debugf("proxy: %s", rawPath) account, path, driver, err := ParsePath(rawPath) if err != nil { return ErrorResp(ctx, err, 500) } - if !account.Proxy && utils.GetFileType(filepath.Ext(rawPath))!=conf.TEXT { - return ErrorResp(ctx,fmt.Errorf("[%s] not allowed proxy",account.Name),403) + if !account.Proxy && utils.GetFileType(filepath.Ext(rawPath)) != conf.TEXT { + return ErrorResp(ctx, fmt.Errorf("[%s] not allowed proxy", account.Name), 403) } link, err := driver.Link(path, account) if err != nil { @@ -55,6 +55,20 @@ func Proxy(ctx *fiber.Ctx) error { return ctx.SendFile(link) } else { driver.Proxy(ctx) + //ctx.Response().ImmediateHeaderFlush = true + //var ProxyNetHttp = fasthttpadaptor.NewFastHTTPHandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // target, _ := url.Parse(link) + // protocol := "https://" + // if strings.HasPrefix(link, "http://") { + // protocol = "http://" + // } + // targetHost, _ := url.Parse(fmt.Sprintf("%s%s", protocol, target.Host)) + // proxy := httputil.NewSingleHostReverseProxy(targetHost) + // r.URL = target + // r.Host = target.Host + // proxy.ServeHTTP(w, r) + //}) + //ProxyNetHttp(ctx.Context()) if err := proxy.Do(ctx, link); err != nil { log.Errorf("proxy error: %s", err) return ErrorResp(ctx,err,500)