X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/3426976606d30278fcf5ed279d3c95900785c4a5..b5188cae0865597462bd6b5068a80ccfceab802a:/app/controllers/api/amf_controller.rb diff --git a/app/controllers/api/amf_controller.rb b/app/controllers/api/amf_controller.rb index db8982d43..34a8ff7f1 100644 --- a/app/controllers/api/amf_controller.rb +++ b/app/controllers/api/amf_controller.rb @@ -37,6 +37,8 @@ module Api class AmfController < ApiController + require "timeout" + include Potlatch before_action :check_api_writable @@ -87,7 +89,7 @@ module Api result = [-5, nil] else case message - when "putway" then + when "putway" orn = renumberednodes.dup result = putway(renumberednodes, *args) result[4] = renumberednodes.reject { |k, _v| orn.key?(k) } @@ -96,7 +98,7 @@ module Api result = putrelation(renumberednodes, renumberedways, *args) when "deleteway" result = deleteway(*args) - when "putpoi" then + when "putpoi" result = putpoi(*args) renumberednodes[result[2]] = result[3] if result[0].zero? && result[2] != result[3] when "startchangeset" @@ -128,11 +130,9 @@ module Api [-2, "An unusual error happened (in #{call}). The server said: #{e}"] end - def amf_handle_error_with_timeout(call, rootobj, rootid) + def amf_handle_error_with_timeout(call, rootobj, rootid, &block) amf_handle_error(call, rootobj, rootid) do - OSM::Timer.timeout(Settings.api_timeout, OSM::APITimeoutError) do - yield - end + Timeout.timeout(Settings.api_timeout, OSM::APITimeoutError, &block) end end @@ -868,7 +868,7 @@ module Api # not just the id, hence this abstraction def getuser(token) - if token =~ /^(.+)\:(.+)$/ + if token =~ /^(.+):(.+)$/ User.authenticate(:username => Regexp.last_match(1), :password => Regexp.last_match(2)) else User.authenticate(:token => token) @@ -906,7 +906,7 @@ module Api # Alternative SQL queries for getway/whichways def sql_find_ways_in_area(bbox) - sql = <<~SQL + sql = <<~SQL.squish SELECT DISTINCT current_ways.id AS wayid,current_ways.version AS version FROM current_way_nodes INNER JOIN current_nodes ON current_nodes.id=current_way_nodes.node_id @@ -920,7 +920,7 @@ module Api def sql_find_pois_in_area(bbox) pois = [] - sql = <<~SQL + sql = <<~SQL.squish SELECT current_nodes.id,current_nodes.latitude*0.0000001 AS lat,current_nodes.longitude*0.0000001 AS lon,current_nodes.version FROM current_nodes LEFT OUTER JOIN current_way_nodes cwn ON cwn.node_id=current_nodes.id @@ -941,7 +941,7 @@ module Api def sql_find_relations_in_area_and_ways(bbox, way_ids) # ** It would be more Potlatchy to get relations for nodes within ways # during 'getway', not here - sql = <<~SQL + sql = <<~SQL.squish SELECT DISTINCT cr.id AS relid,cr.version AS version FROM current_relations cr INNER JOIN current_relation_members crm ON crm.id=cr.id @@ -949,7 +949,7 @@ module Api WHERE #{OSM.sql_for_area(bbox, 'cn.')} SQL unless way_ids.empty? - sql += <<~SQL + sql += <<~SQL.squish UNION SELECT DISTINCT cr.id AS relid,cr.version AS version FROM current_relations cr @@ -963,7 +963,7 @@ module Api def sql_get_nodes_in_way(wayid) points = [] - sql = <<~SQL + sql = <<~SQL.squish SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lon,current_nodes.id,current_nodes.version FROM current_way_nodes,current_nodes WHERE current_way_nodes.id=#{wayid.to_i}