-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoke.go
81 lines (73 loc) · 2.15 KB
/
invoke.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"context"
"fmt"
"gsutil/config"
"gsutil/middleware"
"gsutil/routes"
"os"
"path/filepath"
"cloud.google.com/go/storage"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"google.golang.org/api/option"
)
type FolderInfo struct {
FolderPath string `json:"folderPath"`
}
func contains(s []string, str string) bool {
for _, v := range s {
if v == str {
return true
}
}
return false
}
func main() {
appconfig := config.InitEnv()
firebaseStorage := config.SetupFirebase()
r := gin.Default()
r.Use(cors.New(cors.Config{
AllowMethods: []string{"OPTIONS, GET, POST, PUT, DELETE"},
AllowHeaders: []string{"Origin, X-Requested-With, Content-Type, Accept, Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
allowedOrigins := []string{"http://localhost:3000", appconfig.WebAppUrl}
return contains(allowedOrigins, origin)
},
}))
dir, _ := os.Getwd()
serviceAccountKeyFilePath, err := filepath.Abs(dir + "/" + appconfig.CredentialFile)
if err != nil {
panic("Unable to load service account file")
}
opt := option.WithCredentialsFile(serviceAccountKeyFilePath)
client, err := storage.NewClient(context.Background(), opt)
if err != nil {
fmt.Errorf("storage.NewClient: %v", err)
}
defer client.Close()
routes.InitStorageClient(appconfig.StorageBucket, firebaseStorage)
r.Use(func(c *gin.Context) {
c.Set("firebaseStorage", firebaseStorage)
})
r.Use(middleware.AuthMiddleware)
r.POST("/zip", gin.WrapF(routes.DownloadHandler))
r.POST("/move", routes.MovingFiles)
r.GET("/list", routes.ListObjects)
r.GET("/list/:jobid", routes.ListObjectsInFolder)
r.GET("/list/file/:path", routes.GetObject)
r.POST("/delete-files", routes.DeleteObjects)
r.POST("/upload", routes.UploadFiles)
r.POST("/upload/user", routes.UploadToUser)
r.POST("/upload/cert", routes.UploadCertBadge)
r.POST("/folder/:jobid/create", routes.FolderCreation)
// Determine port for HTTP service.
port := os.Getenv("PORT")
if port == "" {
port = "8081" //Change this when testing locally
fmt.Printf("defaulting to port %s", port)
}
r.Run(":" + port)
}