GithubHelp home page GithubHelp logo

silexlabs / cloudexplorer2 Goto Github PK

View Code? Open in Web Editor NEW
97.0 11.0 22.0 4.06 MB

Manage your users' cloud services from your application

Home Page: http://cloud-explorer.org/

JavaScript 89.88% SCSS 9.19% Dockerfile 0.93%
cloud cloud-storage dropbox-client dropbox-chooser github-client ftp-client ftp github dropbox webdav webdav-client file-upload file-manager file-picker storage cloud-service cloud-explorer react reactjs unifile

cloudexplorer2's Introduction

CloudExplorer2

Manage your users' cloud services from your application.

screenshot from 2017-10-04 11-09-53

There is a live demo here

Install

$ npm install --save cloud-explorer

Use

Here is an example on how to use Cloud Explorer's router to expose an API used by the front end to list files, read and write - see this file for a complete example

// before this create an express application

const CloudExplorer = require('cloud-explorer');

const router = new Router({
  dropbox: {
    clientId: '8lxz0i3aeztt0im',
    clientSecret: 'twhvu6ztqnefkh6',
    redirectUri: `${rootUrl}/ce/dropbox/oauth_callback`,
    state: 'abcd'
  },
  ftp: {redirectUri: `${rootUrl}/ce/ftp/signin`},
});

app.use('/ce', router);

There is also an example of use in Silex website builder here.

And here is an easy way to run a local ftp for tests: npx ftp-srv ftp://0.0.0.0:2121 --root .

Client side

For a complete example see the dist folder.

On the client side, the HTML:

<iframe id="ceIFrame" class="container" src="/ce/cloud-explorer/cloud-explorer.html" />

And the Javascript:

const ce = document.querySelector('#ceIFrame').contentWindow.ce;
ce.showThumbnails(true);
ce.openFile(['.jpg', '.jpeg', '.png', '.gif'])
.then(fileInfo => {
    if(fileInfo) alert('you chose:' + fileInfo.path);
    else alert('you canceled');
})
.catch(e => alert('an error occured: ' + e.message));

In order to know what are the possible options, please read the code

Server side config

When creating CE2 router, your app can pass it options, please see the example in lib/index.js. This is how you are supposed to enable or disable cloud services, or features.

Also you can add custom services and image banks, for this you can use the methods of the Router class: addService and addImageBank.

Notes:

  • if you enable only one service, CE2 will be in "single service" mode and the user will not be presented the list of services but directly enters the only service (if logged in).

API

You can use only CE2 API, it makes Dropbox, FTP, SFTP, Webdav protocols accessible over HTTPS

