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 3, 2024
2 parents 2c1bbb0 + 49e94af commit 7d4dc95
Show file tree
Hide file tree
Showing 31 changed files with 428 additions and 370 deletions.
6 changes: 3 additions & 3 deletions assets/js/match_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,15 @@ SearchTerm.prototype.match = function(target) {
// Should work with most my:conditions except watched.
switch (this.termSpace) {
case 'faves':
ret = this.interactionMatch(target.getAttribute('data-image-id'), 'faved', null, window.booru.interactions);
ret = this.interactionMatch(Number(target.getAttribute('data-image-id')), 'faved', null, window.booru.interactions);

break;
case 'upvotes':
ret = this.interactionMatch(target.getAttribute('data-image-id'), 'voted', 'up', window.booru.interactions);
ret = this.interactionMatch(Number(target.getAttribute('data-image-id')), 'voted', 'up', window.booru.interactions);

break;
case 'downvotes':
ret = this.interactionMatch(target.getAttribute('data-image-id'), 'voted', 'down', window.booru.interactions);
ret = this.interactionMatch(Number(target.getAttribute('data-image-id')), 'voted', 'down', window.booru.interactions);

break;
default:
Expand Down
2 changes: 1 addition & 1 deletion assets/js/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function makeRequest(verb) {
function bindSubscriptionLinks() {
delegate(document, 'fetchcomplete', {
'.js-subscription-link': event => {
const target = $('#js-subscription-target');
const target = event.target.closest('.js-subscription-target');
event.detail.text().then(text => {
target.outerHTML = text;
});
Expand Down
2 changes: 1 addition & 1 deletion assets/js/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function setupImageUpload() {
const [fileField, remoteUrl, scraperError] = $$('.js-scraper', form);
const descrEl = $('.js-image-descr-input', form);
const tagsEl = $('.js-image-tags-input', form);
const sourceEl = $$('.js-image-source', form).find(input => input.value === '');
const sourceEl = $$('.js-source-url', form).find(input => input.value === '');
const fetchButton = $('#js-scraper-preview');
if (!fetchButton) return;

Expand Down
251 changes: 158 additions & 93 deletions assets/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"jest-environment-jsdom": "^29.4.3",
"mini-css-extract-plugin": "^2.7.2",
"normalize-scss": "^7.0.1",
"postcss": "^8.4.21",
"postcss": "^8.4.31",
"postcss-loader": "^7.2.4",
"postcss-scss": "^4.0.6",
"postcss-url": "^10.1.3",
Expand Down
4 changes: 2 additions & 2 deletions docker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM elixir:1.14.4-alpine
FROM elixir:1.15.4-alpine

ADD https://api.github.com/repos/philomena-dev/FFmpeg/git/refs/heads/release/5.1 /tmp/ffmpeg_version.json
ADD https://api.github.com/repos/philomena-dev/FFmpeg/git/refs/heads/release/6.0 /tmp/ffmpeg_version.json
RUN (echo "https://github.com/philomena-dev/prebuilt-ffmpeg/raw/master"; cat /etc/apk/repositories) > /tmp/repositories \
&& cp /tmp/repositories /etc/apk/repositories \
&& apk update --allow-untrusted \
Expand Down
14 changes: 9 additions & 5 deletions lib/philomena/images.ex
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ defmodule Philomena.Images do

defp maybe_suggest_user_verification(_user), do: false

def count_pending_approvals() do
Image
|> where(hidden_from_users: false)
|> where(approved: false)
|> Repo.aggregate(:count)
def count_pending_approvals(user) do
if Canada.Can.can?(user, :approve, %Image{}) do
Image
|> where(hidden_from_users: false)
|> where(approved: false)
|> Repo.aggregate(:count)
else
nil
end
end

def feature_image(featurer, %Image{} = image) do
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/images/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ defmodule Philomena.Images.Image do
tags
|> Enum.map_join("_", & &1.slug)
|> String.to_charlist()
|> Enum.filter(&(&1 in ?a..?z or &1 in '0123456789_-'))
|> Enum.filter(&(&1 in ?a..?z or &1 in ~c"0123456789_-"))
|> List.to_string()
|> String.slice(0..150)

Expand Down
4 changes: 2 additions & 2 deletions lib/philomena/objects.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ defmodule Philomena.Objects do
download_file(source_key, file_path)
upload(dest_key, file_path)
catch
_kind, _value -> Logger.warn("Failed to copy #{source_key} -> #{dest_key}")
_kind, _value -> Logger.warning("Failed to copy #{source_key} -> #{dest_key}")
end
end

Expand Down Expand Up @@ -111,7 +111,7 @@ defmodule Philomena.Objects do
|> Enum.any?(fn {_, v} -> v == :error end)
|> case do
true ->
Logger.warn("Failed to operate on all backends")
Logger.warning("Failed to operate on all backends")

_ ->
:ok
Expand Down
6 changes: 3 additions & 3 deletions lib/philomena/search/float_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ defmodule Philomena.Search.FloatParser do

unsigned_float =
ascii_string([?0..?9], min: 1)
|> optional(ascii_char('.') |> ascii_string([?0..?9], min: 1))
|> optional(ascii_char(~c".") |> ascii_string([?0..?9], min: 1))
|> reduce({List, :to_string, []})
|> reduce(:to_number)

float =
optional(ascii_char('-+'))
optional(ascii_char(~c"-+"))
|> ascii_string([?0..?9], min: 1)
|> optional(ascii_char('.') |> ascii_string([?0..?9], min: 1))
|> optional(ascii_char(~c".") |> ascii_string([?0..?9], min: 1))
|> reduce({List, :to_string, []})
|> reduce(:to_number)

Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/search/int_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Philomena.Search.IntParser do
|> ignore()

int =
optional(ascii_char('-+'))
optional(ascii_char(~c"-+"))
|> ascii_string([?0..?9], min: 1)
|> reduce({List, :to_string, []})
|> reduce(:to_int)
Expand Down
18 changes: 9 additions & 9 deletions lib/philomena/search/ip_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ defmodule Philomena.Search.IpParser do

ipv4_octet =
choice([
ascii_char('2') |> ascii_char('5') |> ascii_char([?0..?5]),
ascii_char('2') |> ascii_char([?0..?4]) |> ascii_char([?0..?9]),
ascii_char('1') |> ascii_char([?0..?9]) |> ascii_char([?0..?9]),
ascii_char(~c"2") |> ascii_char(~c"5") |> ascii_char([?0..?5]),
ascii_char(~c"2") |> ascii_char([?0..?4]) |> ascii_char([?0..?9]),
ascii_char(~c"1") |> ascii_char([?0..?9]) |> ascii_char([?0..?9]),
ascii_char([?1..?9]) |> ascii_char([?0..?9]),
ascii_char([?0..?9])
])
Expand All @@ -16,15 +16,15 @@ defmodule Philomena.Search.IpParser do
|> concat(ipv4_octet)

ipv4_prefix =
ascii_char('/')
ascii_char(~c"/")
|> choice([
ascii_char('3') |> ascii_char([?0..?2]),
ascii_char(~c"3") |> ascii_char([?0..?2]),
ascii_char([?1..?2]) |> ascii_char([?0..?9]),
ascii_char([?0..?9])
])
|> reduce({List, :to_string, []})

ipv6_hexadectet = ascii_string('0123456789abcdefABCDEF', min: 1, max: 4)
ipv6_hexadectet = ascii_string(~c"0123456789abcdefABCDEF", min: 1, max: 4)

ipv6_ls32 =
choice([
Expand Down Expand Up @@ -115,10 +115,10 @@ defmodule Philomena.Search.IpParser do
])

ipv6_prefix =
ascii_char('/')
ascii_char(~c"/")
|> choice([
ascii_char('1') |> ascii_char('2') |> ascii_char([?0..?8]),
ascii_char('1') |> ascii_char([?0..?1]) |> ascii_char([?0..?9]),
ascii_char(~c"1") |> ascii_char(~c"2") |> ascii_char([?0..?8]),
ascii_char(~c"1") |> ascii_char([?0..?1]) |> ascii_char([?0..?9]),
ascii_char([?1..?9]) |> ascii_char([?0..?9]),
ascii_char([?0..?9])
])
Expand Down
4 changes: 2 additions & 2 deletions lib/philomena/search/lexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ defmodule Philomena.Search.Lexer do
|> ignore()

float =
optional(ascii_char('-+'))
optional(ascii_char(~c"-+"))
|> ascii_string([?0..?9], min: 1)
|> optional(ascii_char('.') |> ascii_string([?0..?9], min: 1))
|> optional(ascii_char(~c".") |> ascii_string([?0..?9], min: 1))
|> reduce({List, :to_string, []})
|> reduce(:to_number)

Expand Down
2 changes: 1 addition & 1 deletion lib/philomena/search/literal_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Philomena.Search.LiteralParser do

float =
ascii_string([?0..?9], min: 1)
|> optional(ascii_char('.') |> ascii_string([?0..?9], min: 1))
|> optional(ascii_char(~c".") |> ascii_string([?0..?9], min: 1))
|> reduce({List, :to_string, []})
|> reduce(:to_number)

Expand Down
5 changes: 4 additions & 1 deletion lib/philomena/workers/tag_change_revert_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ defmodule Philomena.TagChangeRevertWorker do
end

defp revert_all(queryable, attributes) do
Batch.query_batches(queryable, [batch_size: 100], fn queryable ->
batch_size = attributes["batch_size"] || 100
attributes = Map.delete(attributes, "batch_size")

Batch.query_batches(queryable, [batch_size: batch_size], fn queryable ->
ids = Repo.all(select(queryable, [tc], tc.id))
TagChanges.mass_revert(ids, cast_ip(atomify_keys(attributes)))
end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ defmodule PhilomenaWeb.TagChange.FullRevertController do
plug :verify_authorized
plug PhilomenaWeb.UserAttributionPlug

def create(conn, params) do
attributes = conn.assigns.attributes

def create(%{assigns: %{attributes: attributes}} = conn, params) do
attributes = %{
ip: to_string(attributes[:ip]),
fingerprint: attributes[:fingerprint],
referrer: attributes[:referrer],
user_agent: attributes[:referrer],
user_id: attributes[:user].id
user_id: attributes[:user].id,
batch_size: attributes[:batch_size] || 100
}

case params do
Expand Down
2 changes: 1 addition & 1 deletion lib/philomena_web/plugs/admin_counters_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule PhilomenaWeb.AdminCountersPlug do
defp maybe_assign_admin_metrics(conn, _user, false), do: conn

defp maybe_assign_admin_metrics(conn, user, true) do
pending_approvals = Images.count_pending_approvals()
pending_approvals = Images.count_pending_approvals(user)
duplicate_reports = DuplicateReports.count_duplicate_reports(user)
reports = Reports.count_reports(user)
artist_links = ArtistLinks.count_artist_links(user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#js-subscription-target
' Error!
.js-subscription-target
' Error!
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ elixir:
unwatch_class = if @watching, do: "", else: "hidden"

= if @conn.assigns.current_user do
span#js-subscription-target
span.js-subscription-target
a.js-subscription-link.media-box__header.media-box__header--channel.media-box__header--link href=watch_path class=watch_class data-remote="true" data-method="post"
i.fa.fa-bell>
span.hide-mobile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ul
h2 Actions
ul
li = link "Revert all tag changes", to: Routes.tag_change_full_revert_path(@conn, :create, [fingerprint: @fingerprint]), data: [confirm: "Are you really, really sure?", method: "create"]
li = link "...the button above didn't work (use carefully, this is resource-intensive)", to: Routes.tag_change_full_revert_path(@conn, :create, [fingerprint: @fingerprint, batch_size: 1]), data: [confirm: "Please confirm that you're aware that this may crash the site and are ready to take on the full wrath of the admins if it does so after you press this button.", method: "create"]

h4 Observed users
table.table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ elixir:
unwatch_class = if @watching, do: "", else: "hidden"

= if @conn.assigns.current_user do
span#js-subscription-target
span.js-subscription-target
a.js-subscription-link href=watch_path class=watch_class data-remote="true" data-method="post"
i.fa.fa-bell>
span.hide-mobile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#js-subscription-target
' Error!
.js-subscription-target
' Error!
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ elixir:
unwatch_class = if @watching, do: "", else: "hidden"

= if @conn.assigns.current_user do
span#js-subscription-target
span.js-subscription-target
a.js-subscription-link href=watch_path class=watch_class data-remote="true" data-method="post"
i.fa.fa-bell>
span.hide-mobile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#js-subscription-target
' Error!
.js-subscription-target
' Error!
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ elixir:
unwatch_class = if @watching, do: "", else: "hidden"

= if @conn.assigns.current_user do
span#js-subscription-target
span.js-subscription-target
a.js-subscription-link href=watch_path class=watch_class data-remote="true" data-method="post"
i.fa.fa-bell>
' Subscribe
Expand Down
1 change: 1 addition & 0 deletions lib/philomena_web/templates/ip_profile/show.html.slime
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ul
h2 Actions
ul
li = link "Revert all tag changes", to: Routes.tag_change_full_revert_path(@conn, :create, [ip: to_string(@ip)]), data: [confirm: "Are you really, really sure?", method: "create"]
li = link "...the button above didn't work (use carefully, this is resource-intensive)", to: Routes.tag_change_full_revert_path(@conn, :create, [ip: to_string(@ip), batch_size: 1]), data: [confirm: "Please confirm that you're aware that this may crash the site and are ready to take on the full wrath of the admins if it does so after you press this button.", method: "create"]

h4 Observed users
table.table
Expand Down
12 changes: 9 additions & 3 deletions lib/philomena_web/views/image_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ defmodule PhilomenaWeb.ImageView do
|> display_order()
|> Enum.map_join("_", & &1.slug)
|> String.to_charlist()
|> Enum.filter(&(&1 in ?a..?z or &1 in '0123456789_-+'))
|> Enum.filter(&(&1 in ?a..?z or &1 in ~c"0123456789_-+"))
|> List.to_string()
|> String.slice(0..150)

Expand Down Expand Up @@ -225,7 +225,11 @@ defmodule PhilomenaWeb.ImageView do
def hidden_toggle(%{assigns: %{current_user: nil}}, _route, _params), do: nil

def hidden_toggle(conn, route, params) do
render(PhilomenaWeb.ImageView, "_hidden_toggle.html", route: route, params: params, conn: conn)
render(PhilomenaWeb.ImageView, "_hidden_toggle.html",
route: route,
params: params,
conn: conn
)
end

def deleted_toggle(conn, route, params) do
Expand Down Expand Up @@ -367,7 +371,9 @@ defmodule PhilomenaWeb.ImageView do
"pettingzoo.co",
"pony.social",
"vulpine.club",
"yiff.life"
"yiff.life",
"socel.net",
"octodon.social"
] ->
"fab fa-mastodon"

Expand Down
6 changes: 4 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ defmodule Philomena.MixProject do
{:jason, "~> 1.4"},
{:ranch, "~> 2.1", override: true},
{:plug_cowboy, "~> 2.6"},
{:slime, "~> 1.3.0",
github: "liamwhite/slime", ref: "cd4ced179197daa596bbb9d313f3808103c9624e", override: true},
{:phoenix_slime, "~> 0.13",
github: "slime-lang/phoenix_slime", ref: "8944de91654d6fcf6bdcc0aed6b8647fe3398241"},
{:phoenix_pubsub_redis, "~> 3.0"},
Expand All @@ -58,8 +60,8 @@ defmodule Philomena.MixProject do
{:nimble_parsec, "~> 1.2"},
{:canary, "~> 1.1"},
{:scrivener_ecto, "~> 2.7"},
{:pbkdf2, "~> 2.0",
github: "code-time/erlang-pbkdf2", ref: "f8f0012a97f58ade9c70ac93260e4259e4ca4b8d"},
{:pbkdf2, ">= 0.0.0",
github: "basho/erlang-pbkdf2", ref: "7e9bd5fcd3cc3062159e4c9214bb628aa6feb5ca"},
{:qrcode, "~> 0.1"},
{:redix, "~> 1.2"},
{:bamboo, "~> 2.2"},
Expand Down
Loading

0 comments on commit 7d4dc95

Please sign in to comment.