[deploy] Store Article's main_image path unprocessed (#10867)

This commit is contained in:
Mac Siri 2020-10-16 14:46:37 -04:00 committed by GitHub
parent f4a10e4a44
commit dd8745ca33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 13 deletions

View file

@ -34,15 +34,7 @@ class ImageUploadsController < ApplicationController
return
end
cloudinary_link(uploaders)
end
def cloudinary_link(uploaders)
links = if params[:wrap_cloudinary]
[ApplicationController.helpers.cloud_cover_url(uploaders[0].url)]
else
uploaders.map(&:url)
end
links = uploaders.map(&:url)
respond_to do |format|
format.json { render json: { links: links }, status: :ok }
end

View file

@ -73,9 +73,6 @@ function generateUploadFormdata(payload) {
formData.append('image[]', value),
);
if (payload.wrap_cloudinary) {
formData.append('wrap_cloudinary', 'true');
}
return formData;
}

View file

@ -28,7 +28,7 @@ export class ArticleCoverImage extends Component {
if (validateFileInputs()) {
const { files: image } = event.dataTransfer || event.target;
const payload = { image, wrap_cloudinary: true };
const payload = { image };
generateMainImage(payload, this.onImageUploadSuccess, this.onUploadError);
}

View file

@ -0,0 +1,15 @@
module DataUpdateScripts
class UpdateArticleMainImagePath
def run
return unless ENV["FOREM_CONTEXT"] == "forem_cloud"
Article.where.not(main_image: [nil, ""]).each do |article|
next unless article.main_image&.starts_with? "https://res.cloudinary.com/"
index = article.main_image.index(URL.url)
article.main_image = article.main_image[index..].gsub("/images/", "/remoteimages/")
article.save
end
end
end
end

View file

@ -0,0 +1,17 @@
require "rails_helper"
require Rails.root.join("lib/data_update_scripts/20201015190914_update_article_main_image_path.rb")
describe DataUpdateScripts::UpdateArticleMainImagePath do
it "update main_image to a raw path" do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("FOREM_CONTEXT").and_return("forem_cloud")
bad_path = "https://res.cloudinary.com/practicaldev/image/fetch/s--d-pOh1Z_--/c_imagga_scale,f_auto," \
"fl_progressive,h_420,q_auto,w_1000/#{URL.url}/images/i/some-image.jpeg"
article = create(:article, main_image: bad_path)
described_class.new.run
expect(article.reload.main_image).to eq(URL.url("/remoteimages/i/some-image.jpeg"))
end
end