Method Path Params Description Example
GET /services List all installed services (Dropbox, FTP...) curl 'http://localhost:6805/ce/services' returns [{"isDir":true,"isService":true,"mime":"application/json","name":"github","isLoggedIn":false,"isOAuth":true,"displayName":"GitHub","icon":"../assets/github.png","description":"Edit files from your GitHub repository."},{"isDir":true,"isService":true,"mime":"application/json","name":"dropbox","isLoggedIn":false,"isOAuth":true,"displayName":"Dropbox","icon":"../assets/dropbox.png","description":"Edit files from your Dropbox."},{"isDir":true,"isService":true,"mime":"application/json","name":"ftp","isLoggedIn":false,"isOAuth":false,"displayName":"FTP","icon":"../assets/ftp.png","description":"Edit files on a web FTP server."},{"isDir":true,"isService":true,"mime":"application/json","name":"fs","isLoggedIn":true,"isOAuth":false,"username":"lexoyo","displayName":"Your Computer","icon":"","description":"Edit files on your local drive."}]
POST /:connector/authorize Connector name (dropbox, ftp, sftp, webdav...) Get the URL to redirecto the user to for oauth flow ``
POST /:connector/logout Connector name Logout ``
GET /\/(.*)\/ls\/(.*)/ Connector name, path List folder content curl 'http://localhost:6805/ce/ftp/ls/' -H 'UNIFILE_FTP_HOST: localhost' -H 'UNIFILE_FTP_TOKEN: demo' -H 'UNIFILE_FTP_PORT: 2121' -H 'UNIFILE_FTP_USER: demo' returns [{"size":0,"modified":"2001-03-01T12:30:00.000Z","name":"upload","isDir":true,"mime":"application/directory"},{"size":0,"modified":"2022-12-01T23:00:00.000Z","name":"download","isDir":true,"mime":"application/directory"}]
GET /\/(.*)\/get\/(.*)/ Connector name, path Get the content of a file `curl 'http://localhost:6805/ce/ftp/get/path/to/test.png' -H 'UNIFILE_FTP_HOST: localhost' -H 'UNIFILE_FTP_TOKEN: demo' -H 'UNIFILE_FTP_PORT: 2121' -H 'UNIFILE_FTP_USER: demo'
` returns the content of test.png
POST /\/(.*)\/upload\/(.*)/ Connector name, path Upload file(s) to the server curl 'http://localhost:6805/ce/ftp/upload/' -X POST -H 'UNIFILE_FTP_HOST: localhost' -H 'UNIFILE_FTP_PASSWORD: demo' -H 'UNIFILE_FTP_TOKEN: nothing' -H 'UNIFILE_FTP_PORT: 2121' -H 'UNIFILE_FTP_USER: demo' -H 'Content-Type: multipart/form-data; boundary=---------------------------2814941533969992343925519265' --data-binary $'-----------------------------2814941533969992343925519265\r\nContent-Disposition: form-data; name="content"; filename="croix.svg"\r\nContent-Type: image/svg+xml\r\n\r\n-----------------------------2814941533969992343925519265--\r\n'
DELETE /\/(.*)\/rm\// Connector name, files to delete Delete file(s) curl 'http://localhost:6805/ce/ftp/rm/' -X DELETE -H 'Content-Type: application/json' -H 'UNIFILE_FTP_HOST: localhost' -H 'UNIFILE_FTP_PASSWORD: demo' -H 'UNIFILE_FTP_TOKEN: nothing' -H 'UNIFILE_FTP_PORT: 2121' -H 'UNIFILE_FTP_USER: demo' --data-binary '[{"name":"unlink","path":"tmp/croix.svg"}]'
PUT mkdir
GET \/(.*)\/stat\/(.*)/
TODO
TODO
TODO
TODO
TODO
TODO
TODO

Cookies or headers

Authentication uses cookie session or can be set from headers. The headers starting with UNIFILE_ are recognized and expected to be UNIFILE_{connector}_{key}_{value}, e.g. curl 'http://localhost:6805/ce/ftp/ls/' -H 'UNIFILE_FTP_HOST: localhost' -H 'UNIFILE_FTP_TOKEN: demo' -H 'UNIFILE_FTP_PORT: 21' -H 'UNIFILE_FTP_USER: demo'

WARNING: you need to allow underscores (_) in headers if you are using nginx or apache servers

Dev setup

To contribute to Cloud Explorer, clone this repo and build:

$ git clone github:silexlabs/CloudExplorer2
$ cd CloudExplorer2
$ npm i
$ npm run build

This will compile the JS files from src/ with ReactJS and Babel. The generated files will go in dist/.

You can serve dist on http://localhost:6805 with

$ npm start

And then access the demo app on http://localhost:6805/ce/cloud-explorer/

Docs

Please feel free to ask in the issues, and contribute docs in the wiki.

For now, the best way to know the API is to take a look at the App class which exposes all CE methods here.

Env vars

CE is configured with environment variables:

Name Default Description
PORT 6805
SERVER_PATH '' Example: '/a-path'
SERVER_URL http://localhost:${port}${rootPath}
DROPBOX_APP_ID undefined
DROBOX_APP_SECRET undefined
DROPBOX_APP_REDIRECT undefined
GITHUB_APP_ID undefined
GITHUB_APP_SECRET undefined
GITHUB_APP_REDIRECT undefined
UNSPLASH_ACCESS_KEY undefined
UNSPLASH_APP_NAME undefined
UNSPLASH_OFFLINE_TEST_PATH undefined
ENABLE_HYPERDRIVE undefined "true" or anything else

