From 74599a1ae25bf44d5ee71c31ae172822dc75faf4 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Fri, 21 Feb 2025 14:52:47 +0530 Subject: [PATCH 1/2] check custom meta for download --- cmd/download.go | 33 +++++++++++++++++++++++++++++++++ go.mod | 4 ++-- go.sum | 2 -- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cmd/download.go b/cmd/download.go index 29772825..e260b396 100644 --- a/cmd/download.go +++ b/cmd/download.go @@ -1,6 +1,7 @@ package cmd import ( + "context" "encoding/json" "os" "strings" @@ -161,6 +162,38 @@ var downloadCmd = &cobra.Command{ os.Exit(1) } + meta, err := allocationObj.GetFileMeta(remotePath) + if err != nil { + PrintError("Error getting file meta", err) + os.Exit(1) + } + if meta.Type == fileref.DIRECTORY { + if meta.CustomMeta == "" { + PrintError("Use downloaddir command to download directory") + os.Exit(1) + } + customMetaMap := make(map[string]string) + err = json.Unmarshal([]byte(meta.CustomMeta), &customMetaMap) + if err != nil { + PrintError("Error unmarshalling custom meta", err) + os.Exit(1) + } + if customMetaMap["large_file"] != "" { + fh, err := os.Create(localPath) + if err != nil { + PrintError("Error creating the file", err) + os.Exit(1) + } + defer fh.Close() + err = allocationObj.DownloadLargeFile(context.Background(), fh, remotePath, "", statusBar) + if err != nil { + PrintError("Error downloading the file", err) + os.Exit(1) + } else { + return + } + } + } if thumbnail { errE = allocationObj.DownloadThumbnail(localPath, remotePath, verifyDownload, statusBar, true) } else { diff --git a/go.mod b/go.mod index ca4f03e9..0fcc3d7d 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.5 require ( github.com/0chain/errors v1.0.3 - github.com/0chain/gosdk v1.19.4-0.20250214122330-072b85b3c09b + github.com/0chain/gosdk v1.19.7-0.20250221092102-ee7dc15762b6 github.com/icza/bitio v1.1.0 github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/cobra v1.6.0 @@ -86,4 +86,4 @@ require ( ) // temporary, for development -//replace github.com/0chain/gosdk => ../gosdk +replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index eedeea9c..3d823daa 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,6 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI= github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= -github.com/0chain/gosdk v1.19.4-0.20250214122330-072b85b3c09b h1:Pdrc+WZqBuT3vcT1JNZRFM7L1Lh4OUoaMz6VW9Uo5k8= -github.com/0chain/gosdk v1.19.4-0.20250214122330-072b85b3c09b/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= From 998a03fec4ed2f63719768b7172a258cf9b339d7 Mon Sep 17 00:00:00 2001 From: Hitenjain14 Date: Fri, 21 Feb 2025 15:01:26 +0530 Subject: [PATCH 2/2] fix build --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0fcc3d7d..84f3281e 100644 --- a/go.mod +++ b/go.mod @@ -86,4 +86,4 @@ require ( ) // temporary, for development -replace github.com/0chain/gosdk => ../gosdk +// replace github.com/0chain/gosdk => ../gosdk diff --git a/go.sum b/go.sum index 3d823daa..867a5aaa 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,8 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI= github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw= github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM= github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc= +github.com/0chain/gosdk v1.19.7-0.20250221092102-ee7dc15762b6 h1:TDBbQXiTll3ByOmaWTlITuUQ/ZCXnpQxxq97Sidf0fs= +github.com/0chain/gosdk v1.19.7-0.20250221092102-ee7dc15762b6/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=