From 43f3ea193f4f9e08d96157db634f7f6331c3b29b Mon Sep 17 00:00:00 2001 From: Thelonius Kort Date: Wed, 15 Mar 2023 10:56:30 +0100 Subject: [PATCH] Add miscellaneous stuff --- .iex-local.exs | 1 - lib/outlook/authors.ex | 2 +- lib/outlook/authors/author.ex | 2 +- lib/outlook/translators/deepl.ex | 2 ++ lib/outlook_web/view_helpers.ex | 6 ++++++ 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.iex-local.exs b/.iex-local.exs index 9fdad06..24c171f 100644 --- a/.iex-local.exs +++ b/.iex-local.exs @@ -3,7 +3,6 @@ alias Outlook.HtmlPreparations.HtmlPreparation alias Outlook.InternalTree.{Html,InternalNode,TranslationUnit} alias Outlook.InternalTree alias Outlook.Articles -alias Outlook.Artikel alias Outlook.Accounts alias Outlook.Articles.Article alias Outlook.Authors diff --git a/lib/outlook/authors.ex b/lib/outlook/authors.ex index 6edb2e1..c0a3f6c 100644 --- a/lib/outlook/authors.ex +++ b/lib/outlook/authors.ex @@ -39,7 +39,7 @@ defmodule Outlook.Authors do def get_author_with_articles!(id) do Repo.get!(Author, id) - |> Repo.preload([:articles]) + |> Repo.preload([articles: :translations]) end @doc """ diff --git a/lib/outlook/authors/author.ex b/lib/outlook/authors/author.ex index 704f5bb..957763d 100644 --- a/lib/outlook/authors/author.ex +++ b/lib/outlook/authors/author.ex @@ -9,7 +9,7 @@ defmodule Outlook.Authors.Author do field :homepage_name, :string field :homepage_url, :string field :name, :string - has_many :articles, Article + has_many :articles, Article, on_delete: :delete_all timestamps() end diff --git a/lib/outlook/translators/deepl.ex b/lib/outlook/translators/deepl.ex index d852251..49fd77e 100644 --- a/lib/outlook/translators/deepl.ex +++ b/lib/outlook/translators/deepl.ex @@ -54,10 +54,12 @@ defmodule Outlook.Translators.Deepl do ) response = Jason.decode!(response_raw.body, keys: :atoms) + require Logger case response do %{status: "done"} -> response %{status: status} -> + Logger.debug "Deepl response: #{response |> inspect}" steps = Map.get(response, :seconds_remaining, 1) * 5 for n <- 0..steps do send(pid, {:progress, %{progress: 100 * n / steps, status: status}}) diff --git a/lib/outlook_web/view_helpers.ex b/lib/outlook_web/view_helpers.ex index 6fe5245..91e6e65 100644 --- a/lib/outlook_web/view_helpers.ex +++ b/lib/outlook_web/view_helpers.ex @@ -12,4 +12,10 @@ defmodule OutlookWeb.ViewHelpers do def tidy_raw(whatever) do whatever end + + # TODO: implement (and use) the following function + @doc "Strip tags to prevent broken html (or 'breaking') from user input." + def strip_links(html) do + raise "Yet to be implemented!" + end end