Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite committed Mar 25, 2024
2 parents 75aea3e + 1f44047 commit ace039a
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 24 deletions.
13 changes: 10 additions & 3 deletions assets/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,19 @@ function listenAutocomplete() {
document.addEventListener('input', event => {
removeParent();
fetchLocalAutocomplete(event);
window.clearTimeout(timeout);

if (localAc !== null && 'ac' in event.target.dataset) {
inputField = event.target;
originalTerm = `${inputField.value}`.toLowerCase();

const suggestions = localAc.topK(originalTerm, 5).map(({ name, imageCount }) => ({ label: `${name} (${imageCount})`, value: name }));
return showAutocomplete(suggestions, originalTerm, event.target);

if (suggestions.length) {
return showAutocomplete(suggestions, originalTerm, event.target);
}
}

window.clearTimeout(timeout);
// Use a timeout to delay requests until the user has stopped typing
timeout = window.setTimeout(() => {
inputField = event.target;
Expand All @@ -158,7 +161,11 @@ function listenAutocomplete() {
}
else {
// inputField could get overwritten while the suggestions are being fetched - use event.target
getSuggestions(fetchedTerm).then(suggestions => showAutocomplete(suggestions, fetchedTerm, event.target));
getSuggestions(fetchedTerm).then(suggestions => {
if (fetchedTerm === event.target.value) {
showAutocomplete(suggestions, fetchedTerm, event.target);
}
});
}
}
}, 300);
Expand Down
3 changes: 1 addition & 2 deletions assets/js/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ function formResult({target, detail}) {

const elements = {
'#description-form': '.image-description',
'#uploader-form': '.image_uploader',
'#source-form': '#image-source'
'#uploader-form': '.image_uploader'
};

function showResult(resultEl, formEl, response) {
Expand Down
16 changes: 15 additions & 1 deletion assets/js/sources.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inputDuplicatorCreator } from './input-duplicator';

function imageSourcesCreator() {
function setupInputs() {
inputDuplicatorCreator({
addButtonSelector: '.js-image-add-source',
fieldSelector: '.js-image-source',
Expand All @@ -9,4 +9,18 @@ function imageSourcesCreator() {
});
}

function imageSourcesCreator() {
setupInputs();
document.addEventListener('fetchcomplete', ({ target, detail }) => {
const sourceSauce = document.querySelector('.js-sourcesauce');

if (target.matches('#source-form')) {
detail.text().then(text => {
sourceSauce.outerHTML = text;
setupInputs();
});
}
});
}

export { imageSourcesCreator };
12 changes: 6 additions & 6 deletions lib/philomena/galleries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ defmodule Philomena.Galleries do
|> case do
{:ok, result} ->
Images.reindex_image(image)
notify_gallery(gallery)
notify_gallery(gallery, image)
reindex_gallery(gallery)

{:ok, result}
Expand Down Expand Up @@ -261,11 +261,11 @@ defmodule Philomena.Galleries do
|> Repo.aggregate(:max, :position)
end

def notify_gallery(gallery) do
Exq.enqueue(Exq, "notifications", NotificationWorker, ["Galleries", gallery.id])
def notify_gallery(gallery, image) do
Exq.enqueue(Exq, "notifications", NotificationWorker, ["Galleries", [gallery.id, image.id]])
end

def perform_notify(gallery_id) do
def perform_notify([gallery_id, image_id]) do
gallery = get_gallery!(gallery_id)

subscriptions =
Expand All @@ -279,8 +279,8 @@ defmodule Philomena.Galleries do
%{
actor_id: gallery.id,
actor_type: "Gallery",
actor_child_id: nil,
actor_child_type: nil,
actor_child_id: image_id,
actor_child_type: "Image",
action: "added images to"
}
)
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/scrapers/twitter.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Philomena.Scrapers.Twitter do
@url_regex ~r|\Ahttps?://(?:mobile\.)?twitter.com/([A-Za-z\d_]+)/status/([\d]+)/?|
@url_regex ~r|\Ahttps?://(?:mobile\.)?(?:twitter\|x).com/([A-Za-z\d_]+)/status/([\d]+)/?|

@spec can_handle?(URI.t(), String.t()) :: true | false
def can_handle?(_uri, url) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule PhilomenaWeb.Autocomplete.TagController do
|> Elasticsearch.search_records(preload(Tag, :aliased_tag))
|> Enum.map(&(&1.aliased_tag || &1))
|> Enum.uniq_by(& &1.id)
|> Enum.filter(&(&1.images_count > 3))
|> Enum.filter(&(&1.images_count > 0))
|> Enum.sort_by(&(-&1.images_count))
|> Enum.take(5)
|> Enum.map(&%{label: "#{&1.name} (#{&1.images_count})", value: &1.name})
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena_web/templates/image/_source.html.slime
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.block
.js-sourcesauce
- has_sources = Enum.any?(@image.sources)
= form_for @changeset, Routes.image_source_path(@conn, :update, @image), [method: "put", class: "hidden", id: "source-form", data: [remote: "true"]], fn f ->
= if can?(@conn, :edit_metadata, @image) and [email protected]_ban do
Expand Down
45 changes: 36 additions & 9 deletions lib/philomena_web/views/image_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,24 @@ defmodule PhilomenaWeb.ImageView do
uri = URI.parse(source)

case uri.host do
u when u in ["twitter.com", "www.twitter.com", "pbs.twimg.com", "twimg.com"] ->
u
when u in [
"twitter.com",
"www.twitter.com",
"mobile.twitter.com",
"x.com",
"mobile.x.com",
"pbs.twimg.com",
"twimg.com"
] ->
"fab fa-twitter"

u when u in ["deviantart.com", "www.deviantart.com", "sta.sh", "www.sta.sh"] ->
u
when u in ["deviantart.com", "sta.sh", "www.sta.sh"] ->
"fab fa-deviantart"

u when u in ["cdn.discordapp.com", "discordapp.com", "discord.com"] ->
u
when u in ["cdn.discordapp.com", "discordapp.com", "discord.com", "media.discordapp.net"] ->
"fab fa-discord"

u when u in ["youtube.com", "www.youtube.com"] ->
Expand All @@ -329,7 +340,14 @@ defmodule PhilomenaWeb.ImageView do
u when u in ["patreon.com", "www.patreon.com"] ->
"fab fa-patreon"

u when u in ["ych.art", "ych.commishes.com", "commishes.com"] ->
u
when u in [
"ych.art",
"ych.commishes.com",
"commishes.com",
"portfolio.commishes.com",
"commishes.io"
] ->
"fa fa-palette"

u when u in ["artstation.com", "www.artstation.com"] ->
Expand All @@ -354,7 +372,8 @@ defmodule PhilomenaWeb.ImageView do
"furbooru.org",
"inkbunny.net",
"e621.net",
"e926.net"
"e926.net",
"sofurry.com"
] ->
"fa fa-paw"

Expand All @@ -373,16 +392,24 @@ defmodule PhilomenaWeb.ImageView do
"vulpine.club",
"yiff.life",
"socel.net",
"octodon.social"
"octodon.social",
"filly.social",
"pone.social",
"hooves.social"
] ->
"fab fa-mastodon"

u
when u in ["tumbex.com", "www.tumbex.com", "tumblr.com"] ->
"fab fa-tumblr"

link ->
cond do
Enum.member?(site_domains, link) -> "favicon-home"
String.contains?(link, "tumblr") -> "fab fa-tumblr"
String.contains?(link, "deviantart") -> "fab fa-deviantart"
String.contains?(link, "sofurry") -> "fa fa-paw"
String.ends_with?(link, ".tumblr.com") -> "fab fa-tumblr"
String.ends_with?(link, ".deviantart.com") -> "fab fa-deviantart"
String.ends_with?(link, ".sofurry.com") -> "fa fa-paw"
String.ends_with?(link, ".userapi.com") -> "fab fa-vk"
true -> "fa fa-link"
end
end
Expand Down

0 comments on commit ace039a

Please sign in to comment.