Giter VIP home page Giter VIP logo

moleculer-flydrive's Introduction

Moleculer logo

moleculer-flydrive

Fluent storage manager service with Node Flydrive.
You need to install @slynova/node-flydrive

Features

  • Local
  • Amazon S3 (You need to install aws-sdk package to be able to use this driver)
  • Digital Ocean Spaces (You need to install aws-sdk package to be able to use this driver)
  • FTP (You need to install jsftp package to be able to use this driver)
  • Possibility to register a custome driver like Google Drive driver

Instalation

npm install moleculer-flydrive

Usage

With no settings (it will mount local storage driver by default with the current directory as root dir)

"use strict"
const FlyDrive = require("moleculer-flydrive");
const { ServiceBroker } = require("moleculer");
const broker = new ServiceBroker();
broker.createService(FlyDrive(),{
  actions: {
    async someAction(ctx){
      //let result = await this.storage.disk().exists("some-file.txt");
      //let result = await this.storage.disk("local").exists("some-file.txt");
      let result = await this.storage.exists("some-file.txt");//will use the default storage defined
      if(result){
        await this.storage.delete("some-file.txt");
      }
    }
  }
})

With settings

"use strict"
const FlyDrive = require("moleculer-flydrive");
const { ServiceBroker } = require("moleculer");
const broker = new ServiceBroker();
//when true passed as param the service will try to create the root dir
broker.createService(FlyDrive(true),{
  settings:{
    STORAGE_ROOT:"<a path>",
    storageConfig:{
      default: "local",
      disks:{
        local: {
          driver: "local"
        },
        s3: {
          driver: 's3',
          key: 'AWS_S3_KEY',
          secret: 'AWS_S3_SECRET',
          region: 'AWS_S3_REGION',
          bucket: 'AWS_S3_BUCKET'
        },
        ftp: {
          driver: 'ftp',
          host: 'FTP_HOST',
          port: 21,
          user: 'FTP_USER',
          pass: 'FTP_PASS',
          longLive: false
        },
      }
    }
  },
  actions: {
    async someAction(ctx){
      //let result = await this.storage.disk().exists("some-file.txt");
      //let result = await this.storage.disk("s3").exists("some-file.txt");
      let result = await this.storage.exists("some-file.txt");//will use the default storage defined
      if(result){
        await this.storage.delete("some-file.txt");
      }
    }
  }
})

Register a custom drive

"use strict"
const FlyDrive = require("moleculer-flydrive");
const GoogleDrive = require("flydrive-google-drive");
const { ServiceBroker } = require("moleculer");
const broker = new ServiceBroker();
//when true passed as param the service will try to create the root dir
broker.createService(FlyDrive(true),{
  settings:{
    STORAGE_ROOT:"<a path>",
    defaultStorage: "local",
    storageConfig:{
      disks:{
        local: {
          driver: "local"
        },
        s3: {
          driver: 's3',
          key: 'AWS_S3_KEY',
          secret: 'AWS_S3_SECRET',
          region: 'AWS_S3_REGION',
          bucket: 'AWS_S3_BUCKET'
        },
        ftp: {
          driver: 'ftp',
          host: 'FTP_HOST',
          port: 21,
          user: 'FTP_USER',
          pass: 'FTP_PASS',
          longLive: false
        },
        //register the driver configuration
        drive: {
          driver: "drive",
          clientId: "GOOGLE_DRIVE_CLIENT_ID",
          clientSecret: "GOOGLE_DRIVE_CLIENT_SECRET",
          redirectUrl: "GOOGLE_DRIVE_REDIRECT_URL",
          access_token: "GOOGLE_DRIVE_ACCESS_TOKEN",
          refresh_token: "GOOGLE_DRIVE_REFRESH_TOKEN"
        }
      },
      //register the driver hanlder
      customDrivers: {
        drive: GoogleDrive
      }
    }
  }
})

Settings

Property Type Description
STORAGE_ROOT String The root directory for local storage driver
defaultStorage String the default driver to use, if not sepecified, local will be used
storageConfig Object the configuration object, refer to Configuration object for more details

Methods

Name Params Result Description
disk String or undefined Storage instance get a specifique disk storage or the default storage if no param passes.
extends name:String,driver: Object constructor the StorageManager instance extends the storage manager, the new driver configuration should have been defined in configuration. Refer to How to register custome driver

Test

You can run npm run test to run tests

Licence

MIT

moleculer-flydrive's People

Contributors

molobala avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

guncloud

moleculer-flydrive's Issues

UnhandledPromiseRejectionWarning: TypeError: StorageManager is not a constructor

Hi,
When I use it with moleculerjs 0.14. I get an error like this
(node:18341) UnhandledPromiseRejectionWarning: TypeError: StorageManager is not a constructor at Service.created (/var/www/html/dev/moleculerjs/node_modules/moleculer-flydrive/src/index.js:97:22) at Service._init (/var/www/html/dev/moleculerjs/node_modules/moleculer/src/service.js:219:24) at Service.parseServiceSchema (/var/www/html/dev/moleculerjs/node_modules/moleculer/src/service.js:194:8) at new Service (/var/www/html/dev/moleculerjs/node_modules/moleculer/src/service.js:63:9) at ServiceBroker.createService (/var/www/html/dev/moleculerjs/node_modules/moleculer/src/service-broker.js:805:14) at Object.<anonymous> (/var/www/html/dev/moleculerjs/index.js:66:13) at Module._compile (internal/modules/cjs/loader.js:1138:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14) (node:18341) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:18341) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Cannot read property 'put' of undefined

Hello all.
I want to use moleculer-flydrive in my project. My code:

const {
    ServiceBroker
} = require("moleculer");
const broker = new ServiceBroker();
const FlyDrive = require("moleculer-flydrive");


module.exports = function () {      
    return {
        name: "flydrive",
        schema: {
            FlyDrive(){
                FlyDrive(true);
            }
        },
        actions: {
            /**
             * Say a 'Hello'
             *
             * @returns
             */
            hello() {
                return "Hello Flydrive Service";
            },
            exists: {
                async handler(ctx) {
                    //let result = await this.storage.disk().exists(ctx.params.filename);
                    //let result = await this.storage.disk("local").exists(ctx.params.filename);
                    // console.log(service.storage);
                    return await this.storage.exists(ctx.params.filename); //will use the default storage defined
                }
            },
            create: {
                async handler(ctx) {
                    return await this.storage.put(ctx.params.filename, ctx.params.fileContent);
                }
            }
        },
}

But when I call create action, it return error "Cannot read property 'put' of undefined"
Any one help me?

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.