-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working implementation of surf research drive storage
- Loading branch information
Showing
14 changed files
with
213 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
defmodule Systems.Storage.SurfResearchDrive.Backend do | ||
@behaviour Systems.Storage.Backend | ||
|
||
alias Systems.Storage.SurfResearchDrive | ||
|
||
require Logger | ||
|
||
def store( | ||
%{ | ||
"user" => username, | ||
"password" => password, | ||
"url" => url, | ||
"folder" => folder | ||
} = _endpoint, | ||
data, | ||
meta_data | ||
) do | ||
filename = filename(meta_data) | ||
file_url = url([url, folder, filename]) | ||
|
||
credentials = Base.encode64("#{username}:#{password}") | ||
|
||
headers = [ | ||
{"Authorization", "Basic #{credentials}"} | ||
] | ||
|
||
case HTTPoison.put(file_url, data, headers) do | ||
{:ok, %{status_code: 201}} -> | ||
:ok | ||
|
||
{_, %{status_code: status_code, body: body}} -> | ||
{:error, "status_code=#{status_code},message=#{body}"} | ||
|
||
{:error, error} -> | ||
Logger.error("[SurfResearchDrive.Backend] #{error}") | ||
{:error, error} | ||
end | ||
end | ||
|
||
def list_files(_endpoint) do | ||
Logger.error("Not yet implemented: list_files/1") | ||
{:error, :not_implemented} | ||
end | ||
|
||
def delete_files(_endpoint) do | ||
Logger.error("Not yet implemented: delete_files/1") | ||
{:error, :not_implemented} | ||
end | ||
|
||
def connected?(_), do: false | ||
|
||
defp filename(%{"identifier" => identifier}) do | ||
identifier | ||
|> Enum.map_join("_", fn [key, value] -> "#{key}-#{value}" end) | ||
|> then(&"#{&1}.json") | ||
end | ||
|
||
defp url(components) do | ||
URI.encode(Enum.join(components, "/")) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Systems.Storage.SurfResearchDrive.EndpointForm do | ||
use Systems.Storage.EndpointForm.Helper, Systems.Storage.SurfResearchDrive.EndpointModel | ||
|
||
import Systems.Storage.Html | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<div> | ||
<.form id={"#{@id}_surfresearchdrive_endpoint_form"} :let={form} for={@changeset} phx-change="change" phx-submit="save" phx-target={@myself}> | ||
<div class="flex flex-col gap-4"> | ||
<.text_input form={form} field={:user} label_text={dgettext("eyra-storage", "surfresearchdrive.user.label")} debounce="0" reserve_error_space={false} /> | ||
<.password_input form={form} field={:password} label_text={dgettext("eyra-storage", "surfresearchdrive.password.label")} debounce="0" reserve_error_space={false} /> | ||
<.text_input form={form} field={:url} label_text={dgettext("eyra-storage", "surfresearchdrive.url.label")} placeholder="https://{url}/remote.php/webdav/>" debounce="0" reserve_error_space={false} /> | ||
<.text_input form={form} field={:folder} label_text={dgettext("eyra-storage", "surfresearchdrive.folder.label")} debounce="0" reserve_error_space={false} /> | ||
<div class="flex flex-row gap-4 items-center mt-2"> | ||
<Button.dynamic_bar buttons={[@submit_button]} /> | ||
<%= if @show_status do %> | ||
<.account_status connected?={@connected?}/> | ||
<% end %> | ||
</div> | ||
</div> | ||
</.form> | ||
</div> | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
defmodule Systems.Storage.SurfResearchDrive.EndpointModel do | ||
use Ecto.Schema | ||
use Frameworks.Utility.Schema | ||
|
||
import Ecto.Changeset | ||
alias Systems.Storage.SurfResearchDrive | ||
|
||
@fields ~w(user password url folder)a | ||
@required_fields @fields | ||
|
||
@derive {Jason.Encoder, only: @fields} | ||
@derive {Inspect, except: [:user, :password]} | ||
schema "storage_endpoints_surfresearchdrive" do | ||
field(:user, :string) | ||
field(:password, :string) | ||
field(:url, :string) | ||
field(:folder, :string) | ||
|
||
timestamps() | ||
end | ||
|
||
def changeset(endpoint, params) do | ||
endpoint | ||
|> cast(params, @fields) | ||
end | ||
|
||
def validate(changeset) do | ||
changeset | ||
|> validate_required(@required_fields) | ||
end | ||
|
||
def ready?(endpoint) do | ||
changeset = | ||
changeset(endpoint, %{}) | ||
|> validate() | ||
|
||
changeset.valid?() | ||
end | ||
|
||
def preload_graph(:down), do: [] | ||
|
||
defimpl Frameworks.Concept.ContentModel do | ||
alias Systems.Storage.SurfResearchDrive | ||
def form(_), do: SurfResearchDrive.EndpointForm | ||
def ready?(endpoint), do: SurfResearchDrive.EndpointModel.ready?(endpoint) | ||
end | ||
end |