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 7, 2024
2 parents c6dbd11 + 886539c commit dfebf9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
24 changes: 16 additions & 8 deletions lib/philomena/scrapers/twitter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ defmodule Philomena.Scrapers.Twitter do
def scrape(_uri, url) do
[user, status_id] = Regex.run(@url_regex, url, capture: :all_but_first)

image_url = "https://d.fxtwitter.com/#{user}/status/#{status_id}.jpg"
api_url = "https://api.fxtwitter.com/#{user}/status/#{status_id}"
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)

{:ok, %Tesla.Env{status: 200}} = Philomena.Http.head(image_url)
json = Jason.decode!(body)

images =
Enum.map(json["tweet"]["media"]["photos"], fn p ->
%{
url: large_format(p["url"]),
camo_url: Camo.Image.image_url(p["url"])
}
end)

%{
source_url: "https://twitter.com/#{user}/status/#{status_id}",
author_name: user,
images: [
%{
url: image_url,
camo_url: Camo.Image.image_url(image_url)
}
]
images: images
}
end

defp large_format(str) do
String.replace_suffix(str, ".jpg", "?format=jpg&name=large")
end
end
10 changes: 7 additions & 3 deletions lib/philomena_web/templates/registration/edit.html.slime
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ p
h3 API Key
p
' Your API key is
code>
= @current_user.authentication_token
' - you can use this to allow API consumers to access your account.
#api-key-button>
code>
= link("Click to show", to: "#", data: [click_show: "#api-key", click_hide: "#api-key-button"])
#api-key.hidden>
code>
= @current_user.authentication_token
p You can use this to allow API consumers to access your account.
p
' Avoid sharing this key with others, as it could be used to compromise
' your account.
Expand Down
6 changes: 5 additions & 1 deletion lib/philomena_web/templates/setting/edit.html.slime
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ h1 Content Settings
p
' RSS feed link (for Newsblur, RSSOwl, Thunderbird, etc.):
br
= url_input f, :subscribe_url, value: Routes.api_rss_watched_url(@conn, :index, key: @conn.assigns.current_user.authentication_token), class: "input input--wide"
#rss-feed-button>
code>
= link("Click to show", to: "#", data: [click_show: "#rss-link", click_hide: "#rss-feed-button"])
#rss-link.hidden
= url_input f, :subscribe_url, value: Routes.api_rss_watched_url(@conn, :index, key: @conn.assigns.current_user.authentication_token), class: "input input--wide"
br
' Do not share this URL with anyone, it may allow an attacker to compromise your account.

Expand Down

0 comments on commit dfebf9d

Please sign in to comment.