VRFS-2698 repurposed urls into usernames
This commit is contained in:
parent
ed47441f67
commit
d52f5b2372
|
|
@ -1478,10 +1478,10 @@
|
|||
});
|
||||
}
|
||||
|
||||
function validateUrlSite(url) {
|
||||
function validateUrlSite(url, sitetype) {
|
||||
return $.ajax({
|
||||
type: "GET",
|
||||
url: '/api/data_validation?data=' + encodeURIComponent(url),
|
||||
url: '/api/data_validation?sitetype='+sitetype+'&data=' + encodeURIComponent(url),
|
||||
contentType: 'application/json'
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ context.JK ||= {};
|
|||
|
||||
context.JK.UrlValidator = class UrlValidator
|
||||
|
||||
constructor: (input_div) ->
|
||||
constructor: (input_div, site_type) ->
|
||||
@EVENTS = context.JK.EVENTS
|
||||
@rest = context.JK.Rest()
|
||||
@site_type = site_type
|
||||
@input_div = input_div
|
||||
@url_input = @input_div.find('input')
|
||||
@data_input = @input_div.find('input')
|
||||
this.show_format_status()
|
||||
@logger = context.JK.logger
|
||||
@site_status = null
|
||||
|
|
@ -19,39 +20,36 @@ context.JK.UrlValidator = class UrlValidator
|
|||
this.renderErrors({})
|
||||
@spinner.hide()
|
||||
validator = this
|
||||
@url_input.bind 'blur', ->
|
||||
@data_input.bind 'blur', ->
|
||||
if validator.show_format_status()
|
||||
validator.validate_url_site()
|
||||
@url_input.bind 'focus', ->
|
||||
validator.validate_site()
|
||||
@data_input.bind 'focus', ->
|
||||
validator.show_format_status()
|
||||
|
||||
url_to_validate: () =>
|
||||
url = @url_input.val()
|
||||
data_to_validate: () =>
|
||||
url = @data_input.val()
|
||||
if 0 < url.length
|
||||
url.substring(0,2000)
|
||||
else
|
||||
null
|
||||
|
||||
validate_url_format: () =>
|
||||
regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
|
||||
regexp.test(this.url_to_validate())
|
||||
|
||||
show_format_status: () =>
|
||||
url = this.url_to_validate()
|
||||
data = this.data_to_validate()
|
||||
yn = true
|
||||
if url
|
||||
yn = this.validate_url_format()
|
||||
if data && 'url' == @site_type
|
||||
regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
|
||||
yn = regexp.test(this.data_to_validate())
|
||||
if yn
|
||||
@checkmark.show()
|
||||
else
|
||||
@checkmark.hide()
|
||||
yn
|
||||
|
||||
validate_url_site: () =>
|
||||
validate_site: () =>
|
||||
@site_status = null
|
||||
@spinner.show()
|
||||
@checkmark.hide()
|
||||
@rest.validateUrlSite(this.url_to_validate())
|
||||
@rest.validateUrlSite(this.data_to_validate(), @site_type)
|
||||
.done(this.processSiteCheck)
|
||||
.fail(this.processSiteCheckFail)
|
||||
|
||||
|
|
|
|||
|
|
@ -704,8 +704,8 @@ class ApiUsersController < ApiController
|
|||
render(json: { message: "blank data #{data}" }, status: :unprocessable_entity) && return
|
||||
end
|
||||
url = nil
|
||||
site = params[:site]
|
||||
unless site.present?
|
||||
site = params[:sitetype]
|
||||
if site.blank? || 'url'==site
|
||||
url = data
|
||||
else
|
||||
url = Utils.username_url(data, site)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ javascript:
|
|||
var initialized = false;
|
||||
$(document).on('JAMKAZAM_READY', function(e, data) {
|
||||
setTimeout(function() {
|
||||
window.url_validator = new JK.UrlValidator($(".url_validator#foobar_url"))
|
||||
window.url_validator = new JK.UrlValidator($(".url_validator#foobar_url"), 'url')
|
||||
url_validator.init()
|
||||
$('#url_input_foobar').val('http://www.jamkazam.com')
|
||||
}, 1)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
class Utils
|
||||
|
||||
def self.username_url(username, site)
|
||||
case site
|
||||
when 'youtube'
|
||||
"https://www.youtube.com/c/#{username}"
|
||||
when 'facebook'
|
||||
"https://www.facebook.com/#{username}"
|
||||
when 'soundcloud'
|
||||
"https://soundcloud.com/#{username}"
|
||||
when 'bandcamp'
|
||||
"http://#{username}.bandcamp.com"
|
||||
when 'fandalism'
|
||||
"http://fandalism.com/#{username}"
|
||||
when 'twitter'
|
||||
"https://twitter.com/#{username}"
|
||||
when 'reverbnation'
|
||||
"http://www.reverbnation.com/#{username}"
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def self.url_validator(url)
|
||||
result = `curl --output /dev/null --silent --head --fail --show-error '#{url}' 2>&1`.chomp
|
||||
if $?.success?
|
||||
return nil
|
||||
else
|
||||
result =~ /curl: \(\d+\) (.*)/
|
||||
return "#{$1} (#{url})"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Reference in New Issue