File system drivers are normally bundled with scopes drivers (see Scopes Drivers). Normally, before a file system driver is accessed, the user should authenticate the corresponding scope (e.g., the "https://www.googleapis.com/auth/drive" scope in the "google_scopes" driver).
After the scope is authenticated and the correspoding credentials stored (in the registry or in some other place), the corresponding remote file system can be mounted. After mounting, a virtual subdirectory within webAppOS user's home directory will be available (we call this directory a mount point).
To mount a remote file system, the registry key "users/[login]/fs_mount_points/[path/to/mount/point]" with the value equal to the remote location string must be created. The location string must start with the driver-specific prefix, e.g., "onedrive:" or "gdrive:", followed by the driver-specific remote location.
The prefix will be used by webAppOS Home File System to determine the driver implementation. Normally, the driver should implement server-side File System API. However, to support serverless webAppOS applications, the file system driver can also provide a client-side implementation of File System API.
The driver must check occasionally the registry key mentioned above as well as the credentials used to connect to the remote file system. In case the registry key is not present or credentials have changed, the driver must consider that the mount point has been unmounted.
The server-side implementation must implement the org.webappos.fs.IFileSystem Java interface (see webAppOS File System API) and specify the corresponding implementation class in service.properties:
fs_driver=some.java.package.JavaClassImplementingIFileSystem
# extends org.webappos.fs.IFileSystem;
fs_prefix="gdrive:"
# some prefix that will be used by webAppOS Home File System
# to determine the file system driver, which will serve the corresponding mount point
The class constructor must take two string arguments: the location of the remote file system and the options string. User's credentials (access tokens) must be taken from the registry (or where the corresponding scopes driver saved them). If the scopes driver authenticated multiple accounts, the options string can specify the account name to use.
The client-side implementation (for serverless access) must be accessible via services/[scopes_driver_name]/[fs_prefix]_fs_driver.js
The [fs_prefix]_fs_driver.js must define an asynchronous (AMD) module that returns a JavaScript constructor function implementing webAppOS File System API.
The constructor function must take two arguments: the location of the remote file system and the options. It must return a JavaScript object implementing methods from org.webappos.fs.IFileSystem (however, the downloadFile function must return a URL string instead of java.io.InputStream).
define(function(){
var ...; // private properties
return function(location, options) {
this.copyPath = async function(src, dst) {
...
};
this.createDirectory = async function(path) {
...
};
... // other functions from IFileSystem implemented in JavaScript,
// however, the downloadFile function must return a URL string
// instead of java.io.InputStream
return this;
};
})