debian-mirror-gitlab/lib/api/helpers/file_upload_helpers.rb
2021-12-11 22:18:48 +05:30

16 lines
474 B
Ruby

# frozen_string_literal: true
module API
module Helpers
module FileUploadHelpers
def file_is_valid?
filename = params[:file]&.original_filename
filename && ImportExportUploader::EXTENSION_ALLOWLIST.include?(File.extname(filename).delete('.'))
end
def validate_file!
render_api_error!({ error: _('You need to upload a GitLab project export archive (ending in .gz).') }, 422) unless file_is_valid?
end
end
end
end