uploads: factor out image dimension and filetype detection code.

* Add MediaFile abstraction. A MediaFile represents an image or video file.
* Move filetype detection and dimension parsing code from uploads to MediaFile.
This commit is contained in:
evazion
2020-05-06 00:33:35 -05:00
parent eab413199c
commit e477232e02
10 changed files with 215 additions and 154 deletions

View File

@@ -90,7 +90,7 @@ class UploadService
begin
upload.update(status: "preprocessing")
file = Utils.get_file_for_upload(upload, file: params[:file])
file = Utils.get_file_for_upload(upload, file: params[:file]&.tempfile)
Utils.process_file(upload, file, original_post_id: original_post_id)
upload.rating = params[:rating]
@@ -116,7 +116,7 @@ class UploadService
# if a file was uploaded after the preprocessing occurred,
# then process the file and overwrite whatever the preprocessor
# did
Utils.process_file(pred, pred.file) if pred.file.present?
Utils.process_file(pred, pred.file.tempfile) if pred.file.present?
pred.status = "completed"
pred.save