1 # frozen_string_literal: true
3 class ExportController < ApplicationController
4 before_action :authorize_web
5 before_action :set_locale
6 before_action :update_totp, :only => [:create]
7 authorize_resource :class => false
9 content_security_policy(:only => :show) do |policy|
10 policy.frame_ancestors("*")
17 # When the user clicks 'Export' we redirect to a URL which generates the export download
19 param! :minlon, Float, :required => true
20 param! :minlat, Float, :required => true
21 param! :maxlon, Float, :required => true
22 param! :maxlat, Float, :required => true
24 bbox = BoundingBox.from_lon_lat_params(params)
25 style = params[:format]
26 format = params[:mapnik_format]
30 # redirect to API map get
31 redirect_to api_map_path(:bbox => bbox)
34 # redirect to a special 'export' cgi script
35 scale = params[:mapnik_scale]
36 token = ROTP::TOTP.new(Settings.totp_key, :interval => 3600).now if Settings.totp_key
38 redirect_to "https://render.openstreetmap.org/cgi-bin/export?bbox=#{bbox}&scale=#{scale}&format=#{format}&token=#{token}", :allow_other_host => true
39 when "cyclemap", "transportmap"
43 width = params[:width]
44 height = params[:height]
46 redirect_to "https://tile.thunderforest.com/static/#{style[..-4]}/#{lon},#{lat},#{zoom}/#{width}x#{height}.#{format}?apikey=#{Settings.thunderforest_key}", :allow_other_host => true