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

selfish-google-drive

v1.0.9

Published

Google drive api for that access your own account with function that named with linux command line

Downloads

12

Readme

selfish-google-drive


Google drive api wrapper that access your own account with function that named with linux command line

Installation

npm install selfish-google-drive --save

Usage

If you use the api for the first time, it will generate sgd-token.json (recommended to add it to .gitignore). Everytime you use the api, It will read the json file instead of call the api again to get the token, it will call the google api again if the sgd-token.json expired (expired in 3600s) or invalid.

The sgd-token.json should be like this

{
  "access_token": "somestring",
  "token_type": "Bearer",
  "expires_in": 3600
}

To init the package you should provide credential like below from google.

const credential = {
  clientID: 'somestring',
  clientSecret: 'somestring',
  refreshToken: 'somestring'
}

You can check how to generate the credential at How do I authorise an app (web or installed) without user intervention?

1. mkdir

Create folder at your google drive

return sgd.mkdir('HADOKE1N').then(console.log)

// { kind: 'drive#file',
//   id: '1rKARa_6zPZPPp4s5_ruOaxZLX6p3aIaE',
//   name: 'HADOKE1N',
//   mimeType: 'application/vnd.google-apps.folder' }
2. ls

Show list all files in drive or in a specific folder

return sgd.ls('1rKARa_6zPZPPp4s5_ruOaxZLX6p3aIaE').then(console.log)

// { kind: 'drive#fileList',
//   incompleteSearch: false,
//   files:
//    [ { kind: 'drive#file',
//        id: '1ipyXmH1DFQFSE1MPsBZ6J0O6KOGmYO-i',
//        name: 'abc.jpg',
//        mimeType: 'image/jpeg' },
//      { kind: 'drive#file',
//        id: '1bsyupFgTuUbepwA_DAN-9pypN0EEkN2q',
//        name: 'abc',
//        mimeType: 'application/vnd.google-apps.folder' } ]
3. find

Find and list by search query object (by name or mimetype)

const searchObject = {
  name: 'fakta',
  mimeType: 'image/jpeg',
}

return sgd.find(searchObject).then(console.log)

// { kind: 'drive#fileList',
//   incompleteSearch: false,
//   files:
//    [ { kind: 'drive#file',
//        id: '1ipyXmH1DFQFSE1MPsBZ6J0O6KOGmYO-i',
//        name: 'fakta.jpg',
//        mimeType: 'image/jpeg' } ] }
4. wget

Download file from google drive to given path

const dummyFile = {
  id: '0B68_w41xvLYFc3RhcnRlcl9maWxl',
  path: 'data/Getting started.pdf',
  mimeType: 'application/pdf'
}

return sgd.wget(dummyFile).then(console.log)

// data/Getting started.pdf
5. scp

Upload file to given folder to google drive

const dummyFilePath = '/home/eucliwood/repos/cermati/rajamoney/data/Masterfile-Redirections.xlsx'
const data = {
  name: 'Masterfile-Redirections',
  path: dummyFilePath,
  folder: ['1bsyupFgTuUbepwA_DAN-9pypN0EEkN2q', '1UbsbRlKP0tQkhZXHT2k2E05wa3j2t3WN'] // [Optional] Folder ids, or just leave it empty
}

return sgd.scp(data).then(console.log)

// const dummyFilePath = '/home/eucliwood/repos/creepy/creepy/data/images/5a99889d027fc292448e66f9.jpg'
// {
//   "kind": "drive#file",
//   "id": "1_rIXalPiqAVopyr8HiwcU_DzvmT68EY3",
//   "name": "Masterfile-Redirections.xlsx",
//   "mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
//  }

Open for suggesstion :)

License

MIT