[deploy] Store Article's main_image path unprocessed (#10867)
This commit is contained in:
parent
f4a10e4a44
commit
dd8745ca33
5 changed files with 34 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -73,9 +73,6 @@ function generateUploadFormdata(payload) {
|
|||
formData.append('image[]', value),
|
||||
);
|
||||
|
||||
if (payload.wrap_cloudinary) {
|
||||
formData.append('wrap_cloudinary', 'true');
|
||||
}
|
||||
return formData;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue