From bc7a4594e7e08bda95522351c8e5dc8ed472ee95 Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Wed, 3 Nov 2021 12:49:41 -0700 Subject: [PATCH] Adjust TMS redirects for google cloud, new route redirect style (#1548) * Adjust TMS redirects for google cloud, new route redirect style * Update utility_controller.rb * Apply suggestions from code review * Update _cloud_exports.html.erb * Update tms_info.html.erb * Delete utility_controller_test.rb * Update routes.rb * Update utility_controller.rb * Update app/controllers/utility_controller.rb * Update utility_controller.rb * Update .codecov.yml * Update _cloud_exports.html.erb --- .codecov.yml | 5 ++++- app/controllers/utility_controller.rb | 15 ++++++++------- app/views/maps/_cloud_exports.html.erb | 7 ++++++- app/views/utility/tms_info.html.erb | 12 +++++++++--- config/routes.rb | 3 ++- test/controllers/utility_controller_test.rb | 19 ------------------- 6 files changed, 29 insertions(+), 32 deletions(-) delete mode 100644 test/controllers/utility_controller_test.rb diff --git a/.codecov.yml b/.codecov.yml index 6875bfe0..97754ac0 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -8,4 +8,7 @@ comment: coverage: status: project: on - patch: on + patch: + default: + target: 50% + threshold: 5% diff --git a/app/controllers/utility_controller.rb b/app/controllers/utility_controller.rb index fdbdf938..1ffa7c8b 100644 --- a/app/controllers/utility_controller.rb +++ b/app/controllers/utility_controller.rb @@ -1,10 +1,11 @@ class UtilityController < ApplicationController - # translates TMS formats from one ordering to another - def tms_alt - # /z/x/y.png - # /z/x/y.png - # /z/x/(2*z-y-1).png - y = 2**params[:z].to_i - params[:y].to_i - 1 - redirect_to("/tms/#{params[:id]}/#{params[:z]}/#{params[:x]}/#{y}.png") + # TMS redirects now handled mostly in config/routes.rb + + # most export TMS routes are handled in app/views/maps/_cloud_exports.html.erb, but this may catch some too + # if no static local file exists in format /tms/:id/:z/:x/:y.png, this action handles the request + def tms + unless Map.find_by(slug: params[:id]) # if no map with the given slug is found, record_not_found is thrown + redirect_to("https://mapknitter-exports-warps.storage.googleapis.com/#{params[:id]}/tms/#{params[:z]}/#{params[:x]}/#{params[:y]}.png") + end end end diff --git a/app/views/maps/_cloud_exports.html.erb b/app/views/maps/_cloud_exports.html.erb index d6c8649a..2b9d8fb7 100644 --- a/app/views/maps/_cloud_exports.html.erb +++ b/app/views/maps/_cloud_exports.html.erb @@ -5,7 +5,7 @@ <% exports.order(created_at: :desc).each_with_index do |export, i| %>

Export <%= exports.count - i %>: - ">Status: + ">Status:

<% end %> @@ -36,6 +36,8 @@ var addExport, collectExportUrls; console.log(response, response.status); var status_el = export_el.find('.status-container'); var slug = status_el.attr('data-slug'); + var slug_el = export_el.find('.slug-el'); + var slug = slug_el.attr('data-slug'); status_el.html(''); if (response.status != "complete") status_el.append(' '); @@ -47,6 +49,9 @@ var addExport, collectExportUrls; if (response.geotiff && typeof response.geotiff === "boolean") status_el.append(' GeoTiff'); else if (response.geotiff) status_el.append(' GeoTiff'); + if (response.tms && typeof response.tms === "boolean") status_el.append(' TMS'); + else if (response.zip) status_el.append(' TMS'); + if (response.zip && typeof response.zip === "boolean") status_el.append(' TMS (zip)'); else if (response.zip) status_el.append(' TMS (zip)'); diff --git a/app/views/utility/tms_info.html.erb b/app/views/utility/tms_info.html.erb index d9093bfe..2c378393 100644 --- a/app/views/utility/tms_info.html.erb +++ b/app/views/utility/tms_info.html.erb @@ -1,9 +1,15 @@ -
+ diff --git a/config/routes.rb b/config/routes.rb index c9551c94..19930209 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -42,7 +42,8 @@ Mapknitter::Application.routes.draw do get 'images/revert', to: 'images#revert' get 'images/:url', to: 'images#fetch' - get 'tms/:id/alt/:z/:x/:y.png', to: 'utility#tms_alt' + get 'tms/:id/alt/:z/:x/:y.png', to: redirect {|params, req| "/tms/#{params[:id]}/#{params[:z]}/#{params[:x]}/#{2**params[:z].to_i - params[:y].to_i - 1}.png"} + get 'tms/:id/:z/:x/:y.png', to: 'utility#tms_redirect' get 'tms/:id/', to: 'utility#tms_info' get 'tms/:id/alt/', to: 'utility#tms_info' diff --git a/test/controllers/utility_controller_test.rb b/test/controllers/utility_controller_test.rb deleted file mode 100644 index c929329d..00000000 --- a/test/controllers/utility_controller_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' - -class UtilityControllerTest < ActionController::TestCase - test 'should translate tms format' do - get(:tms_alt, - params: { - id: 1, - x: 10, - y: 30, - z: 40 - } - ) - - y = 2**40.to_i - 30.to_i - 1 - assert_redirected_to "/tms/1/40/10/#{y}.png" - end -end