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.
- When a file is uploaded, it triggers UploadsController#create
- UploadsController makes some optimizations and then call Upload.create_for
- Upload model creates a record and sends an object back to UploadsController.
- UploadsController sends back the data as json to Ember app.
- Ember app checks for link to be an image and wraps it around img tag.
What I thought of doing:-
- I chose to use ffmpeg to convert gif to mp4 video and then insert the mp4 video to the uploads record.
- I have added a script to convert gif to mp4 video here in upload model.
- But there was an error message saying that format was not supported.
- 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.
- 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?