Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Very basic version of Dropbox 'ls' working.

  • Loading branch information...
commit 96040c0de9798815f0b8b5b3a8d61f6b2c98317a 1 parent 5b9eee6
Adam Koprowski akoprow authored
Showing with 38 additions and 4 deletions.
  1. +8 −0 resources/style.css
  2. +30 −4 src/dropbox.opa
8 resources/style.css
View
@@ -28,3 +28,11 @@
.prompt {
color: #0BC;
}
+pre {
+ display: block !important;
+ white-space: pre !important;
+ font-family: monospace !important;
+ background-color: transparent !important;
+ padding: 0px !important;
+ margin: 0px !important;
+}
34 src/dropbox.opa
View
@@ -77,7 +77,7 @@ Please re-run your application with: --dropbox-config option")
executor(connect)
}
- function authenticate() {
+ private function authenticate() {
token = DB.OAuth.get_request_token(redirect)
Log.info("Dropbox", "Obtained request token {token}")
match (token) {
@@ -92,12 +92,38 @@ Please re-run your application with: --dropbox-config option")
}
}
+ private function pad(length, s) {
+ String.pad_left(" ", length, s)
+ }
+
+ private date_printer = Date.generate_printer("%Y-%m-%d %k:%M")
+
+ private function show_element(Dropbox.element element) {
+ info =
+ match (element) {
+ case {file, ~metadata, ...}: metadata
+ case {folder, ~metadata, ...}: metadata
+ }
+ size = "{info.size}"
+ modification = Option.map(Date.to_formatted_string(date_printer, _), info.modified) ? ""
+ name = info.path
+ <pre>{size |> pad(10, _)} {modification |> pad(16, _)} {name}</>
+ }
+
+ private function files_to_xhtml(files) {
+ <>{List.map(show_element, files)}</>
+ }
+
function ls(creds) {
match (creds) {
case {authenticated: creds}:
- files = DB.Files("dropbox", "/").metadata(DB.default_metadata_options, creds)
- ls_xhtml = <>Files: {files}</>
- Service.respond_with(ls_xhtml)
+ db_files = DB.Files("dropbox", "/").metadata(DB.default_metadata_options, creds)
+ response =
+ match (db_files) {
+ case {success: {~contents, ...}}: files_to_xhtml(contents ? [])
+ default: <>Dropbox connection failed</>
+ }
+ Service.respond_with(response)
default:
authenticate()
}
Please sign in to comment.
Something went wrong with that request. Please try again.