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