diff options
| author | Antonia Rescribe <antonia@rescribe.xyz> | 2021-11-22 17:35:12 +0000 | 
|---|---|---|
| committer | Nick White <git@njw.name> | 2021-11-22 18:05:53 +0000 | 
| commit | 26a11790593d55dc6fa3bc6f76fec1501acfa376 (patch) | |
| tree | ca1cc4fd1f7c3d3f2e7f3c5d49ce663d9411b810 /internal/pipeline | |
| parent | 673f77278f5b65576de7fee651ae290345e65282 (diff) | |
changed put.go so that a 4-digit number is appended to the end of each filename when images are uploaded to the pipeline
Diffstat (limited to 'internal/pipeline')
| -rw-r--r-- | internal/pipeline/put.go | 29 | 
1 files changed, 20 insertions, 9 deletions
| diff --git a/internal/pipeline/put.go b/internal/pipeline/put.go index 8cbecac..444735a 100644 --- a/internal/pipeline/put.go +++ b/internal/pipeline/put.go @@ -9,6 +9,7 @@ import (  	"image"  	_ "image/jpeg"  	_ "image/png" +	"io/ioutil"  	"os"  	"path/filepath"  	"strings" @@ -81,18 +82,28 @@ func DetectQueueType(dir string, conn Queuer) string {  // from a directory (recursively) into conn.WIPStorageId(), prefixed with  // the given bookname and a slash  func UploadImages(dir string, bookname string, conn Uploader) error { -	walker := make(fileWalk) -	go func() { -		_ = filepath.Walk(dir, walker.Walk) -		close(walker) -	}() +	files, err := ioutil.ReadDir(dir) +	if err != nil { +		fmt.Errorf("Failed to read directory %s: %v", dir, err) +	} -	for path := range walker { -		name := filepath.Base(path) -		err := conn.Upload(conn.WIPStorageId(), bookname + "/" + name, path) +	filenum := 0 +	for _, file := range files { +		if file.IsDir() { +			continue +		} +		origname := file.Name() +		origsuffix := filepath.Ext(origname) +		origbase := strings.TrimSuffix(origname, origsuffix) +		origpath := filepath.Join(dir, origname) + +		newname := fmt.Sprintf("%s_%04d%s", origbase, filenum, origsuffix) +		err = conn.Upload(conn.WIPStorageId(), filepath.Join(bookname, newname), origpath)  		if err != nil { -			return fmt.Errorf("Failed to upload %s: %v", path, err) +			return fmt.Errorf("Failed to upload %s: %v", origpath, err)  		} + +		filenum++  	}  	return nil | 
