Skip to content

Commit edd426c

Browse files
committed
clean up
1 parent 4dfb096 commit edd426c

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

internal/file_serve.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package internal
22

33
import (
4-
"fmt"
54
"os"
5+
"path"
66
"strings"
77

88
"github.com/gofiber/fiber/v2"
@@ -20,16 +20,15 @@ func HandleDownloadFile(c *fiber.Ctx) error {
2020
return sendResponse(c, fiber.StatusUnauthorized, false, err.Error())
2121
}
2222

23-
file := fmt.Sprintf("%s/%s", AppCnf.Path, out.Subject)
24-
_, err = os.Lstat(file)
25-
23+
filePath := path.Join(AppCnf.Path, out.Subject)
24+
file, err := os.Lstat(filePath)
2625
if err != nil {
2726
ms := strings.SplitN(err.Error(), "/", -1)
2827
return sendResponse(c, fiber.StatusNotFound, false, ms[len(ms)-1])
2928
}
3029

31-
c.Attachment(file)
32-
return c.SendFile(file, AppCnf.Compress)
30+
c.Attachment(file.Name())
31+
return c.SendFile(filePath, AppCnf.Compress)
3332
}
3433

3534
func HandleServeFile(c *fiber.Ctx) error {
@@ -43,9 +42,8 @@ func HandleServeFile(c *fiber.Ctx) error {
4342
if err != nil {
4443
return sendResponse(c, fiber.StatusUnauthorized, false, err.Error())
4544
}
46-
ms := strings.SplitN(out.Subject, "/", -1)
4745

48-
c.Attachment(ms[len(ms)-1])
49-
c.Set("X-Accel-Redirect", fmt.Sprintf("%s%s", AppCnf.NginxFileServePath, out.Subject))
46+
c.Attachment(path.Base(out.Subject))
47+
c.Set("X-Accel-Redirect", path.Join(AppCnf.NginxFileServePath, out.Subject))
5048
return c.SendStatus(fiber.StatusOK)
5149
}

0 commit comments

Comments
 (0)