cloudexplorer2's People

Contributors

clemos avatar jbips avatar jotakar avatar kraftman avatar lexoyo avatar singchan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloudexplorer2's Issues

Favorite or recent places

It would be very helpful to let the user mark some folders as favorite or to memorize the "recent places" i.e. the folders in which the user has opened files from recently

One or the other would add the folders to a menu so that the user can select them to "cd" into one of them directly

Feature request: image thumbnails

In order to display image thumbnails, I will create a different view specific to images

This mode will be used when the API is called like this:

ce.openFile(['.jpg', '.jpeg', '.png', '.gif'])
.then(fileInfo => {
    ...
})

This means these tasks

  • new "mode" for images, with thumbnails list
  • new design
  • resize images on the fly

If anyone has ideas (design or code) please comment :)
cc @clemos @ceubri @suddenheroes

FTP can crash the server

When I login with FTP on an unreachable server, it crashes the nodejs app

For example, on an instance which is online, host set as localhost
screenshot from 2018-03-21 18-47-06
Then
screenshot from 2018-03-21 18-50-27

save as: confirm overrite

When the user "save as" a file, he/she is asked a name, and when the chosen name is already in the file list, a "are you sure?" dialog should ask to confirm

Upload images

Since recently (I think)
When I try to upload an image, it contains errors
I tried with fs on chrome and with dropbox on firefox

Keyboard shortcut to select current folder

When the user has to select a folder: if there is no selection then enter should select the current folder (otherwise, if there is a selection it enters the selected folder as it already does it)

Save copy or save as

When I try to "save copy" or "save as", the selected file is not saved and I get the next error message:
App.jsx:95 Uncaught (in promise) Error: Invalid data. You must provide a String or a File at App.jsx:95 at Array.map (<anonymous>) at App.write (App.jsx:90) at ce.read.then (demo-page.js:82)

All permisions are right, and I can create folders and so, but I can't save.

Single service mode

In some cases we need to have only 1 service and skip the list of services. For example the downloadable/offline version of Silex needs only the FS service. Another use case is a hosting company willing to host files only on their servers.

So there are a few things to do

  • when the list of services is displayed, if there is only one service, open this service
  • when the user is trying to list a folder and he is not authenticated, display a popin with the links
    • log in => call the authenticate route and open a popup for oauth
    • register => open an external link
    • back to "/" => cd /
  • hide the service from the bread crumbs
  • optional idea: even if there is multiple services, allow the calling app to specify a "root path" and skip the services list, and sandbox the user to this folder, e.g. /github/myrepo/gh-pages/ or /ftp/htdocs/

Your Heroku example is now dead

When i clicked "local" and tried deleting some files. It's actually deleting the files that are used to run the example. So now it's dead xD

Do not re-auth when the user is already logged in

When I have already authorized access to a service, and I enter this service again, CE2 opens a popup for me to authorize again. This should not be the case

What I do

  • open CE2
  • double click on github
  • authorize access to my github
  • click the little "house" to go back to "/"
  • [optional] close CE2 window and come back later
  • double click on github again

What happens: a popup opens and goes to github, then github redirects to the callback page which closes the popup

What I expect: do not open a popup, enter github folder immediately

Also when the service is FS, the user is always logged in so we should not open a popup and close it when "/authorize" returns an empty URL

To do that, I am supposed to

  • use the code of this PR so that "/services" route will return a list of services with the "isLoggedIn" field
  • when CE2 is initialized, I need to always load "/services", not just when we have an initial route set to "/"
  • store the services in UnifileService class, do not cache it
  • when the user wants to access a service, check UnifileService::services and see if isLoggedIn is true, in which case it will not open a popup
  • when the user authorizes us to access a service, update UnifileService::services with isLoggedIn set to true
  • when the an access error occures, update UnifileService::services with isLoggedIn set to false

Warning message from React

At runtime I have this warning message:

"Warning: Accessing PropTypes via the main React package is deprecated, and will be removed in  React v16.0. Use the latest available v15.* prop-types package from npm instead. For info on usage, compatibility, migration and more, see https://fb.me/prop-types-docs"

