summaryrefslogtreecommitdiff
path: root/internal/pipeline/put.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-12-06 11:07:23 +0000
committerNick White <git@njw.name>2021-12-06 11:07:23 +0000
commit059ec57f8d99033f0570d89e0848f3ac02cf3dc4 (patch)
treec69a00537bde176a0a8d875d68593337a7d91cb1 /internal/pipeline/put.go
parentc40fb54b4b4d85060b8f60cb76fec5c7b23ca34b (diff)
pipeline: ignore any files with a non-image suffix, rather than erroring on them
Diffstat (limited to 'internal/pipeline/put.go')
-rw-r--r--internal/pipeline/put.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/internal/pipeline/put.go b/internal/pipeline/put.go
index 1be36f0..d44f74f 100644
--- a/internal/pipeline/put.go
+++ b/internal/pipeline/put.go
@@ -41,8 +41,8 @@ func (f fileWalk) Walk(path string, info os.FileInfo, err error) error {
return nil
}
-// CheckImages checks that all files in a directory are images
-// that can be decoded (skipping dotfiles)
+// CheckImages checks that all files with a ".jpg" or ".png" suffix
+// in a directory are images that can be decoded (skipping dotfiles)
func CheckImages(dir string) error {
checker := make(fileWalk)
go func() {
@@ -51,6 +51,11 @@ func CheckImages(dir string) error {
}()
for path := range checker {
+ suffix := filepath.Ext(path)
+ lsuffix := strings.ToLower(suffix)
+ if lsuffix != ".jpg" && lsuffix != ".png" {
+ continue
+ }
f, err := os.Open(path)
if err != nil {
return fmt.Errorf("Opening image %s failed: %v", path, err)
@@ -78,11 +83,12 @@ func DetectQueueType(dir string, conn Queuer) string {
}
}
-// UploadImages uploads all files (except those which start with a ".")
-// from a directory (recursively) into conn.WIPStorageId(), prefixed with
-// the given bookname and a slash. It also appends all file names with
-// sequential numbers, like 0001, to ensure they are appropriately named
-// for further processing in the pipeline.
+// UploadImages uploads all files with a suffix of ".jpg" or ".png"
+// (except those which start with a ".") from a directory (recursively)
+// into conn.WIPStorageId(), prefixed with the given bookname and a
+// slash. It also appends all file names with sequential numbers, like
+// 0001, to ensure they are appropriately named for further processing
+// in the pipeline.
func UploadImages(dir string, bookname string, conn Uploader) error {
files, err := ioutil.ReadDir(dir)
if err != nil {
@@ -94,8 +100,12 @@ func UploadImages(dir string, bookname string, conn Uploader) error {
if file.IsDir() {
continue
}
+ origsuffix := filepath.Ext(file.Name())
+ lsuffix := strings.ToLower(origsuffix)
+ if lsuffix != ".jpg" && lsuffix != ".png" {
+ continue
+ }
origname := file.Name()
- origsuffix := filepath.Ext(origname)
origbase := strings.TrimSuffix(origname, origsuffix)
origpath := filepath.Join(dir, origname)