Skip to content
Snippets Groups Projects
Unverified Commit e6baf226 authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

added variant urls to medias

parent d8d4f769
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@
# filename :string
# identifier :string
# mime_type :string
# variant_urls :text default([]), is an Array
# created_at :datetime
# updated_at :datetime
# university_id :uuid not null
......@@ -36,7 +37,7 @@ class Communication::Website::Imported::Medium < ApplicationRecord
has_one_attached_deletable :file
after_commit :download_file_from_file_url, on: [:create, :update], if: :saved_change_to_file_url
scope :for_variant_url, -> (variant_url) { where('? = ANY(variant_urls)', variant_url) }
def data=(value)
super value
......@@ -46,11 +47,12 @@ class Communication::Website::Imported::Medium < ApplicationRecord
self.mime_type = value['mime_type']
self.created_at = value['date_gmt']
self.updated_at = value['modified_gmt']
self.variant_urls = (value['media_details']['sizes'] || {}).values.map { |variant|
Addressable::URI.parse(variant['source_url']).display_uri.to_s
}
end
protected
def download_file_from_file_url
def load_remote_file!
uri = URI(file_url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
......@@ -60,5 +62,4 @@ class Communication::Website::Imported::Medium < ApplicationRecord
response = http.request(request)
file.attach(io: StringIO.new(response.body), filename: filename, content_type: mime_type)
end
handle_asynchronously :download_file_from_file_url, queue: 'default'
end
class AddVariantUrlsToCommunicationWebsiteImportedMedia < ActiveRecord::Migration[6.1]
def change
add_column :communication_website_imported_media, :variant_urls, :text, array: true, default: []
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_26_035253) do
ActiveRecord::Schema.define(version: 2021_10_26_094556) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
......@@ -88,6 +88,7 @@ ActiveRecord::Schema.define(version: 2021_10_26_035253) do
t.uuid "website_id", null: false
t.string "filename"
t.string "mime_type"
t.text "variant_urls", default: [], array: true
t.index ["university_id"], name: "index_communication_website_imported_media_on_university_id"
t.index ["website_id"], name: "index_communication_website_imported_media_on_website_id"
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment