danvergara / morphos

Self-hosted file converter server
MIT License
1.06k stars 44 forks source link

Refactor file factory #20

Closed danvergara closed 9 months ago

danvergara commented 9 months ago

Pull Request Template

Description

This change is a little big since it´s meant to fix a couple of problems I couldn't solved in the previous PR. The main addition is change signature on the ConvertTo method to receive the target file type (e.g. image or document) alongside the target sub-type (e.g. png), so that the object which implements the File interface can figure out how to convert the file to the target format based on the information mentioned above.

type File interface {
    SupportedFormats() map[string][]string
    ConvertTo(string, string, []byte) ([]byte, error)
}

The result seems repetitive for the image package, because conversion between images is pretty much the same, but I can't guarantee the same for conversion across different file types.

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Ran the test suite locally and QA'd it myself with different images I have for testing purposes.

Checklist: