Plugin idea: Image optimization with WebP

In order to get familiarised with the discourse codebase was trying to add conversion of gif to video format and storing it.

Firstly here is what I understood from the code and correct me if I am wrong.

  1. When a file is uploaded, it triggers UploadsController#create
  2. UploadsController makes some optimizations and then call Upload.create_for
  3. Upload model creates a record and sends an object back to UploadsController.
  4. UploadsController sends back the data as json to Ember app.
  5. Ember app checks for link to be an image and wraps it around img tag.

What I thought of doing:-

  1. I chose to use ffmpeg to convert gif to mp4 video and then insert the mp4 video to the uploads record.
  2. I have added a script to convert gif to mp4 video here in upload model.
  3. But there was an error message saying that format was not supported.
  4. I figured out that it was because of this validator check and if I add an exception for mp4 extension everything works, but people are then able to upload mp4 videos.
  5. I could have added the script in OptimizedImage model, but it looks like it is used mainly for storing thumbnails of the images.
    Note: -With the above implementation we will be losing the original gif image.

Could somebody tell me if I have understood the flow correctly and suggest me changes in my implementation?