screenshot from 2018-01-13 20-30-00

Filters

On the demo page, when I set filters, it still displays all the files
It used to work properly, do you have an idea of what could have changed @JbIPS ?

Enter key on rename cd to folder

When trying to rename a folder I hit Enter key and this cd into the folder, not renaming it. The behavior of Enter should be the same as when creating a folder.

Exposed credentials

I just received a message warning me of exposed credentials:

Hi Folks!
I just wanted to give you a heads up that my team detected some exposed credentials within the CloudExplorer source repository on GitHub. (I got your e-mail addresses from the npm ownership data for CloudExplorer.)
I don't know if the creds are still active or carry any risk, but wanted to let you know anyway. The creds are for Dropbox, GitHub, and Unsplash.
https://github.com/silexlabs/CloudExplorer2/blob/main/lib/index.js#L35C5-L48C95
https://github.com/silexlabs/CloudExplorer2/blob/main/README.md
https://github.com/silexlabs/CloudExplorer2/blob/main/lib/index.js#L63
Thanks!!
Mike

error page for ftp login

Right now when you try to login to ftp and give the wrong login or pass, the error is displayed as JSON
There should be a page to display auth errors for FTP
Then we should use this page also for SFTP and maybe other services too
CC @JbIPS

Multiple upload

When I upload more than 1 image at once, the images are corrupted
I tried

  • on firefox
  • 2 and 3 images
  • with the OS file explorer and with drop files in the browser
  • github and dropbox

Webdav

When I activate the webdav service on my Silex instance, webdav bug
Error: Unknown connector: webdav

Must be something in CE2 router... or unifile

Login form callback are wrong

Connectors that use a login form use an old URL callback (as in silexlabs/Silex#710). This should be updated.

While we're playing with those URL, we should create an POST endpoint to retrieve the form value without putting them in the URL, hence closing #35

Issue with breadcrumb

Maybe it's a personal opinion but I think when you click on a breadcrumb you should cd in this directory, not in its parent as it is today.

Fail downloading a zip file

I tried to download a ZIP file from my FTP (BTW, awesome to have an online FTP explorer!) by clicking on the download button, but it opened a new tab with some garbage data in it.

Why isn't it downloading normally?

FTP password is submitted in GET

When the user logs in to FTP or SFTP, the auth page sends the password in get to cloud explorer's router

We should avoid that and use POST data

Feature request: pagination for image banks

For now the image banks show a fixed number of results
It would be nice to load more photos when the user scrolls down

  • add a page number in the routes of image banks
  • make API call when the user scrolls and reach the bottom of the list (in thumbnail view only)

Feature request: display file info and preview

When a file (or even a folder?) is selected, it should be possible to display details about the file, such as weight, dates and type... And most important a preview.

Probably something like gdrive "file details":

screenshot from 2018-10-26 15-37-23

UI standards

Many clickable zone do not have a cursor: pointer; style

Probably many other UI/UX mistakes in CE2 (every time the user click, something should happen immediately...)

scroll with keyboard

When the user uses the keyboard arrows to move the selection, if the selection is on a file or folder which is not visible, the view should scroll so that the selection is visible.

Static methods errors

In the last commit there two changes that produces errors: static render in KeynavsBoard adn sttic getService in App.jsx. They are static but they are called as non static methods in React modules.

build fail on heroku

the build fails on heroku, it says

       > [email protected] build:sass /tmp/build_ebcfe0756f037b5b6357e660e375b000/lexoyo-CloudExplorer2-7046414
       > node-sass --include-path src/sass --include-path node_modules/font-awesome/scss src/sass/style.scss dist/style.css
       sh: 1: node-sass: not found   

Cannot install via npm

When installing the lib via npm, I get an error with the postinstall script:

cp: cannot stat 'node_modules/font-awesome/fonts/*': No such file or directory
cp: cannot stat 'node_modules/npm-font-open-sans/fonts/*': No such file or directory

Linter warnings

We should cleanup the code to remove linter warnings, i.e. do npm run lint and fix the warnings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.