From 6a93e8d3bf68c03644e5b453e61f7e8e5066a124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Fri, 12 Nov 2021 15:40:49 +0100 Subject: [PATCH] media endpoint --- app/controllers/media_controller.rb | 2 +- app/views/active_storage/blobs/jekyll.html.erb | 5 ++++- test/models/variant_service_test.rb | 2 -- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index e8710637f..1a0aefdc4 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -6,6 +6,6 @@ class MediaController < ApplicationController blob_or_variant_url = transformations.empty? ? url_for(@blob) : url_for(@blob.variant(transformations)) - render json: { transformations: transformations, url: blob_or_variant_url } + redirect_to blob_or_variant_url end end diff --git a/app/views/active_storage/blobs/jekyll.html.erb b/app/views/active_storage/blobs/jekyll.html.erb index 5591fe2bd..34b0c7c1f 100644 --- a/app/views/active_storage/blobs/jekyll.html.erb +++ b/app/views/active_storage/blobs/jekyll.html.erb @@ -1,6 +1,9 @@ <% width, height = @blob.metadata.values_at('width', 'height') ratio = width.present? && height.present? ? (width.to_f / height.to_f) : nil +university = University.find_by(id: @blob.university_id) +base_url = university&.url || "" +media_endpoint_path = medium_path(signed_id: @blob.signed_id, filename_with_transformations: @blob.filename) %> <%# TODO: Replace @blob.url with the media endpoint when it's ready %> <%= raw({ @@ -9,5 +12,5 @@ ratio = width.present? && height.present? ? (width.to_f / height.to_f) : nil "width" => width, "height" => height, "ratio" => ratio, - "url" => @blob.url + "url" => "#{base_url}#{media_endpoint_path}" }.compact.to_yaml) %> diff --git a/test/models/variant_service_test.rb b/test/models/variant_service_test.rb index dcbe6cd51..62858b2e9 100644 --- a/test/models/variant_service_test.rb +++ b/test/models/variant_service_test.rb @@ -6,12 +6,10 @@ class VariantServiceTest < ActiveSupport::TestCase include ActiveRecord::TestFixtures setup do - ActiveStorage::Current.host = "https://example.com" @was_tracking, ActiveStorage.track_variants = ActiveStorage.track_variants, false end teardown do - ActiveStorage::Current.reset ActiveStorage.track_variants = @was_tracking end -- GitLab