Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
58 lines
1.5 KiB
Ruby
58 lines
1.5 KiB
Ruby
class ArticleKeyConverter
|
|
def initialize(article)
|
|
@article = article
|
|
end
|
|
|
|
def process
|
|
new_content = replace(@article.content)
|
|
@article.update(content: new_content)
|
|
end
|
|
|
|
private
|
|
|
|
def convert_key(id)
|
|
verifier_name = 'ActiveStorage'
|
|
key_generator = ActiveSupport::KeyGenerator.new(Rails.application.secrets.secret_key_base, iterations: 1000,
|
|
hash_digest_class: OpenSSL::Digest::SHA1)
|
|
key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator)
|
|
secret = key_generator.generate_key(verifier_name.to_s)
|
|
verifier = ActiveSupport::MessageVerifier.new(secret)
|
|
|
|
begin
|
|
ActiveStorage::Blob.find(verifier.verify(id, purpose: :blob_id))
|
|
.try(:signed_id)
|
|
rescue StandardError
|
|
nil
|
|
end
|
|
end
|
|
|
|
def replace(text)
|
|
keys = get_keys(text)
|
|
keys.each do |key|
|
|
new_key = convert_key(key)
|
|
text = text.gsub(key, new_key) if new_key
|
|
end
|
|
text
|
|
end
|
|
|
|
def get_keys(text)
|
|
uris = text.scan(URI::DEFAULT_PARSER.make_regexp).flatten.select do |x|
|
|
x.to_s.include?('rails/active_storage')
|
|
end
|
|
|
|
uris.map { |x| x.split('/')[-2] }
|
|
end
|
|
end
|
|
|
|
# rubocop:disable Style/OneClassPerFile
|
|
class UpdateArticleImageKeys < ActiveRecord::Migration[7.0]
|
|
def change
|
|
# Iterate through all articles
|
|
Article.find_each do |article|
|
|
# Run the ArticleKeyConverter for each one
|
|
ArticleKeyConverter.new(article).process
|
|
end
|
|
end
|
|
end
|
|
# rubocop:enable Style/OneClassPerFile
|