From a4a890e9d626f385121b6fd3445b530ae369a3bc Mon Sep 17 00:00:00 2001 From: Alex Hoyau Date: Sat, 2 Jul 2016 22:05:27 +0200 Subject: [PATCH] license and readme (#1) --- LICENSE | 22 +++++++ README.md | 188 ++++++++++-------------------------------------------- 2 files changed, 55 insertions(+), 155 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b8de5aa --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License + +Copyright (c) 2010-2016 Google, Inc. http://angularjs.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/README.md b/README.md index 83e1e96..e193d0f 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,14 @@ [![Build Status](https://travis-ci.org/silexlabs/unifile.png?branch=master)](https://travis-ci.org/silexlabs/unifile) -Express middleware to provide web services for accessing cloud storage services with a common API. - -> [Here is the API online documentation with code samples in Javascript, node.js, python...](http://docs.unifile.apiary.io/) +Nodejs library to access cloud storage services with a common API. Currently supported services * FTP * Dropbox * GitHub: use git as a cloud with repository and branches as folder -* local web server: auth and browse a given folder on the server where unifile is running -* self hosting mode (we call it "open pages"): auth with [Mozilla persona](https://www.mozilla.org/en-US/persona/), choose a name and brose a folder on the server where unifile is installed and which is served as `http(s)://the-unifile-server.com/chosen-name/` - this is an experimental feature which still has to be fine tuned -* extend unifile: see instructions bellow to add a service - -Example - GET /api/v1.0/dropbox/exec/ls/path/to/folder/ list a directory of the loggedin user #Motivation @@ -27,143 +19,48 @@ So we have decided that Silex would edit the user's files on the user's Dropbox. We hope that other communities will benefit this way to use their cloud services before they install the web app locally. -#How to install - -With node installed ([download](http://nodejs.org/download)), install unifile in your project - - $ npm install unifile - -Then write a small node.js server like this and name it ```server.js``` - - // node modules - var unifile = require('unifile'); - var express = require('express'); - var bodyParser = require('body-parser'); - var cookieParser = require('cookie-parser'); - var session = require('express-session'); - var multipart = require('connect-multiparty'); - - // init express - var app = express(); - - // config - var options = unifile.defaultConfig; - - // parse data for file upload - app.use(options.apiRoot, multipart({limit: '100mb'})); - - // parse data for post and get requests - app.use(options.apiRoot, bodyParser.urlencoded({ - extended: true, - limit: '10mb' - })); - app.use(options.apiRoot, bodyParser.json({limit: '10mb'})); - app.use(options.apiRoot, cookieParser()); - - // session management - app.use(options.apiRoot, session({ - secret: options.sessionSecret, - resave: false, - saveUninitialized: false - })); - - // use unifile as a middleware - app.use(options.apiRoot, unifile.middleware(express, app, options)); - - // server 'loop' - app.listen(6805); // 6805 is the date of sexual revolution started in paris france 8-) - -Save this as ```server.js``` and start it with - - $ node server.js - -Then start making calls with wget or your browser. For example... - - http://localhost:6805/api/v1.0/services/list/ - -... will list the available services: - - [ - { - "name": "dropbox", - "display_name": "Dropbox", - "description": "Access files from your Dropbox.", - "isLoggedIn": true, - "isConnected": true, - "user": { - "display_name": "Alex Hoyau", - "quota_info": { - "available": 5234491392, - "used": 4528634951 - } - } - }, - { - "name": "ftp", - "display_name": "FTP", - "description": "Access files through FTP.", - "isLoggedIn": false, - "isConnected": false - "user": { - "display_name": "test", - } - }, - { - "name": "www", - "display_name": "Web server", - "description": "Access files on the server where unifile is running.", - "isLoggedIn": false, - "isConnected": false - "user": { - "display_name": "admin", - } - } - ] - -#API calls - -Let's take the example of the Dropbox service - -Connect to the service - -Basic login and such - - GET /api/v1.0/dropbox/connect/ returns an URL, which you will open and authorize unifile to access the service (this is an oauth2 authorization mechanism) - GET /api/v1.0/dropbox/login/ now your have access to the service - - GET /api/v1.0/dropbox/account/ Get your account info, with your display_name at least - GET /api/v1.0/dropbox/logout/ Log out from the service (connect and login will be required) - -Execute commands - - GET /api/v1.0/dropbox/exec/ls/path/to/folder/ list a directory - GET /api/v1.0/dropbox/exec/rm/path/to/folder-or-file/ remove a file or directory - GET /api/v1.0/dropbox/exec/mkdir/path/to/folder/ create a directory - GET /api/v1.0/dropbox/exec/cp/path/to/src/:/path/to/dst/ copy a file or directory - GET /api/v1.0/dropbox/exec/mv/path/to/src/:/path/to/dst/ move (rename) a file or directory - GET /api/v1.0/dropbox/exec/get/path/to/file.txt access a file - GET /api/v1.0/dropbox/exec/put/path/to/file.txt:{string} write data to a file - POST /api/v1.0/dropbox/exec/put/path/to/file.txt write data to a file + +#Use + +Requirements + +* [nodejs](http://nodejs.org/) > 6.0.0 + +#Use in your nodejs project + +##With express + +Add unifile lib to your project + +``` +$ npm install unifile --save +``` + +Then write a small node.js server [like this one](./samples/simple-api-server.js). Or play with the sample: + +``` +$ cd samples +$ npm install +$ node simple-api-server.js +``` + +Then open `http://localhost:6805/` and play with your cloud storages. + + #License -license: MIT +[license: MIT](./LICENSE) #Developer guide Here is how to contribute -##Add a service - -The services in unifile are cloud storage services, e.g. Dropbox and google drive. - -Each service is a Node.js class implementing a given set of functions, e.g. ls, rm, cp... +**FIXME** -If you wish to add a service, +##Add a service -* add your .js file in lib/services/ (duplicate the lib/services/dropbox.js file in order to have all the required methods) -* edit core/router.js to make your service reachable -* if you use an external node.js library, add the dependency in package.json +**FIXME** Here is a list of services which could be useful @@ -179,22 +76,3 @@ Here is a list of services which could be useful **Let's discuss [this list of issues which set the future of unifile](https://github.com/silexlabs/unifile/labels/enhancement)** -unifile archi, tests and readme - -## Notes - -* doc: https://www.dreamfactory.com/developers/live_API -* mock, doc et tests: http://apiblueprint.org/ -* https://npmjs.org/package/social-cms-backend -* tests http://stackoverflow.com/questions/11520170/unit-testing-oauth-js-with-mocha - -to do - -* app keys and sensitive info in env vars -* unit tests for get/put/cat -* pagination for ls commands? -* security: make the "allowCrossDomain" function look for the api key and det if the domain is allowed -* best practices for the api - http://www.startupcto.com/backend-tech/building-an-api-best-practices -* mimic unix commands : /v1.0/gdrive/exec/?cmd="cd /example1/test/ ; cp img1.jpg img2.jpg ; ls" -* add a new service