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