mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
plumb in spoiler execution to image loading endpoints
This commit is contained in:
parent
e6950c70c1
commit
1d23b9be55
22 changed files with 175 additions and 36 deletions
|
@ -116,7 +116,7 @@ defmodule Philomena.SpoilerExecutor do
|
|||
{id, :complex}
|
||||
|
||||
matched_tags ->
|
||||
matched_tags
|
||||
{id, matched_tags}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ defmodule PhilomenaWeb.ActivityController do
|
|||
}
|
||||
|
||||
alias Philomena.Interactions
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -102,6 +103,12 @@ defmodule PhilomenaWeb.ActivityController do
|
|||
user
|
||||
)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
[images, top_scoring, watched, featured_image]
|
||||
)
|
||||
|
||||
render(
|
||||
conn,
|
||||
"index.html",
|
||||
|
@ -114,6 +121,7 @@ defmodule PhilomenaWeb.ActivityController do
|
|||
streams: streams,
|
||||
topics: topics,
|
||||
interactions: interactions,
|
||||
spoilers: spoilers,
|
||||
layout_class: "layout--wide"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.DuplicateReportController do
|
|||
|
||||
alias Philomena.DuplicateReports
|
||||
alias Philomena.DuplicateReports.DuplicateReport
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
@ -30,9 +31,16 @@ defmodule PhilomenaWeb.DuplicateReportController do
|
|||
|> order_by(desc: :created_at)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(duplicate_reports, &[&1.image, &1.duplicate_of_image])
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Duplicate Reports",
|
||||
duplicate_reports: duplicate_reports,
|
||||
spoilers: spoilers,
|
||||
layout_class: "layout--wide"
|
||||
)
|
||||
end
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do
|
|||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.SourceChanges.SourceChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -15,10 +16,17 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do
|
|||
|> preload([:user, image: [:user, :tags]])
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(source_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Source Changes for Fingerprint `#{fingerprint}'",
|
||||
fingerprint: fingerprint,
|
||||
source_changes: source_changes
|
||||
source_changes: source_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule PhilomenaWeb.FingerprintProfile.TagChangeController do
|
|||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.TagChanges.TagChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -16,10 +17,17 @@ defmodule PhilomenaWeb.FingerprintProfile.TagChangeController do
|
|||
|> order_by(desc: :created_at)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(tag_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Tag Changes for Fingerprint `#{fingerprint}'",
|
||||
fingerprint: fingerprint,
|
||||
tag_changes: tag_changes
|
||||
tag_changes: tag_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ defmodule PhilomenaWeb.GalleryController do
|
|||
alias PhilomenaWeb.NotificationCountPlug
|
||||
alias Philomena.Elasticsearch
|
||||
alias Philomena.Interactions
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Galleries.Gallery
|
||||
alias Philomena.Galleries
|
||||
import Ecto.Query
|
||||
|
@ -33,9 +34,16 @@ defmodule PhilomenaWeb.GalleryController do
|
|||
Gallery |> preload([:creator, thumbnail: :tags])
|
||||
)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(galleries, & &1.thumbnail)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Galleries",
|
||||
galleries: galleries,
|
||||
spoilers: spoilers,
|
||||
layout_class: "layout--wide"
|
||||
)
|
||||
end
|
||||
|
@ -58,8 +66,6 @@ defmodule PhilomenaWeb.GalleryController do
|
|||
|
||||
{gallery_prev, gallery_next} = prev_next_page_images(conn, query)
|
||||
|
||||
interactions = Interactions.user_interactions([images, gallery_prev, gallery_next], user)
|
||||
|
||||
watching = Galleries.subscribed?(gallery, user)
|
||||
|
||||
prev_image = if gallery_prev, do: [gallery_prev], else: []
|
||||
|
@ -70,6 +76,9 @@ defmodule PhilomenaWeb.GalleryController do
|
|||
|
||||
Galleries.clear_notification(gallery, user)
|
||||
|
||||
interactions = Interactions.user_interactions(gallery_images, user)
|
||||
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, gallery_images)
|
||||
|
||||
conn
|
||||
|> NotificationCountPlug.call([])
|
||||
|> Map.put(:params, params)
|
||||
|
@ -83,7 +92,8 @@ defmodule PhilomenaWeb.GalleryController do
|
|||
gallery_next: gallery_next,
|
||||
gallery_images: gallery_images,
|
||||
images: images,
|
||||
interactions: interactions
|
||||
interactions: interactions,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.Image.RelatedController do
|
|||
|
||||
alias PhilomenaWeb.ImageLoader
|
||||
alias Philomena.Interactions
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Images.Image
|
||||
|
||||
plug PhilomenaWeb.CanaryMapPlug, index: :show
|
||||
|
@ -59,12 +60,14 @@ defmodule PhilomenaWeb.Image.RelatedController do
|
|||
)
|
||||
|
||||
interactions = Interactions.user_interactions(images, user)
|
||||
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, images)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "##{image.id} - Related Images",
|
||||
layout_class: "wide",
|
||||
images: images,
|
||||
interactions: interactions
|
||||
interactions: interactions,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ defmodule PhilomenaWeb.Image.ReportingController do
|
|||
alias Philomena.Images.Image
|
||||
alias Philomena.DuplicateReports.DuplicateReport
|
||||
alias Philomena.DuplicateReports
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -26,11 +27,18 @@ defmodule PhilomenaWeb.Image.ReportingController do
|
|||
%DuplicateReport{}
|
||||
|> DuplicateReports.change_duplicate_report()
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(dupe_reports, &[&1.image, &1.duplicate_of_image])
|
||||
)
|
||||
|
||||
render(conn, "show.html",
|
||||
layout: false,
|
||||
image: image,
|
||||
dupe_reports: dupe_reports,
|
||||
changeset: changeset
|
||||
changeset: changeset,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.Image.SourceChangeController do
|
|||
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.SourceChanges.SourceChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -19,10 +20,17 @@ defmodule PhilomenaWeb.Image.SourceChangeController do
|
|||
|> order_by(desc: :created_at)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(source_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Source Changes on Image #{image.id}",
|
||||
image: image,
|
||||
source_changes: source_changes
|
||||
source_changes: source_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.Image.TagChangeController do
|
|||
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.TagChanges.TagChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -20,10 +21,17 @@ defmodule PhilomenaWeb.Image.TagChangeController do
|
|||
|> order_by(desc: :created_at)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(tag_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Tag Changes on Image #{image.id}",
|
||||
image: image,
|
||||
tag_changes: tag_changes
|
||||
tag_changes: tag_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ defmodule PhilomenaWeb.ImageController do
|
|||
Galleries.Gallery
|
||||
}
|
||||
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Interactions
|
||||
alias Philomena.Comments
|
||||
alias Philomena.Repo
|
||||
|
@ -37,12 +38,14 @@ defmodule PhilomenaWeb.ImageController do
|
|||
{:ok, {images, _tags}} = ImageLoader.search_string(conn, "created_at.lte:3 minutes ago")
|
||||
|
||||
interactions = Interactions.user_interactions(images, conn.assigns.current_user)
|
||||
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, images)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Images",
|
||||
layout_class: "layout--wide",
|
||||
images: images,
|
||||
interactions: interactions
|
||||
interactions: interactions,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -66,6 +69,7 @@ defmodule PhilomenaWeb.ImageController do
|
|||
|> TextileRenderer.render_one(conn)
|
||||
|
||||
interactions = Interactions.user_interactions([image], conn.assigns.current_user)
|
||||
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, [image])
|
||||
|
||||
comment_changeset =
|
||||
%Comment{}
|
||||
|
@ -89,6 +93,7 @@ defmodule PhilomenaWeb.ImageController do
|
|||
interactions: interactions,
|
||||
watching: watching,
|
||||
layout_class: "layout--wide",
|
||||
spoilers: spoilers,
|
||||
title: "##{image.id} - #{image.tag_list_cache}"
|
||||
]
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do
|
|||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.SourceChanges.SourceChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -17,10 +18,17 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do
|
|||
|> preload([:user, image: [:user, :tags]])
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(source_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Source Changes for IP `#{ip}'",
|
||||
ip: ip,
|
||||
source_changes: source_changes
|
||||
source_changes: source_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule PhilomenaWeb.IpProfile.TagChangeController do
|
|||
use PhilomenaWeb, :controller
|
||||
|
||||
alias Philomena.TagChanges.TagChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -18,10 +19,17 @@ defmodule PhilomenaWeb.IpProfile.TagChangeController do
|
|||
|> order_by(desc: :created_at)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(tag_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Tag Changes for IP `#{ip}'",
|
||||
ip: ip,
|
||||
tag_changes: tag_changes
|
||||
tag_changes: tag_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ defmodule PhilomenaWeb.Profile.SourceChangeController do
|
|||
alias Philomena.Users.User
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.SourceChanges.SourceChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -29,10 +30,17 @@ defmodule PhilomenaWeb.Profile.SourceChangeController do
|
|||
|> order_by(desc: :created_at)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(source_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Source Changes for User `#{user.name}'",
|
||||
user: user,
|
||||
source_changes: source_changes
|
||||
source_changes: source_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
|
|||
alias Philomena.Users.User
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.TagChanges.TagChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -25,10 +26,17 @@ defmodule PhilomenaWeb.Profile.TagChangeController do
|
|||
|> order_by(desc: :created_at)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(tag_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Tag Changes for User `#{user.name}'",
|
||||
user: user,
|
||||
tag_changes: tag_changes
|
||||
tag_changes: tag_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
alias Philomena.Galleries.Gallery
|
||||
alias Philomena.Posts.Post
|
||||
alias Philomena.Comments.Comment
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Interactions
|
||||
alias Philomena.Tags.Tag
|
||||
alias Philomena.UserIps.UserIp
|
||||
|
@ -137,8 +138,11 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
|
||||
statistics = calculate_statistics(user)
|
||||
|
||||
interactions =
|
||||
Interactions.user_interactions([recent_uploads, recent_faves, recent_artwork], current_user)
|
||||
images = [recent_uploads, recent_faves, recent_artwork]
|
||||
|
||||
interactions = Interactions.user_interactions(images, current_user)
|
||||
|
||||
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, images)
|
||||
|
||||
forced = user.forced_filter
|
||||
|
||||
|
@ -153,6 +157,7 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
"show.html",
|
||||
user: user,
|
||||
interactions: interactions,
|
||||
spoilers: spoilers,
|
||||
commission_information: commission_information,
|
||||
recent_artwork: recent_artwork,
|
||||
recent_uploads: recent_uploads,
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule PhilomenaWeb.Search.ReverseController do
|
|||
use PhilomenaWeb, :controller
|
||||
|
||||
alias PhilomenaWeb.ImageReverse
|
||||
alias Philomena.SpoilerExecutor
|
||||
|
||||
plug PhilomenaWeb.ScraperCachePlug
|
||||
plug PhilomenaWeb.ScraperPlug, params_key: "image", params_name: "image"
|
||||
|
@ -12,8 +13,9 @@ defmodule PhilomenaWeb.Search.ReverseController do
|
|||
|
||||
def create(conn, %{"image" => image_params}) when is_map(image_params) do
|
||||
images = ImageReverse.images(image_params)
|
||||
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, images)
|
||||
|
||||
render(conn, "index.html", title: "Reverse Search", images: images)
|
||||
render(conn, "index.html", title: "Reverse Search", images: images, spoilers: spoilers)
|
||||
end
|
||||
|
||||
def create(conn, _params) do
|
||||
|
|
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.SearchController do
|
|||
|
||||
alias PhilomenaWeb.ImageLoader
|
||||
alias Philomena.Interactions
|
||||
alias Philomena.SpoilerExecutor
|
||||
|
||||
def index(conn, params) do
|
||||
user = conn.assigns.current_user
|
||||
|
@ -10,6 +11,7 @@ defmodule PhilomenaWeb.SearchController do
|
|||
case ImageLoader.search_string(conn, params["q"], include_hits: custom_ordering?(conn)) do
|
||||
{:ok, {images, tags}} ->
|
||||
interactions = Interactions.user_interactions(images, user)
|
||||
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, images)
|
||||
|
||||
conn
|
||||
|> render("index.html",
|
||||
|
@ -18,6 +20,7 @@ defmodule PhilomenaWeb.SearchController do
|
|||
tags: tags,
|
||||
search_query: params["q"],
|
||||
interactions: interactions,
|
||||
spoilers: spoilers,
|
||||
layout_class: "layout--wide"
|
||||
)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ defmodule PhilomenaWeb.Tag.TagChangeController do
|
|||
|
||||
alias Philomena.Tags.Tag
|
||||
alias Philomena.TagChanges.TagChange
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -20,10 +21,17 @@ defmodule PhilomenaWeb.Tag.TagChangeController do
|
|||
|> order_by(desc: :created_at)
|
||||
|> Repo.paginate(conn.assigns.scrivener)
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
Enum.map(tag_changes, & &1.image)
|
||||
)
|
||||
|
||||
render(conn, "index.html",
|
||||
title: "Tag Changes for Tag `#{tag.name}'",
|
||||
tag: tag,
|
||||
tag_changes: tag_changes
|
||||
tag_changes: tag_changes,
|
||||
spoilers: spoilers
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ defmodule PhilomenaWeb.TagController do
|
|||
alias Philomena.Elasticsearch
|
||||
alias Philomena.{Tags, Tags.Tag}
|
||||
alias PhilomenaWeb.TextileRenderer
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Interactions
|
||||
|
||||
plug PhilomenaWeb.RecodeParameterPlug, [name: "id"] when action in [:show]
|
||||
|
@ -57,6 +58,7 @@ defmodule PhilomenaWeb.TagController do
|
|||
{images, _tags} = ImageLoader.query(conn, %{term: %{"namespaced_tags.name" => tag.name}})
|
||||
|
||||
interactions = Interactions.user_interactions(images, user)
|
||||
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, images)
|
||||
|
||||
body = TextileRenderer.render_one(%{body: tag.description || ""}, conn)
|
||||
|
||||
|
@ -78,6 +80,7 @@ defmodule PhilomenaWeb.TagController do
|
|||
tags: [{tag, body, dnp_entries}],
|
||||
search_query: search_query,
|
||||
interactions: interactions,
|
||||
spoilers: spoilers,
|
||||
images: images,
|
||||
layout_class: "layout--wide",
|
||||
title: "#{tag.name} - Tags"
|
||||
|
|
|
@ -2,6 +2,7 @@ defmodule PhilomenaWeb.ImageFilterPlug do
|
|||
import Plug.Conn
|
||||
import Philomena.Search.String
|
||||
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Images.Query
|
||||
|
||||
# No options
|
||||
|
@ -14,7 +15,7 @@ defmodule PhilomenaWeb.ImageFilterPlug do
|
|||
forced = defaults(conn.assigns[:forced_filter])
|
||||
|
||||
tag_exclusion = %{terms: %{tag_ids: filter.hidden_tag_ids ++ forced.hidden_tag_ids}}
|
||||
query_spoiler = invalid_filter_guard(user, filter.spoilered_complex_str)
|
||||
query_spoiler = SpoilerExecutor.compile_spoiler(user, filter)
|
||||
|
||||
query_exclusion = %{
|
||||
bool: %{
|
||||
|
@ -32,8 +33,7 @@ defmodule PhilomenaWeb.ImageFilterPlug do
|
|||
}
|
||||
|
||||
conn
|
||||
|> assign(:compiled_complex_filter, query_exclusion)
|
||||
|> assign(:compiled_complex_spoiler, query_spoiler)
|
||||
|> assign(:compiled_spoiler, query_spoiler)
|
||||
|> assign(:compiled_filter, query)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
defmodule PhilomenaWeb.TextileRenderer do
|
||||
alias Philomena.Textile.Parser
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.SpoilerExecutor
|
||||
alias Philomena.Repo
|
||||
import Phoenix.HTML
|
||||
import Phoenix.HTML.Link
|
||||
|
@ -17,7 +18,7 @@ defmodule PhilomenaWeb.TextileRenderer do
|
|||
opts = %{image_transform: &Camo.Image.image_url/1}
|
||||
parsed = Enum.map(posts, &Parser.parse(opts, &1.body))
|
||||
|
||||
images =
|
||||
{images, spoilers} =
|
||||
parsed
|
||||
|> Enum.flat_map(fn tree ->
|
||||
tree
|
||||
|
@ -29,7 +30,7 @@ defmodule PhilomenaWeb.TextileRenderer do
|
|||
[]
|
||||
end)
|
||||
end)
|
||||
|> find_images
|
||||
|> find_images(conn)
|
||||
|
||||
parsed
|
||||
|> Enum.map(fn tree ->
|
||||
|
@ -38,7 +39,7 @@ defmodule PhilomenaWeb.TextileRenderer do
|
|||
{:text, text} ->
|
||||
text
|
||||
|> replacement_entities()
|
||||
|> replacement_images(conn, images)
|
||||
|> replacement_images(conn, spoilers, images)
|
||||
|
||||
{_k, markup} ->
|
||||
markup
|
||||
|
@ -59,7 +60,7 @@ defmodule PhilomenaWeb.TextileRenderer do
|
|||
|> String.replace("'", "’")
|
||||
end
|
||||
|
||||
defp replacement_images(t, conn, images) do
|
||||
defp replacement_images(t, conn, spoilers, images) do
|
||||
t
|
||||
|> String.replace(~r|>>(\d+)([pts])?|, fn match ->
|
||||
# Stupid, but the method doesn't give us capture group information
|
||||
|
@ -78,6 +79,7 @@ defmodule PhilomenaWeb.TextileRenderer do
|
|||
Phoenix.View.render(@image_view, "_image_target.html",
|
||||
image: image,
|
||||
size: :medium,
|
||||
spoilers: spoilers,
|
||||
conn: conn
|
||||
)
|
||||
|> safe_to_string()
|
||||
|
@ -86,6 +88,7 @@ defmodule PhilomenaWeb.TextileRenderer do
|
|||
Phoenix.View.render(@image_view, "_image_target.html",
|
||||
image: image,
|
||||
size: :small,
|
||||
spoilers: spoilers,
|
||||
conn: conn
|
||||
)
|
||||
|> safe_to_string()
|
||||
|
@ -94,6 +97,7 @@ defmodule PhilomenaWeb.TextileRenderer do
|
|||
Phoenix.View.render(@image_view, "_image_target.html",
|
||||
image: image,
|
||||
size: :thumb_small,
|
||||
spoilers: spoilers,
|
||||
conn: conn
|
||||
)
|
||||
|> safe_to_string()
|
||||
|
@ -105,24 +109,32 @@ defmodule PhilomenaWeb.TextileRenderer do
|
|||
end)
|
||||
end
|
||||
|
||||
defp find_images(text_segments) do
|
||||
defp find_images(text_segments, conn) do
|
||||
text_segments
|
||||
|> Enum.flat_map(fn t ->
|
||||
Regex.scan(~r|>>(\d+)|, t, capture: :all_but_first)
|
||||
|> Enum.map(fn [first] -> String.to_integer(first) end)
|
||||
|> Enum.filter(&(&1 < 2_147_483_647))
|
||||
end)
|
||||
|> load_images()
|
||||
|> load_images(conn)
|
||||
end
|
||||
|
||||
defp load_images([]), do: %{}
|
||||
defp load_images([], _conn), do: {%{}, %{}}
|
||||
|
||||
defp load_images(ids) do
|
||||
defp load_images(ids, conn) do
|
||||
images =
|
||||
Image
|
||||
|> where([i], i.id in ^ids)
|
||||
|> where([i], i.hidden_from_users == false)
|
||||
|> preload(:tags)
|
||||
|> Repo.all()
|
||||
|> Map.new(&{&1.id, &1})
|
||||
|
||||
spoilers =
|
||||
SpoilerExecutor.execute_spoiler(
|
||||
conn.assigns.compiled_spoiler,
|
||||
images
|
||||
)
|
||||
|
||||
{Map.new(images, &{&1.id, &1}), spoilers}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue