mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 00:37:06 +08:00
16 lines
382 B
Ruby
16 lines
382 B
Ruby
class UploadUrlValidator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
if value.present?
|
|
uri =
|
|
begin
|
|
URI.parse(value)
|
|
rescue URI::Error
|
|
end
|
|
|
|
unless uri && Upload.exists?(url: value)
|
|
record.errors[attribute] << (options[:message] || I18n.t('errors.messages.invalid'))
|
|
end
|
|
end
|
|
end
|
|
end
|