2 class ChangesController < ApplicationController
3 skip_before_action :verify_authenticity_token
4 before_action :api_deny_access_handler
6 authorize_resource :class => false
8 before_action :check_api_readable
9 around_action :api_call_handle_error, :api_call_timeout
11 # Get a list of the tiles that have changed within a specified time
14 zoom = (params[:zoom] || "12").to_i
16 if params.include?(:start) && params.include?(:end)
17 starttime = Time.parse(params[:start])
18 endtime = Time.parse(params[:end])
20 hours = (params[:hours] || "1").to_i.hours
21 endtime = Time.now.getutc
22 starttime = endtime - hours
25 if zoom >= 1 && zoom <= 16 &&
26 endtime > starttime && endtime - starttime <= 24.hours
27 mask = (1 << zoom) - 1
29 tiles = Node.where(:timestamp => starttime..endtime).group("maptile_for_point(latitude, longitude, #{zoom})").count
31 doc = OSM::API.new.get_xml_doc
32 changes = XML::Node.new "changes"
33 changes["starttime"] = starttime.xmlschema
34 changes["endtime"] = endtime.xmlschema
36 tiles.each do |tile, count|
37 x = (tile.to_i >> zoom) & mask
40 t = XML::Node.new "tile"
44 t["changes"] = count.to_s
51 render :xml => doc.to_s
53 render :plain => "Requested zoom is invalid, or the supplied start is after the end time, or the start duration is more than 24 hours", :status => :bad_request