npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jaybirdgroup/jb-file-storage

v1.1.3

Published

A storage interface to work with local file storage, s3, youtube and vimeo

Downloads

82

Readme

Storage

A file storage interface to work with Local File Storage and S3.

Additionally, video files can bу uploaded to the Youtube or Vimeo

Usage

Install package.

$ npm i jb-file-storage --save

Work with Local storage.

const Storage = require('jb-file-storage');
const Fs = require('fs');

const LocalStorage = new Storage('local', {
    basePath: './public/uploads/',
    baseUrl: 'http://localhost:8080/public/uploads/'
});

// Path to file
let input = '/path/to/source/file.txt';
// OR read stream
input = Fs.createReadStream(input);

LocalStorage.saveFile(input, 'path/to/dest/file.txt', 'text/plain', (err, result) => {

    if (err) {
        return console.log(err);
    }

    console.log(result);

    // Example result
    // {
    //     url: 'http://localhost:8080/public/uploads/path/to/dest/file.txt',
    //     path: 'path/to/dest/file.txt'
    // }
});

// Note: the same arguments and response parameters for method LocalStorage.saveFileOnce().

// Note: basePath will be prepended to the file path
LocalStorage.deleteFile('path/to/file.txt', (err) => {

    if (err) {
        return console.log(err);
    }

    console.log('success!')
});

// Note: Work only for S3 and Local storage
// Note: basePath will be prepended to the folder path
LocalStorage.deleteDir('path/to/folder', (err) => {

    if (err) {
        return console.log(err);
    }

    console.log('success!')
});

S3

You need to create S3 Bucket and get Access Key and Secret Access Key. See Managing Access Keys for Your AWS Account guide.

const Storage = require('jb-file-storage');

const S3Storage = new Storage('s3', {
    basePath: 'project/uploads/',
    baseUrl: 'https://{bucket}.s3.amazonaws.com/project/uploads/',
    s3config: {
        accessKeyId: '{access-key}',
        secretAccessKey: '{secret-access-key}',
        params: {
            Bucket: '{bucket}',
            ACL: 'public-read'
        }
    }
});

// use the same api for all storages

// Also for youtube available different behaviour for saveFileOnce(). 
// Method prevent re-uploading in case of file existence 

Youtube

Read Obtaining authorization credentials to get Client Id and App Secret.

To make Youtube upload work, we need to authorize API requests with oAuth Token.

Add your domain URI to the Authorized JavaScript origins. For example: http://localhost:8080.

Add callback URI http://localhost:8080/api/settings/youtubeoauth/callback to the Authorized redirect URIs.

TODO: Add description on how to retrieve Youtube Access Token and routes configuration

const Storage = require('jb-file-storage');

const YoutubeStorage = new Storage('youtube', {
    baseUrl: 'https://www.youtube.com',
    type: 'oauth',
    auth: {
        accessToken: '{oauth-access-token}'
    },
    apiConfig: {
        clientId: '{client-id}',
        appSecret: '{app-secret}'
    }
});

// use the same api for all storages

Vimeo

Read Getting Started guide to get API Config values.

const Storage = require('jb-file-storage');

const VimeoStorage = new Storage('vimeo', {
    baseUrl: 'https://player.vimeo.com/video/',
    apiConfig: {
        clientId: '{client-id}',
        appSecret: '{app-secret}',
        accessToken: '{access-token}'
    }
});

// use the same api for all storages