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

tmc-egg-oss

v1.0.0

Published

OSS plugin for egg

Downloads

4

Readme

egg-oss

NPM version build status Test coverage David deps Known Vulnerabilities npm download

OSS plugin for egg

Install

$ npm i egg-oss

Configration

To enable oss plugin, you should change ${baseDir}/config/plugin.js

// config/plugin.js
exports.oss = {
  enable: true,
  package: 'egg-oss',
};

Then fill in nessary information like OSS's bucket, accessKeyId, accessKeySecret in ${baseDir}/config/config.{env}.js

Mention, egg-oss support normal oss client and oss cluster client, based on ali-oss:

// normal oss bucket
exports.oss = {
  client: {
    accessKeyId: 'your access key',
    accessKeySecret: 'your access secret',
    bucket: 'your bucket name',
    endpoint: 'oss-cn-hongkong.aliyun.com',
    timeout: '60s',
  },
};

// cluster oss bucket
// need to config all bucket information under cluster
exports.oss = {
  client: {
    cluster: [{
      endpoint: 'host1',
      accessKeyId: 'id1',
      accessKeySecret: 'secret1',
    }, {
      endpoint: 'host2',
      accessKeyId: 'id2',
      accessKeySecret: 'secret2',
    }],
    schedule: 'masterSlave', //default is `roundRobin`
    timeout: '60s',
  },
};

Init in egg agent, default is false:

exports.oss = {
  useAgent: true,
};

Usage

You can aquire oss instance on app or ctx.

const path = require('path');

// upload a file in controller
module.exports = function*() {
  const parts = this.multipart();
  let object;
  let part;
  part = yield parts;
  while (part) {
    if (part.length) {
      // arrays are busboy fields
      console.log('field: ' + part[0]);
      console.log('value: ' + part[1]);
      console.log('valueTruncated: ' + part[2]);
      console.log('fieldnameTruncated: ' + part[3]);
    } else {
      // otherwise, it's a stream
      console.log('field: ' + part.fieldname);
      console.log('filename: ' + part.filename);
      console.log('encoding: ' + part.encoding);
      console.log('mime: ' + part.mime);
      // file handle
      object = yield this.oss.put('egg-oss-demo-' + part.filename, part);
    }
    part = yield parts;
  }
  console.log('and we are done parsing the form!');
  if (object) {
    console.log('get oss object: %j', object);
    this.unsafeRedirect(object.url);
  } else {
    this.body = 'please select a file to upload!';
  }
}

To learn OSS client API, please check oss document

Create one more OSS buckets

Some application need to access more than one oss bucket, then you need to configure oss.clients, and you can create new oss instance dynamicly by app.oss.createInstance(config).

  • ${appdir}/config/config.default.js
exports.oss = {
  clients: {
    bucket1: {
      bucket: 'bucket1',
    },
    bucket2: {
      bucket: 'bucket2',
    },
  },
  // shared by client, clients and createInstance
  default: {
    endpoint: '',
    accessKeyId: '',
    accessKeySecret: '',
  },
};

exports.bucket3 = {
  bucket: 'bucket3',
};
  • ${appdir}/config/plugin.js
exports.oss = true;
  • ${appdir}/app.js
module.exports = function (app) {
  const bucket1 = app.oss.get('bucket1');
  const bucket2 = app.oss.get('bucket2');
  // it will merge app.config.bucket3 and app.config.oss.default
  const bucket3 = app.oss.createInstance(app.config.bucket3);
}

Questions & Suggestions

Please open an issue here.

secure keys

ping @fengmk2 to give you the access key!

License

MIT