diff --git a/pkg/v1/files.go b/pkg/v1/files.go index f4f91c1..4ef43cd 100644 --- a/pkg/v1/files.go +++ b/pkg/v1/files.go @@ -36,11 +36,11 @@ func (f filesHandler) CreateFolder(storage, path string) error { return nil } -// Uploads a .gcode file to the given storage at the given path. +// Uploads a .gcode or .bgcode file to the given storage at the given path. func (f filesHandler) Upload( storage, folderPath, fileName string, content []byte, overwrite, printAfterUpload bool, ) error { - if !strings.HasSuffix(fileName, ".gcode") { + if !hasValidExtension(fileName) { return ErrNonGcodeFile } if len(content) == 0 { @@ -68,7 +68,7 @@ func (f filesHandler) Upload( // Starts the print of the file at the given path in the given storage. func (f filesHandler) StartPrint(storage string, path string) error { - if !strings.HasSuffix(path, ".gcode") { + if !hasValidExtension(path) { return ErrNonGcodeFile } _, err := f.printer.post(fmt.Sprintf("/api/v1/files/%s/%s", storage, path), nil) @@ -105,3 +105,12 @@ func (f filesHandler) parseError(err error) error { } return err } + +func hasValidExtension(fileName string) bool { + for _, extension := range []string{".gcode", ".bgcode"} { + if strings.HasSuffix(fileName, extension) { + return true + } + } + return false +} diff --git a/pkg/v1/v1.go b/pkg/v1/v1.go index e0e687d..1009da5 100644 --- a/pkg/v1/v1.go +++ b/pkg/v1/v1.go @@ -5,7 +5,7 @@ import ( ) var ( - ErrNonGcodeFile = fmt.Errorf("file must have .gcode extension") + ErrNonGcodeFile = fmt.Errorf("file must have .gcode or .bgcode extension") ErrEmptyFile = fmt.Errorf("empty files are not supported") ErrStorageNotFound = fmt.Errorf("storage not found")