From 2bc02c56d0e27ef2c34847143b90d31319b6d9a3 Mon Sep 17 00:00:00 2001 From: Akilan Date: Wed, 5 Jul 2023 16:05:33 +0100 Subject: [PATCH] added panic for programs that fails with SSL and added flag to download gateway address --- .DS_Store | Bin 6148 -> 8196 bytes main.go | 54 +++++++++++++++++++++++++------------------- templates/.DS_Store | Bin 6148 -> 6148 bytes 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/.DS_Store b/.DS_Store index 5574fc0b6e1769288a4d7faad3189cfa913efee6..55060073fbab369066299354751fbad43380d1df 100644 GIT binary patch delta 454 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD7Z0TH}hr%jz7$c**Q2SHn1=X zPUc}r6l7sYVMt^sVMt6VPR>cn&(GPM$+D7>1IC-I$SST;7F?8Oa|=LAIVmSU32LGvke>G+ x3^o?7W?an9!6C>D6axYQZXn?bvUFqNcjn3bGM*qOFfc)!19Bn5=6Iet%mCcXB=`UT diff --git a/main.go b/main.go index 5bd9cab..db4eca8 100644 --- a/main.go +++ b/main.go @@ -46,6 +46,8 @@ var ( P2PRCRootNode *string // P2PRCExposePort Public exposed port P2PRCExposePort *string + // DownloadGatewayURL Download Gateway URL + DownloadGatewayURL *string ) // ------------------------------------------------------------------------------------------------------------- @@ -63,6 +65,7 @@ func init() { P2PRC = flag.Bool("P2PRC", false, "Run P2PRC mode to selfnode node") P2PRCRootNode = flag.String("P2PRCHost", "", "Run P2PRC mode to selfnode node") P2PRCExposePort = flag.String("P2PRCExposedPort", "", "Port exposed externally for P2PRC") + DownloadGatewayURL = flag.String("DownloadGatewayURL", "localhost:8081", "Download gateway URL (Start with http: or https:)") } // InitPeernet Initializes Peernet backend @@ -109,9 +112,10 @@ type BlockchainRequest struct { } type File struct { - Hash []byte `json:"hash"` - Type uint16 `json:"type"` - Name string `json:"name"` + Hash []byte `json:"hash"` + Type uint16 `json:"type"` + Name string `json:"name"` + FileFormat uint16 `json:"format"` } // BlockchainResponse blockchain backend API response struct @@ -312,7 +316,7 @@ func AddFileToBlockchain(hash []byte, filename string) *BlockchainResponse { url := BackendAddressWithHTTP + "/blockchain/file/add" // Get file type - detectType, _, err := webapi.FileDetectType(filename) + detectType, fileFormat, err := webapi.FileDetectType(filename) if err != nil { panic(err) } @@ -323,6 +327,7 @@ func AddFileToBlockchain(hash []byte, filename string) *BlockchainResponse { files.Name = filename files.Hash = hash files.Type = detectType + files.FileFormat = fileFormat blockchainRequest.Files = append(blockchainRequest.Files, files) Byte, err := json.Marshal(blockchainRequest) @@ -446,7 +451,7 @@ func main() { "hash": hex.EncodeToString(warehouseResult.Hash), "filename": header.Filename, "size": header.Size, - "link": "http://164.90.177.167:8889/" + hex.EncodeToString(publicKey.SerializeCompressed()) + "/" + hex.EncodeToString(warehouseResult.Hash) + "/?filename=" + header.Filename, + "link": *DownloadGatewayURL + "/" + hex.EncodeToString(publicKey.SerializeCompressed()) + "/" + hex.EncodeToString(warehouseResult.Hash) + "/?filename=" + header.Filename, "address": *WebpageAddress, "backendUrl": *BackEndApiAddress, }) @@ -463,22 +468,22 @@ func main() { // Implement CURL script to ensure linux users can upload directly // the Cli like https://bashupload.com // Ex: curl http://localhost:8080/uploadCurl -F add=@ - r.POST("/uploadCurl", lm.Middleware(), func(c *gin.Context) { - file, header, err := c.Request.FormFile("add") - defer file.Close() - - if err != nil { - fmt.Println(err) - } - - publicKey, warehouseResult, err := UploadFile(backend, &file, header, "") - if err != nil { - fmt.Println(err) - } - - link := "http://peer.ae/" + hex.EncodeToString(publicKey.SerializeCompressed()) + "/" + hex.EncodeToString(warehouseResult.Hash) - c.Data(http.StatusOK, "plain/text", []byte(link)) - }) + //r.POST("/uploadCurl", lm.Middleware(), func(c *gin.Context) { + // file, header, err := c.Request.FormFile("add") + // defer file.Close() + // + // if err != nil { + // fmt.Println(err) + // } + // + // publicKey, warehouseResult, err := UploadFile(backend, &file, header, "") + // if err != nil { + // fmt.Println(err) + // } + // + // link := "http://peer.ae/" + hex.EncodeToString(publicKey.SerializeCompressed()) + "/" + hex.EncodeToString(warehouseResult.Hash) + // c.Data(http.StatusOK, "plain/text", []byte(link)) + //}) // --------------------------------------------------------------------------------------------- @@ -490,8 +495,11 @@ func main() { // ---------------------------------- Start Gin server ----------------------------------------- // check if SSL is used or not if *SSL { - BackendAddressWithHTTP = "https://" + *BackEndApiAddress - r.RunTLS(*WebpageAddress, *Certificate, *Key) + BackendAddressWithHTTP = "http://" + *BackEndApiAddress + err := r.RunTLS(*WebpageAddress, *Certificate, *Key) + if err != nil { + panic(err) + } *WebpageAddress = "https://" + *WebpageAddress } else { BackendAddressWithHTTP = "http://" + *BackEndApiAddress diff --git a/templates/.DS_Store b/templates/.DS_Store index 033d80f71554435ecb3f583f59847cbd4b043a01..9953bb6fe2fce7811c289b37f20fef43c6176221 100644 GIT binary patch delta 35 rcmZoMXfc@J&&akhU^gQp+hiW5`pNs5nl@K5_pwZD$l1)!@s}R}(5nm; delta 122 zcmZoMXfc@J&&aVcU^gQp$7CL+dQ~olOolv$6oyoW3I;uf42BYhT!tLaoc!dZoctsP z1_l8J2F9P0YnUb)^DvY$6fop4