From 6883b26ac60527257d4867ae8fb9626392faf9cf Mon Sep 17 00:00:00 2001 From: Panos Chatzopoulos Date: Wed, 1 Nov 2023 17:21:11 +0100 Subject: [PATCH] add endpoint for c4gh header size Co-authored-by: Kostas Koumpouras Co-authored-by: Panos Chatzopoulos " --- api/api.go | 1 + api/s3/s3.go | 2 ++ api/sda/sda.go | 15 +++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/api/api.go b/api/api.go index bcb7035..44dc34d 100644 --- a/api/api.go +++ b/api/api.go @@ -44,6 +44,7 @@ func Setup() *http.Server { router.GET("/s3-encrypted/*path", SelectedMiddleware(), s3.Download) router.GET("/health", healthResponse) router.GET("/header/*path", SelectedMiddleware(), s3.Download) + router.GET("/c4gheadsize/*path", SelectedMiddleware(), s3.Download) // Configure TLS settings log.Info("(3/5) Configuring TLS") diff --git a/api/s3/s3.go b/api/s3/s3.go index 52ce024..f215197 100644 --- a/api/s3/s3.go +++ b/api/s3/s3.go @@ -224,6 +224,8 @@ func GetObject(c *gin.Context) { c.Params = append(c.Params, gin.Param{Key: "fileid", Value: fileInfo.FileID}) if strings.Contains(c.Request.URL.String(), "header") { c.Params = append(c.Params, gin.Param{Key: "type", Value: "header"}) + } else if strings.Contains(c.Request.URL.String(), "c4gheadsize") { + c.Params = append(c.Params, gin.Param{Key: "type", Value: "headersize"}) } // Download the file diff --git a/api/sda/sda.go b/api/sda/sda.go index f5ac6f7..2f2df02 100644 --- a/api/sda/sda.go +++ b/api/sda/sda.go @@ -221,6 +221,7 @@ func Download(c *gin.Context) { return } } + log.Debug("- - - - - - - test 1 - - - - - - - ") if c.Param("type") == "header" { bamReader, err := bam.NewReader(fileStream, 0) if err != nil { @@ -237,7 +238,21 @@ func Download(c *gin.Context) { return + } else if c.Param("type") == "headersize" { + log.Debug("- - - - - - - test 2 - - - - - - - ") + head := fileDetails.Header + log.Debug("head: ", head) + //headlength := len(head) + headlength := bytes.NewReader(head) + log.Debug("headlength size: ", headlength.Size()) + buf := new(bytes.Buffer) + len := strconv.Itoa(int(headlength.Size())) + fmt.Fprint(buf, len) + sendStream(c.Writer, buf) + + return } + log.Debug("- - - - - - - test 3 - - - - - - - ") sendStream(c.Writer, fileStream) }