Browse Source
Update output config format to allow string extensions
feature/update-route-registration
Roman Zipp
3 years ago
committed by
Fabian Vowie
No known key found for this signature in database
GPG Key ID: C27317C33B27C410
4 changed files with
56 additions and
7 deletions
-
README.md
-
config/example.json
-
pipelines/pipeline.go
-
pipelines/pipeline_test.go
|
|
@ -105,7 +105,7 @@ Authorization: Bearer <Token> |
|
|
|
} |
|
|
|
], |
|
|
|
"output": { |
|
|
|
"format": 0, |
|
|
|
"format": "jpg", |
|
|
|
"quality": 90 |
|
|
|
} |
|
|
|
} |
|
|
@ -148,13 +148,13 @@ Available pipeline `type`s: `0` (Image), `1` (Video) |
|
|
|
|
|
|
|
The image pipeline offers the following additional output options. |
|
|
|
|
|
|
|
Available `format` types: `0` (jpeg) |
|
|
|
Available `format` types: `jpg` (or `jpeg`), `png`, `gif`, `tif` (or `tiff`) and `bmp` |
|
|
|
The `quality` field can contain any integer between 1 and 100. |
|
|
|
|
|
|
|
```json |
|
|
|
{ |
|
|
|
"output": { |
|
|
|
"format": 0, |
|
|
|
"format": "jpg", |
|
|
|
"quality": 90 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -33,7 +33,7 @@ |
|
|
|
} |
|
|
|
], |
|
|
|
"output": { |
|
|
|
"format": 0, |
|
|
|
"format": "jpg", |
|
|
|
"quality": 90 |
|
|
|
} |
|
|
|
} |
|
|
@ -38,7 +38,7 @@ type Pipeline struct { |
|
|
|
RemoveMetadata bool `json:"remove_metadata" faker:"-"` |
|
|
|
Steps []Step `json:"steps" faker:"-"` |
|
|
|
Output struct { |
|
|
|
Format int `json:"format"` |
|
|
|
Format string `json:"format"` |
|
|
|
Quality int `json:"quality"` |
|
|
|
} `json:"output" faker:"-"` |
|
|
|
} |
|
|
@ -63,7 +63,16 @@ func (p Pipeline) Run(srcPath, bucketName string, storageProvider storage.IStora |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
format := imaging.Format(p.Output.Format) |
|
|
|
outputFormat := p.Output.Format |
|
|
|
if outputFormat == "" { |
|
|
|
outputFormat = "jpg" |
|
|
|
} |
|
|
|
|
|
|
|
format, err := imaging.FormatFromExtension(outputFormat) |
|
|
|
if err != nil { |
|
|
|
return "", errors.New(fmt.Sprintf("output format '%s' is not supported", outputFormat)) |
|
|
|
} |
|
|
|
|
|
|
|
var options []imaging.EncodeOption |
|
|
|
|
|
|
|
if p.Output.Quality != 0 { |
|
|
|
|
|
@ -362,4 +362,44 @@ func TestEncoding(t *testing.T) { |
|
|
|
os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) |
|
|
|
os.Remove(storageProvider.GetPath(Bucket, dest)) |
|
|
|
}) |
|
|
|
|
|
|
|
t.Run("Wrong output format results in error", func(t *testing.T) { |
|
|
|
const InvalidPayload string = `{ |
|
|
|
"name": "example pipeline", |
|
|
|
"type": 1, |
|
|
|
"removeMetadata": false, |
|
|
|
"steps": [ |
|
|
|
{ |
|
|
|
"name": "resize image", |
|
|
|
"type": 0, |
|
|
|
"options": { |
|
|
|
"width": 1280, |
|
|
|
"height": 720, |
|
|
|
"upscale": false |
|
|
|
} |
|
|
|
} |
|
|
|
], |
|
|
|
"output": { |
|
|
|
"format": "foo", |
|
|
|
"quality": 50 |
|
|
|
} |
|
|
|
}` |
|
|
|
|
|
|
|
wd, _ := os.Getwd() |
|
|
|
pipe := DeserializePipelines([][]byte{[]byte(InvalidPayload)})[0] |
|
|
|
|
|
|
|
storageProvider := storage.GetFileSystemStorageProvider("test", "..") |
|
|
|
|
|
|
|
// copy test file to storage bucket
|
|
|
|
_, err := storageProvider.StoreExisting(Bucket, "source.jpg", filepath.Join(wd, "../tests/files/900x900.jpg")) |
|
|
|
assert.Nil(t, err, "Test file should be readable") |
|
|
|
assert.FileExists(t, storageProvider.GetPath(Bucket, "source.jpg")) |
|
|
|
|
|
|
|
// run pipeline steps
|
|
|
|
_, err = pipe.Run("source.jpg", Bucket, storageProvider) |
|
|
|
assert.EqualError(t, err, "output format 'foo' is not supported") |
|
|
|
|
|
|
|
// clean up
|
|
|
|
os.Remove(storageProvider.GetPath(Bucket, "source.jpg")) |
|
|
|
}) |
|
|
|
} |