From 92ae96225e9318eae50b4a9ae1fe797b747438b5 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sat, 13 Feb 2021 16:31:46 -0500 Subject: [PATCH] Dropbox: shared links --- examples/dropboxDemo.ur | 6 ++- src/ur/dropbox.ur | 81 +++++++++++++++++++++++++++++++++++++++++ src/ur/dropbox.urs | 33 +++++++++++++++++ 3 files changed, 118 insertions(+), 2 deletions(-) diff --git a/examples/dropboxDemo.ur b/examples/dropboxDemo.ur index 3f61420..b80ac3d 100644 --- a/examples/dropboxDemo.ur +++ b/examples/dropboxDemo.ur @@ -9,8 +9,10 @@ fun create r = return ID: {[m.Id]} fun download path = - r <- D.Files.getTemporaryLink path; - redirect (bless r.Link) + u <- D.Sharing.createSharedLinkWithSettings {Path = path, + Settings = Api.optionals {RequestedVisibility = Dropbox.VisPublic, + Access = Dropbox.Viewer}}; + redirect (bless u) fun req id = r <- D.FileRequests.get id; diff --git a/src/ur/dropbox.ur b/src/ur/dropbox.ur index cfcc94b..4d2d10e 100644 --- a/src/ur/dropbox.ur +++ b/src/ur/dropbox.ur @@ -183,6 +183,81 @@ type path = { } val _ : json path = json_record {Path = "path"} +datatype requested_visibility = + VisPublic + | VisTeamOnly + | VisPassword +val _ : json requested_visibility = json_derived + (fn x => + case x of + "public" => VisPublic + | "team_only" => VisTeamOnly + | "password" => VisPassword + | _ => error Bad Dropbox visibility {[x]}) + (fn x => + case x of + VisPublic => "public" + | VisTeamOnly => "team_only" + | VisPassword => "password") + +datatype link_audience = + AudPublic + | AudTeam + | AudNoOne + | AudPassword +val _ : json link_audience = json_derived + (fn x => + case x of + "public" => AudPublic + | "team" => AudTeam + | "no_one" => AudNoOne + | "password" => AudPassword + | _ => error Bad Dropbox audience {[x]}) + (fn x => + case x of + AudPublic => "public" + | AudTeam => "team" + | AudNoOne => "no_one" + | AudPassword => "password") + +datatype requested_link_access_level = + Viewer + | Editor + | Max +val _ : json requested_link_access_level = json_derived + (fn x => + case x of + "viewer" => Viewer + | "editor" => Editor + | "max" => Max + | _ => error Bad Dropbox access level {[x]}) + (fn x => + case x of + Viewer => "viewer" + | Editor => "editor" + | Max => "max") + +type shared_link_settings = { + RequestedVisibility : option requested_visibility, + LinkPassword : option string, + Expires : option time, + Audience : option link_audience, + Access : option requested_link_access_level +} +val _ : json shared_link_settings = json_record_withOptional {} + {RequestedVisibility = "requested_visibility", + LinkPassword = "link_password", + Expires = "expires", + Audience = "audience", + Access = "access"} + +type shared_link_parameters = { + Path : string, + Settings : shared_link_settings +} +val _ : json shared_link_parameters = json_record {Path = "path", + Settings = "settings"} + functor Make(M : AUTH) = struct open M @@ -250,4 +325,10 @@ functor Make(M : AUTH) = struct r <- api "files/get_temporary_link" (toJson {Path = p}); return (fromJson r) end + + structure Sharing = struct + fun createSharedLinkWithSettings p = + r <- api "sharing/create_shared_link_with_settings" (toJson p); + return (fromJson r : shared_link).Url + end end diff --git a/src/ur/dropbox.urs b/src/ur/dropbox.urs index 3e67bd8..a154bdb 100644 --- a/src/ur/dropbox.urs +++ b/src/ur/dropbox.urs @@ -76,6 +76,35 @@ type temporary_link = { Link : string } +datatype requested_visibility = + VisPublic + | VisTeamOnly + | VisPassword + +datatype link_audience = + AudPublic + | AudTeam + | AudNoOne + | AudPassword + +datatype requested_link_access_level = + Viewer + | Editor + | Max + +type shared_link_settings = { + RequestedVisibility : option requested_visibility, + LinkPassword : option string, + Expires : option time, + Audience : option link_audience, + Access : option requested_link_access_level +} + +type shared_link_parameters = { + Path : string, + Settings : shared_link_settings +} + functor Make(M : AUTH) : sig structure FileRequests : sig val list : transaction (list file_request) @@ -87,4 +116,8 @@ functor Make(M : AUTH) : sig val listFolder : list_folder_parameters -> transaction (list metadata) val getTemporaryLink : string (* path *) -> transaction temporary_link end + + structure Sharing : sig + val createSharedLinkWithSettings : shared_link_parameters -> transaction string (* url *) + end end