Skip to content

Commit

Permalink
Merge pull request #48 from podlove/fix/media-upload
Browse files Browse the repository at this point in the history
fix(server) - upload media handling http error
  • Loading branch information
dnkbln authored Sep 9, 2024
2 parents 4c18048 + 1bd1387 commit 03c9364
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions server/lib/publisher/wordpress/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ defmodule Publisher.WordPress.API do
{:ok, response} = Req.get(req, url: "podlove/v2/episodes")
"""
def new(headers) do
def new(headers, opts \\ []) do
user = get_header_value(headers, "wordpress-user")
password = get_header_value(headers, "wordpress-password")
site = get_header_value(headers, "wordpress-site")

default_connect_options = [transport_opts: [verify: :verify_none]]
http1 = Keyword.get(opts, :http1, false)

connect_options =
if http1 do
Keyword.put(default_connect_options, :protocols, [:http1])
else
default_connect_options
end

Req.new(
base_url: site <> "/wp-json/",
headers: [{"Content-Type", "application/json"}],
auth: {:basic, user <> ":" <> password},
connect_options: [transport_opts: [verify: :verify_none]]
connect_options: connect_options
)
end

Expand Down
2 changes: 1 addition & 1 deletion server/lib/publisher/wordpress/episode.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Publisher.WordPress.Episode do
alias Publisher.WordPress.Media

def save(conn, params) do
req = API.new(conn.req_headers)
req = API.new(conn.req_headers, http1: true)

with episode_id <- find_or_create_episode(req, params["guid"]),
post_id <- fetch_post_id(req, episode_id),
Expand Down
4 changes: 2 additions & 2 deletions server/lib/publisher/wordpress/podcast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule Publisher.WordPress.Podcast do
# Logger.log(:info, "user: #{user}, endpoint: #{site}/wp-json/wp/v2/media")
Logger.log(:info, "body { name: #{image_name}, type: #{image_type} }")

req = API.new(headers)
req = API.new(headers, http1: true)

with {:ok, source_url} <- Media.upload_image(req, base64_image, image_name, image_type),
{:ok, info} <- save_podcast_image_url(req, source_url) do
Expand All @@ -93,7 +93,7 @@ defmodule Publisher.WordPress.Podcast do
# Logger.log(:info, "user: #{user}, endpoint: #{site}/wp-json/wp/v2/media")
Logger.log(:info, "body { name: #{image_name}, url: #{image_url} }")

req = API.new(headers)
req = API.new(headers, http1: true)

with {:ok, source_url} <- Media.upload_media_from_url(req, image_url, image_name),
{:ok, info} <- save_podcast_image_url(req, source_url) do
Expand Down

0 comments on commit 03c9364

Please sign in to comment.