fixing ALL the formatting

This commit is contained in:
Chaska 2024-04-29 19:56:15 -05:00
parent b8134d4237
commit efd7aa704c
12 changed files with 119 additions and 86 deletions

View file

@ -63,7 +63,8 @@ defmodule Philomena.ArtistLinks.ArtistLink do
def validate_category(changeset) do
tag = get_field(changeset, :tag)
if not is_nil(tag) and tag.category not in ["origin", "oc", "director", "writer", "colorist", "content-fanmade"] do
if not is_nil(tag) and
tag.category not in ["origin", "oc", "director", "writer", "colorist", "content-fanmade"] do
add_error(changeset, :tag, "must be a creator, fanmade, or oc tag")
else
changeset

View file

@ -74,8 +74,7 @@ defmodule Philomena.DnpEntries.DnpEntry do
"I only want to allow art of a certain type or from a certain location to be uploaded to CubFur"},
{"With Permission Only",
"I only want people with my permission to be allowed to upload my art to CubFur"},
{"Artist Upload Only",
"I want to be the only person allowed to upload my art to CubFur"},
{"Artist Upload Only", "I want to be the only person allowed to upload my art to CubFur"},
{"Other", "I would like a DNP entry under other conditions"}
]
end

View file

@ -4,9 +4,13 @@ defmodule Philomena.Images.TagValidator do
def validate_tags(changeset) do
blacklist = Config.get(:tag)["blacklist"]
tags = changeset |> get_field(:tags) |> Enum.reject(fn x ->
x.name in blacklist
end)
tags =
changeset
|> get_field(:tags)
|> Enum.reject(fn x ->
x.name in blacklist
end)
validate_tag_input(changeset, tags)
end
@ -49,9 +53,10 @@ defmodule Philomena.Images.TagValidator do
end
def strip_bad_words(changeset, tags) do
tag_input = tags
|> Enum.reduce([], fn x, acc -> [x.name | acc] end)
|> Enum.join(", ")
tag_input =
tags
|> Enum.reduce([], fn x, acc -> [x.name | acc] end)
|> Enum.join(", ")
changeset
|> put_change(:tag_input, tag_input)

View file

@ -7,24 +7,26 @@ defmodule Philomena.Scrapers.Derpibooru do
end
def scrape(_uri, url) do
[_, submission_id] = Regex.run(@url_regex, url, capture: :all)
[_, submission_id] = Regex.run(@url_regex, url, capture: :all)
api_url = "https://derpibooru.org/api/v1/json/images/#{submission_id}"
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)
json = Jason.decode!(body)
submission = json["image"]
tags = submission["tags"]
%{
source_url: url,
tags: tags,
sources: submission["source_urls"],
description: submission["description"],
images: [%{
url: "#{submission["representations"]["full"]}",
camo_url: Camo.Image.image_url(submission["representations"]["medium"])
}]
images: [
%{
url: "#{submission["representations"]["full"]}",
camo_url: Camo.Image.image_url(submission["representations"]["medium"])
}
]
}
end
end
end

View file

@ -14,16 +14,19 @@ defmodule Philomena.Scrapers.E621 do
submission = json["post"]
tags = submission["tags"]["general"] ++ submission["tags"]["species"]
tags = for x <- tags do
String.replace(x, "_", " ")
end
rating = case submission["rating"] do
"s" -> "safe"
"q" -> "suggestive"
"e" -> "explicit"
_ -> nil
end
tags =
for x <- tags do
String.replace(x, "_", " ")
end
rating =
case submission["rating"] do
"s" -> "safe"
"q" -> "suggestive"
"e" -> "explicit"
_ -> nil
end
tags = if is_nil(rating), do: tags, else: [rating | tags]
@ -33,15 +36,19 @@ defmodule Philomena.Scrapers.E621 do
tags: tags,
sources: submission["sources"],
description: submission["description"],
images: [%{
url: "#{submission["file"]["url"]}",
camo_url: Camo.Image.image_url(submission["file"]["url"])
}]
images: [
%{
url: "#{submission["file"]["url"]}",
camo_url: Camo.Image.image_url(submission["file"]["url"])
}
]
}
end
defp e621_user do
Application.get_env(:philomena, :e621_user)
end
defp e621_apikey do
Application.get_env(:philomena, :e621_apikey)
end

View file

