Skip to content

Commit

Permalink
Allow upload of .bgcode files
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmilda committed Apr 17, 2024
1 parent a1d0dd7 commit 1134145
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions pkg/v1/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/v1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1134145

Please sign in to comment.