|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 | 4 | "log"
|
6 | 5 | "os"
|
7 | 6 | "path/filepath"
|
8 | 7 |
|
9 |
| - "encoding/base64" |
10 |
| - |
11 | 8 | "github.com/lugvitc/staticfs/middleware"
|
12 | 9 |
|
13 | 10 | "github.com/gin-gonic/gin"
|
14 | 11 | "github.com/joho/godotenv"
|
15 | 12 | )
|
16 | 13 |
|
17 |
| -func loadSecretKey() ([]byte, error) { |
18 |
| - secretKey := os.Getenv("JWT_SECRET") |
19 |
| - if secretKey == "" { |
20 |
| - return nil, fmt.Errorf("PUBLIC_KEY environment variable not set") |
21 |
| - } |
22 |
| - return base64.StdEncoding.DecodeString(secretKey) |
23 |
| -} |
24 |
| - |
25 | 14 | func main() {
|
26 | 15 | err := godotenv.Load()
|
27 | 16 | if err != nil {
|
28 |
| - log.Fatal("Error loading .env file") |
| 17 | + log.Fatalln("Error loading .env file") |
29 | 18 | }
|
30 | 19 | dataDir := os.Getenv("DATA_DIR")
|
31 | 20 | r := gin.Default()
|
32 |
| - secretKey, err := loadSecretKey() |
33 |
| - if err != nil { |
34 |
| - log.Fatalf("Error loading public key: %v", err) |
| 21 | + secretKey := os.Getenv("JWT_SECRET") |
| 22 | + if secretKey == "" { |
| 23 | + log.Fatalln("JWT_SECRET environment variable not set") |
35 | 24 | }
|
36 |
| - r.Use(middleware.AuthMiddleware(secretKey)) |
| 25 | + r.Use(middleware.AuthMiddleware([]byte(secretKey))) |
37 | 26 | r.GET("/*filepath", func(c *gin.Context) {
|
38 | 27 | teamID := c.MustGet("teamId").(string)
|
39 | 28 | containerID := c.MustGet("containerId").(string)
|
40 | 29 | requestedFile := c.Param("filepath")
|
41 | 30 |
|
42 | 31 | // Clean the file path to prevent directory traversal attacks.
|
43 | 32 | fullPath := filepath.Join(dataDir, teamID, containerID, filepath.Clean(requestedFile))
|
44 |
| - // fmt.Println(fullPath) |
45 | 33 | c.File(fullPath)
|
46 | 34 | })
|
47 |
| - // token, err := utils.CreateJWT("randomteam123", "randomcontainer123", secretKey) |
48 |
| - // if err != nil { |
49 |
| - // log.Fatalf("Failed to generate JWT: %v", err) |
50 |
| - // } |
51 |
| - // fmt.Println("Generated JWT:", token) |
52 | 35 | r.Run()
|
53 | 36 | }
|
0 commit comments