Skip to content

Commit

Permalink
Add handling overwriting sharepoint file
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsierant committed Oct 16, 2024
1 parent 06035c5 commit e7340fe
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions apps/api/lib/buildel/blocks/sharepoint_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,20 @@ defmodule Buildel.Blocks.SharepointClient do
def handle_input("create", {_name, :binary, path, metadata}, state) do
content = File.read!(path)

{:ok, res} = upload_document(content, metadata.file_name, state)

document = %{
"name" => res["name"],
"id" => res["id"],
"size" => res["size"],
"mime_type" => res["file"]["mimeType"],
"download_url" => res["@microsoft.graph.downloadUrl"]
}
with {:ok, res} <- upload_document(content, metadata.file_name, state) do
document = %{
"name" => res["name"],
"id" => res["id"],
"size" => res["size"],
"mime_type" => res["file"]["mimeType"],
"download_url" => res["@microsoft.graph.downloadUrl"]
}

state |> output("create", {:text, Jason.encode!(document)})
state |> output("create", {:text, Jason.encode!(document)})
else
{:error, reason} ->
state |> send_error(reason)
end
end

defp upload_document(file_content, file_path, state) do
Expand All @@ -185,8 +188,11 @@ defmodule Buildel.Blocks.SharepointClient do
{:ok, %Req.Response{status: 201, body: body}} ->
{:ok, body}

{:ok, %Req.Response{body: reason}} ->
{:error, reason}
{:ok, %Req.Response{status: 200, body: body}} ->
{:ok, body}

{:error, %Req.Response{body: reason}} ->
{:ok, reason}

{:error, reason} ->
{:error, reason}
Expand Down

0 comments on commit e7340fe

Please sign in to comment.