webinos/Webinos-Platform — pull request #490 by felixjendrusch (2013-02-28 12:39:54+00:00)
Title: Multiple file systems

Jira issue: [WP-44](http://jira.webinos.org/browse/WP-44), [WP-601](http://jira.webinos.org/browse/WP-601), [WP-694](http://jira.webinos.org/browse/WP-694)

## Overview

* Zap and Shake/Slide and Share demo hack solved ([WP-44](http://jira.webinos.org/browse/WP-44)).
* `resolveLocalFileSystemURL` and `toURL` are no longer supported
* `getLink` asynchronously generates a temporary URL (`FileEntry` only).
* Support for multiple file systems ([WP-601](http://jira.webinos.org/browse/WP-601)).
* Including support for local file systems and dropbox file systems.
* Configuration in `webinos_config.json` (subject to changes).
* Remove unnecessary dependencies ([WP-694](http://jira.webinos.org/browse/WP-694)).
* Removed `inherits`, added `express@3.1.x`, `node-uuid@1.4.x`, and `dbox@0.5.x`.
* Keeping `mkdirp@0.3.x` for now.

## Shares

We are now introducing the concept of *shares*, i.e., a shared folder on one of the supported file systems (currently local and dropbox). At the moment, shares are configured in the `webinos_config.json`. This will change however, when opinions about configuration of webinos eventually converge.

### Local shares

Sharing a folder from the local file system requires creating a named share including the full path to the folder. The default `webinos_config.json` includes an example (excerpt):

```json
{ "name" : "file"
, "params" :
{ "local" :
{ "shares" :
[ { "name" : "desktop"
, "path" : "/path/to/desktop"
}
]
}
}
}
```

Generating temporary URLs and serving underlying content from the local file system also requires setting up a server (default: `localhost:9999`):

```json
{ "name" : "file"
, "params" :
{ "local" :
{ "server" :
{ "port" : 9999
, "hostname" : "localhost"
}
}
}
}
```

### Dropbox shares

In addition to creating a named share including the full path to the folder rooted at the webinos app folder, sharing a folder from a dropbox file system requires an access token, which can be obtained as follows (copied from [sintaxi/node-dbox](https://github.com/sintaxi/node-dbox)).

#### Step 1

Create an `app` using application credentials provided by dropbox.

```javascript
var dbox = require("dbox")
var app = dbox.app({ "app_key": "38j04m9q86j2zva", "app_secret": "pzl7f411nu6dy4p" })
```

#### Step 2

Authorization is a three step process.

a) Get a request token.

```javascript
var request_token
app.requesttoken(function (status, value) {
request_token = value
})
```

b) Visit the URL to grant authorization.

`https://www.dropbox.com/1/oauth/authorize?oauth_token=#{ request_token.oauth_token }`

c) Generate the access token with the request token.

```javascript
app.accesstoken(request_token, function (status, access_token) {
console.log(access_token)
})
```

#### Step 3

Configure webinos to use the obtained access token and set up the desired shares (excerpt):

```json
{ "name" : "file"
, "params" :
{ "dropbox" :
{ "access_token" :
{ "oauth_token_secret" : "a12bc3d4e5fghi6"
, "oauth_token" : "ab1c2defghijklm"
, "uid" : "1234567"
}
, "shares" :
[ { "name" : "full"
, "path" : "/"
}
]
}
}
}
```

Generating temporary URLs and serving underlying content from a dropbox file system is delegated to dropbox.

## Security & Policies

Instead of enforcing any origin-specific security checks as originally specified (see [File API: Directories and System](http://www.w3.org/TR/file-system-api/)), access control is delegated to the Policies API. Unfortunately, persistently attaching policies to dynamic services is an open issue. Further investigation is required.