-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dataset : ajout de colonnes pour logos personnalisés (#3741)
* Add custom_logos columns and use them * Add script to generate logos and output commands * Move bucket URL to config
- Loading branch information
1 parent
318a225
commit 8c9bb84
Showing
9 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
apps/transport/priv/repo/migrations/20240123133743_dataset_custom_logos_columns.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule DB.Repo.Migrations.DatasetCustomLogosColumns do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:dataset) do | ||
add(:custom_logo, :string) | ||
add(:custom_full_logo, :string) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Run script: | ||
# `elixir scripts/custom_logo.exs /tmp/logo.jpg f0700f5f9954` | ||
Mix.install([{:image, "~> 0.37"}]) | ||
|
||
require Logger | ||
|
||
cellar_base_url = "http://transport-data-gouv-fr-logos-prod.cellar-c2.services.clever-cloud.com/" | ||
|
||
{[], [src_path, datagouv_id]} = OptionParser.parse!(System.argv(), strict: [src_path: :string, datagouv_id: :string]) | ||
|
||
extension = src_path |> Path.extname() |> String.downcase() | ||
|
||
logo_filename = "#{datagouv_id}#{extension}" | ||
full_logo_filename = "#{datagouv_id}_full#{extension}" | ||
logo_path = "/tmp/#{logo_filename}" | ||
full_logo_path = "/tmp/#{full_logo_filename}" | ||
|
||
src_path | ||
|> Image.thumbnail!(100) | ||
|> Image.embed!(100, 100, background_color: :white) | ||
|> Image.write!(logo_path) | ||
|
||
src_path | ||
|> Image.thumbnail!(500) | ||
|> Image.write!(full_logo_path) | ||
|
||
Logger.info("Logos have been generated to:\n- #{logo_path}\n- #{full_logo_path}") | ||
|
||
commands = | ||
[logo_path, full_logo_path] | ||
|> Enum.map_join("\n", fn path -> | ||
"s3cmd put --acl-public --add-header='Cache-Control: public, max-age=604800' #{path} s3://transport-data-gouv-fr-logos-prod/" | ||
end) | ||
|
||
Logger.info("Run the following commands to upload files.\n#{commands}") | ||
|
||
Logger.info( | ||
"Query:\nUPDATE dataset SET custom_logo = '#{cellar_base_url}#{logo_filename}', custom_full_logo = '#{cellar_base_url}#{full_logo_filename}' WHERE datagouv_id = '#{datagouv_id}';" | ||
) |