2020-02-11 04:08:39 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Helpers
|
|
|
|
module FileUploadHelpers
|
|
|
|
def file_is_valid?
|
2020-03-13 14:09:39 -04:00
|
|
|
filename = params[:file]&.original_filename
|
2021-10-19 08:12:07 -04:00
|
|
|
filename && ImportExportUploader::EXTENSION_ALLOWLIST.include?(File.extname(filename).delete('.'))
|
2020-02-11 04:08:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def validate_file!
|
2020-03-13 14:09:39 -04:00
|
|
|
render_api_error!({ error: _('You need to upload a GitLab project export archive (ending in .gz).') }, 422) unless file_is_valid?
|
2020-02-11 04:08:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|