Skip to content

Commit

Permalink
Dropbox: shared links
Browse files Browse the repository at this point in the history
  • Loading branch information
achlipala committed Feb 13, 2021
1 parent e3db45b commit 92ae962
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/dropboxDemo.ur
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ fun create r =
return <xml><body>ID: {[m.Id]}</body></xml>

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;
Expand Down
81 changes: 81 additions & 0 deletions src/ur/dropbox.ur
Original file line number Diff line number Diff line change
Expand Up @@ -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 <xml>Bad Dropbox visibility {[x]}</xml>)
(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 <xml>Bad Dropbox audience {[x]}</xml>)
(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 <xml>Bad Dropbox access level {[x]}</xml>)
(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

Expand Down Expand Up @@ -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
33 changes: 33 additions & 0 deletions src/ur/dropbox.urs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit 92ae962

Please sign in to comment.