-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
79 lines (64 loc) · 2.35 KB
/
main.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
package main
import (
"errors"
"fmt"
"net/http"
"os"
"strconv"
"github.com/JackalLabs/jackalapi/japicore"
"github.com/JackalLabs/jutils"
"github.com/rs/cors"
"github.com/uptrace/bunrouter"
)
func main() {
coreSession := japicore.InitJApiCore()
router := bunrouter.New(
bunrouter.WithMethodNotAllowedHandler(coreSession.MethodNotAllowedHandler()),
bunrouter.WithNotFoundHandler(coreSession.RouteNotFoundHandler()),
)
group := router.NewGroup("")
handler := http.Handler(router)
handler = cors.Default().Handler(handler)
group.WithGroup("", func(group *bunrouter.Group) {
group.GET("/version", coreSession.VersionHandler())
})
group.WithGroup("/fid", func(group *bunrouter.Group) {
group.GET("/download/:id", coreSession.DownloadByFidHandler())
group.GET("/d/:id", coreSession.DownloadByFidHandler())
group.GET("/ipfs/:id", coreSession.IpfsHandler())
group.POST("/upload", coreSession.UploadByPathHandler())
group.POST("/u", coreSession.UploadByPathHandler())
group.DELETE("/del/:id", coreSession.DeleteByFidHandler())
})
group.WithGroup("/p", func(group *bunrouter.Group) {
group.GET("/downloadfrombulk/*location", coreSession.BasicDownloadFromBulkByPathHandler())
group.GET("/download/*location", coreSession.BasicDownloadByPathHandler())
group.GET("/d/*location", coreSession.BasicDownloadByPathHandler())
group.POST("/import", coreSession.ImportHandler())
group.POST("/upload", coreSession.UploadByPathHandler())
group.POST("/u", coreSession.UploadByPathHandler())
group.DELETE("/delfrombulk/:filename/*location", coreSession.BasicDeleteFromBulkByPathHandler())
group.DELETE("/del/:filename/*location", coreSession.BasicDeleteByPathHandler())
})
port := jutils.LoadEnvVarOrFallback("JAPI_PORT", "3535")
portNum, err := strconv.ParseInt(port, 10, 64)
if err != nil {
panic(err)
}
fmt.Println("<<<<< * >>>>>")
fmt.Printf("🌍 Started JAPI: http://0.0.0.0:%d\n", portNum)
err = http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", portNum), handler)
if err != nil {
panic(err)
}
fmt.Printf("🌍 JAPI Wallet: %s\n", coreSession.Wallet.GetAddress())
fmt.Printf("🌍 JAPI Network: %s\n", coreSession.Wallet.GetChainID())
fmt.Println("<<<<< * >>>>>")
if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("Server Closed\n")
return
} else if err != nil {
fmt.Printf("error starting server: %s\n", err)
os.Exit(1)
}
}