@ -13,19 +13,21 @@ defmodule Philomena.Scrapers.Furaffinity do
submission = Jason.decode!(body)
rating = case submission["rating"] do
"General" -> "safe"
"Mature" -> "suggestive"
"Adult" -> "explicit"
_ -> nil
end
rating =
case submission["rating"] do
"General" -> "safe"
"Mature" -> "suggestive"
"Adult" -> "explicit"
_ -> nil
end
description = submission["description"]
|> HtmlSanitizeEx.strip_tags()
|> String.replace(~r/ +/, " ")
|> String.replace(~r/\n \n +/, "\n")
|> String.replace(~r/\n /, "\n")
|> String.trim()
description =
submission["description"]
|> HtmlSanitizeEx.strip_tags()
|> String.replace(~r/ +/, " ")
|> String.replace(~r/\n \n +/, "\n")
|> String.replace(~r/\n /, "\n")
|> String.trim()
%{
source_url: url,

View file

@ -7,24 +7,26 @@ defmodule Philomena.Scrapers.Furbooru do
end
def scrape(_uri, url) do
[_, submission_id] = Regex.run(@url_regex, url, capture: :all)
[_, submission_id] = Regex.run(@url_regex, url, capture: :all)
api_url = "https://furbooru.org/api/v1/json/images/#{submission_id}"
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)
json = Jason.decode!(body)
submission = json["image"]
tags = submission["tags"]
%{
source_url: url,
tags: tags,
sources: submission["source_urls"],
description: submission["description"],
images: [%{
url: "#{submission["representations"]["full"]}",
camo_url: Camo.Image.image_url(submission["representations"]["medium"])
}]
images: [
%{
url: "#{submission["representations"]["full"]}",
camo_url: Camo.Image.image_url(submission["representations"]["medium"])
}
]
}
end
end
end

View file

@ -7,18 +7,23 @@ defmodule Philomena.Scrapers.Inkbunny do
end
def scrape(_uri, url) do
[_, submission_id] = Regex.run(@url_regex, url, capture: :all)
api_url = "https://inkbunny.net/api_submissions.php?show_description=yes&sid=#{inkbunny_sid()}&submission_ids=#{submission_id}"
[_, submission_id] = Regex.run(@url_regex, url, capture: :all)
api_url =
"https://inkbunny.net/api_submissions.php?show_description=yes&sid=#{inkbunny_sid()}&submission_ids=#{submission_id}"
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)
json = Jason.decode!(body)
[submission] = json["submissions"]
images = for x <- submission["files"] do
%{
url: "#{x["file_url_full"]}",
camo_url: Camo.Image.image_url(x["file_url_preview"])
}
end
images =
for x <- submission["files"] do
%{
url: "#{x["file_url_full"]}",
camo_url: Camo.Image.image_url(x["file_url_preview"])
}
end
%{
source_url: url,
@ -27,6 +32,7 @@ defmodule Philomena.Scrapers.Inkbunny do
images: images
}
end
defp inkbunny_sid do
Application.get_env(:philomena, :inkbunny_sid)
end

View file

