Skip to content

Commit 280fa40

Browse files
authored
Merge pull request #663 from 0chain/feat/sync-video
Filter for video files
2 parents 72b8014 + 00b6548 commit 280fa40

File tree

7 files changed

+58
-10
lines changed

7 files changed

+58
-10
lines changed

.github/workflows/build-zbox.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
make install
4141
4242
- name: 'Upload Artifact'
43-
uses: actions/upload-artifact@v3
43+
uses: actions/upload-artifact@v4
4444
with:
4545
name: zbox-linux
4646
path: zbox
@@ -93,7 +93,7 @@ jobs:
9393
zip zbox-windows.zip zbox.exe libgcc_s_seh-1.dll libstdc++-6.dll libwinpthread-1.dll
9494
9595
- name: 'Upload Artifact'
96-
uses: actions/upload-artifact@v3
96+
uses: actions/upload-artifact@v4
9797
with:
9898
name: zbox-windows.zip
9999
path: zbox-windows.zip
@@ -121,7 +121,7 @@ jobs:
121121
run: make install
122122

123123
- name: 'Upload Artifact'
124-
uses: actions/upload-artifact@v3
124+
uses: actions/upload-artifact@v4
125125
with:
126126
name: zbox-macos
127127
path: zbox

cmd/common.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"io"
56
"log"
67
"os"
78
"sync"
@@ -16,6 +17,10 @@ const (
1617

1718
func (s *StatusBar) Started(allocationId, filePath string, op int, totalBytes int) {
1819
s.b = pb.StartNew(totalBytes)
20+
if s.f != nil {
21+
s.b.Output = s.f
22+
s.b.NotPrint = true
23+
}
1924
s.b.Set(0)
2025
}
2126
func (s *StatusBar) InProgress(allocationId, filePath string, op int, completedBytes int, data []byte) {
@@ -60,6 +65,7 @@ func (s *StatusBar) RepairCompleted(filesRepaired int) {
6065
type StatusBar struct {
6166
b *pb.ProgressBar
6267
wg *sync.WaitGroup
68+
f io.Writer
6369
success bool
6470
}
6571

cmd/download.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ var downloadCmd = &cobra.Command{
8181
sdk.SetNumBlockDownloads(numBlocks)
8282
wg := &sync.WaitGroup{}
8383
statusBar := &StatusBar{wg: wg}
84+
if logFilePath != "" {
85+
f, err := os.Create(logFilePath)
86+
if err != nil {
87+
PrintError("Error creating log file", err)
88+
os.Exit(1)
89+
}
90+
defer f.Close()
91+
statusBar.f = f
92+
}
8493
wg.Add(1)
8594
var errE error
8695
var allocationObj *sdk.Allocation

cmd/root.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var bSilent bool
3434
var allocUnderRepair bool
3535

3636
var walletJSON string
37+
var logFilePath string
3738

3839
var rootCmd = &cobra.Command{
3940
Use: "zbox",
@@ -58,6 +59,7 @@ func init() {
5859
rootCmd.PersistentFlags().StringVar(&cDir, "configDir", "", "configuration directory (default is $HOME/.zcn)")
5960
rootCmd.PersistentFlags().BoolVar(&bSilent, "silent", false, "(default false) Do not show interactive sdk logs (shown by default)")
6061
rootCmd.PersistentFlags().Float64Var(&txFee, "fee", 0, "transaction fee for the given transaction (if unset, it will be set to blockchain min fee)")
62+
rootCmd.PersistentFlags().StringVar(&logFilePath, "log", "", "log file path where progress will be logged")
6163
}
6264

6365
func Execute() {
@@ -89,8 +91,9 @@ func initConfig() {
8991
logger.SyncLoggers([]*logger.Logger{zcncore.GetLogger(), sdk.GetLogger()})
9092

9193
// set the log file
92-
zcncore.SetLogFile("cmdlog.log", !bSilent)
93-
sdk.SetLogFile("cmdlog.log", !bSilent)
94+
logPath := "cmdlog.log"
95+
zcncore.SetLogFile(logPath, !bSilent)
96+
sdk.SetLogFile(logPath, !bSilent)
9497

9598
err = client.Init(context.Background(), cfg)
9699
if err != nil {

cmd/sync.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,30 @@ func filterEmptyFiles(localPath string, lDiff []sdk.FileDiff) (filterDiff []sdk.
8181
return
8282
}
8383

84+
func filterVideoFiles(localPath string, lDiff []sdk.FileDiff) (filterDiff []sdk.FileDiff) {
85+
localPath = strings.TrimRight(localPath, "/")
86+
for _, f := range lDiff {
87+
path := localPath + f.Path
88+
parentPath := filepath.Dir(path)
89+
videoPath := filepath.Dir(parentPath)
90+
//get extension of directory name
91+
parentPathExt := filepath.Ext(parentPath)
92+
if parentPathExt == "" && filepath.Base(parentPath) != "preview" {
93+
filterDiff = append(filterDiff, f)
94+
continue
95+
}
96+
if filepath.Base(path) == "thumbnail_generated.jpg" || filepath.Base(path) == "0kb" || (f.Type == "d" && filepath.Base(path) == "preview") {
97+
continue
98+
}
99+
100+
ext := filepath.Ext(videoPath)
101+
if ext != ".mp4" && ext != ".mkv" && ext != ".avi" && ext != ".mov" && ext != ".flv" && ext != ".wmv" && ext != ".webm" {
102+
filterDiff = append(filterDiff, f)
103+
}
104+
}
105+
return
106+
}
107+
84108
func startMultiUploadUpdate(allocationObj *sdk.Allocation, argsSlice []chunkedUploadArgs) error {
85109
totalOperations := len(argsSlice)
86110
if totalOperations == 0 {
@@ -220,6 +244,7 @@ var syncCmd = &cobra.Command{
220244
}
221245

222246
lDiff = filterEmptyFiles(localpath, lDiff)
247+
lDiff = filterVideoFiles(localpath, lDiff)
223248

224249
if len(lDiff) > 0 {
225250
printTable(lDiff)
@@ -282,7 +307,11 @@ var syncCmd = &cobra.Command{
282307
fileMetas[f.Path] = fileMeta
283308
// TODO: User confirm??
284309
fmt.Printf("Deleting remote %s...\n", f.Path)
285-
err = allocationObj.DeleteFile(f.Path)
310+
opReq := sdk.OperationRequest{
311+
RemotePath: f.Path,
312+
OperationType: constants.FileOperationDelete,
313+
}
314+
err = allocationObj.DoMultiOperation([]sdk.OperationRequest{opReq})
286315
if err != nil {
287316
PrintError("Error deleting remote file,", err.Error())
288317
}
@@ -374,6 +403,7 @@ var getDiffCmd = &cobra.Command{
374403
PrintError("Error getting diff.", err)
375404
os.Exit(1)
376405
}
406+
lDiff = filterVideoFiles(localpath, lDiff)
377407

378408
util.PrintJSON(lDiff)
379409
},
@@ -394,7 +424,7 @@ func init() {
394424
If file exists, this will be used for comparison with remote.
395425
After sync complete, remote snapshot will be updated to the same file for next use.`)
396426
syncCmd.PersistentFlags().StringArray("excludepath", []string{}, "Remote folder paths exclude to sync")
397-
syncCmd.Flags().BoolP("verifydownload", "v", true, "pass this option to verify downloaded blocks")
427+
syncCmd.Flags().BoolP("verifydownload", "v", false, "pass this option to verify downloaded blocks")
398428

399429
syncCmd.MarkFlagRequired("allocation")
400430
syncCmd.MarkFlagRequired("localpath")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.22.5
66

77
require (
88
github.com/0chain/errors v1.0.3
9-
github.com/0chain/gosdk v1.19.0-RC2.0.20250117164514-4933fa5602a5
9+
github.com/0chain/gosdk v1.19.2
1010
github.com/icza/bitio v1.1.0
1111
github.com/olekukonko/tablewriter v0.0.5
1212
github.com/spf13/cobra v1.6.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/0chain/common v1.18.3 h1:42dYOv2KyMTSanuS67iDtfv+ErbSRqR8NJ3MG72MwaI=
4040
github.com/0chain/common v1.18.3/go.mod h1:Lapu2Tj7z5Sm4r+X141e7vsz4NDODTEypeElYAP3iSw=
4141
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
4242
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
43-
github.com/0chain/gosdk v1.19.0-RC2.0.20250117164514-4933fa5602a5 h1:A8Ig1uLfMIaGtP4/m2X7/KZC9+thbsOJNBaMY/ZsycY=
44-
github.com/0chain/gosdk v1.19.0-RC2.0.20250117164514-4933fa5602a5/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
43+
github.com/0chain/gosdk v1.19.2 h1:OpGwtUAObAqU4HatQ8VM/Z+m07LG65NhF1dO/1q9RTs=
44+
github.com/0chain/gosdk v1.19.2/go.mod h1:8unFy9Dx2YyPKMYPDGR3MFhUEymbAfQcRDm9bobVLGw=
4545
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4646
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
4747
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=

0 commit comments

Comments
 (0)