]> git.openstreetmap.org Git - rails.git/blob - app/controllers/export_controller.rb
Merge remote-tracking branch 'upstream/pull/6197'
[rails.git] / app / controllers / export_controller.rb
1 class ExportController < ApplicationController
2   before_action :authorize_web
3   before_action :set_locale
4   before_action :update_totp, :only => [:finish]
5   authorize_resource :class => false
6
7   content_security_policy(:only => :embed) do |policy|
8     policy.frame_ancestors("*")
9   end
10
11   caches_page :embed
12
13   # When the user clicks 'Export' we redirect to a URL which generates the export download
14   def finish
15     bbox = BoundingBox.from_lon_lat_params(params)
16     style = params[:format]
17     format = params[:mapnik_format]
18
19     case style
20     when "osm"
21       # redirect to API map get
22       redirect_to api_map_path(:bbox => bbox)
23
24     when "mapnik"
25       # redirect to a special 'export' cgi script
26       scale = params[:mapnik_scale]
27       token = ROTP::TOTP.new(Settings.totp_key, :interval => 3600).now if Settings.totp_key
28
29       redirect_to "https://render.openstreetmap.org/cgi-bin/export?bbox=#{bbox}&scale=#{scale}&format=#{format}&token=#{token}", :allow_other_host => true
30     when "cyclemap", "transportmap"
31       zoom = params[:zoom]
32       lat = params[:lat]
33       lon = params[:lon]
34       width = params[:width]
35       height = params[:height]
36
37       redirect_to "https://tile.thunderforest.com/static/#{style[..-4]}/#{lon},#{lat},#{zoom}/#{width}x#{height}.#{format}?apikey=#{Settings.thunderforest_key}", :allow_other_host => true
38     end
39   end
40
41   def embed; end
42 end