@ -16,26 +16,30 @@ defmodule Philomena.Scrapers.Pixiv do
description = submission["illust_details"]["comment"]
images = if submission["illust_details"]["manga_a"] do
submission["illust_details"]["manga_a"]
else
[submission["illust_details"]]
end
images =
if submission["illust_details"]["manga_a"] do
submission["illust_details"]["manga_a"]
else
[submission["illust_details"]]
end
images = for x <- images do
pre = x["url_small"] || x["url_s"]
{:ok, %Tesla.Env{status: 200, body: body, headers: headers}}
= Philomena.Http.get(pre, [{"Referer", "https://pixiv.net/"}])
images =
for x <- images do
pre = x["url_small"] || x["url_s"]
type = headers
|> Enum.into(%{})
|> Map.get("content-type")
{:ok, %Tesla.Env{status: 200, body: body, headers: headers}} =
Philomena.Http.get(pre, [{"Referer", "https://pixiv.net/"}])
%{
url: x["url"],
camo_url: "data:#{type};base64,#{Base.encode64(body)}"
}
end
type =
headers
|> Enum.into(%{})
|> Map.get("content-type")
%{
url: x["url"],
camo_url: "data:#{type};base64,#{Base.encode64(body)}"
}
end
%{
source_url: url,

View file

@ -14,11 +14,12 @@ defmodule PhilomenaWeb.ScraperPlug do
conn
%{"scraper_cache" => url} when not is_nil(url) and url != "" ->
headers = if String.contains?(url, "pximg.net") do
[{"Referer", "https://pixiv.net/"}]
else
[]
end
headers =
if String.contains?(url, "pximg.net") do
[{"Referer", "https://pixiv.net/"}]
else
[]
end
url
|> Philomena.Http.get(headers)

View file

@ -328,13 +328,15 @@ defmodule PhilomenaWeb.ImageView do
"fav.me"
] ->
"fab fa-deviantart"
u
when u in [
"inkbunny.net",
"ib.metapix.net",
"tx.ib.metapix.net"
] ->
"fa-solid fa-carrot"
"inkbunny.net",
"ib.metapix.net",
"tx.ib.metapix.net"
] ->
"fa-solid fa-carrot"
u
when u in [
"cdn.discordapp.com",
@ -450,7 +452,7 @@ defmodule PhilomenaWeb.ImageView do
u when u in ["etsy.com", "www.etsy.com"] ->
"fab fa-etsy"
u when u in ["derpibooru.org", "derpicdn.net"] ->
"fa-solid fa-horse-head"

View file

@ -35,6 +35,7 @@
"gettext": {:hex, :gettext, "0.24.0", "6f4d90ac5f3111673cbefc4ebee96fe5f37a114861ab8c7b7d5b30a1108ce6d8", [:mix], [{:expo, "~> 0.5.1", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "bdf75cdfcbe9e4622dd18e034b227d77dd17f0f133853a1c73b97b3d6c770e8b"},
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"html_sanitize_ex": {:hex, :html_sanitize_ex, "1.4.3", "67b3d9fa8691b727317e0cc96b9b3093be00ee45419ffb221cdeee88e75d1360", [:mix], [{:mochiweb, "~> 2.15 or ~> 3.1", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm", "87748d3c4afe949c7c6eb7150c958c2bcba43fc5b2a02686af30e636b74bccb7"},
"httpoison": {:hex, :httpoison, "1.8.2", "9eb9c63ae289296a544842ef816a85d881d4a31f518a0fec089aaa744beae290", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "2bb350d26972e30c96e2ca74a1aaf8293d61d0742ff17f01e0279fef11599921"},
"hut": {:hex, :hut, "1.4.0", "7a1238ec00f95c9ec75412587ee11ac652eca308a7f4b8cc9629746d579d6cf0", [:"erlang.mk", :rebar3], [], "hexpm", "7af8704b9bae98a336f70d9560fc3c97f15665265fa603dbd05352e63d6ebb03"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
@ -45,6 +46,7 @@
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"mint": {:hex, :mint, "1.5.2", "4805e059f96028948870d23d7783613b7e6b0e2fb4e98d720383852a760067fd", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "d77d9e9ce4eb35941907f1d3df38d8f750c357865353e21d335bdcdf6d892a02"},
"mix_audit": {:hex, :mix_audit, "2.1.2", "6cd5c5e2edbc9298629c85347b39fb3210656e541153826efd0b2a63767f3395", [:make, :mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:yaml_elixir, "~> 2.9", [hex: :yaml_elixir, repo: "hexpm", optional: false]}], "hexpm", "68d2f06f96b9c445a23434c9d5f09682866a5b4e90f631829db1c64f140e795b"},
"mochiweb": {:hex, :mochiweb, "3.2.2", "bb435384b3b9fd1f92f2f3fe652ea644432877a3e8a81ed6459ce951e0482ad3", [:rebar3], [], "hexpm", "4114e51f1b44c270b3242d91294fe174ce1ed989100e8b65a1fab58e0cba41d5"},
"neotoma": {:hex, :neotoma, "1.7.3", "d8bd5404b73273989946e4f4f6d529e5c2088f5fa1ca790b4dbe81f4be408e61", [:rebar], [], "hexpm", "2da322b9b1567ffa0706a7f30f6bbbde70835ae44a1050615f4b4a3d436e0f28"},
"nimble_options": {:hex, :nimble_options, "1.1.0", "3b31a57ede9cb1502071fade751ab0c7b8dbe75a9a4c2b5bbb0943a690b63172", [:mix], [], "hexpm", "8bbbb3941af3ca9acc7835f5655ea062111c9c27bcac53e004460dfd19008a99"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},