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

oss-upload-tool

v0.9.0

Published

Integrated oss upload

Downloads

302

Readme

npm size test NPM downloads

oss-upload-tool

Integrated oss upload
Complete integration COS-OSS / ALI-OSS / S3-OSS, Welcome to improve together.

Install

Using npm:

npm install oss-upload-tool --save-dev

Using yarn:

yarn add oss-upload-tool -D

Usage

The tool will prioritize the identification of environment variables for easy invocation.
Before use, please register environment variables in advance to facilitate use. In CI/Action, you can set environment variables to prevent exposure of OSS parameters.

# General parameters
npm config --global set oss_upload_tool_secret_id "your secret_id"
npm config --global get oss_upload_tool_secret_key "your secret_key"
npm config --global get oss_upload_tool_bucket "your bucket"
npm config --global get oss_upload_tool_region "your region"

There are the following environment variables.
It is recommended to set the environment variable corresponding to oss first, then you do not need to specify the type of oss service provider.

# General parameters
npm config get oss_upload_tool_secret_id
npm config get oss_upload_tool_secret_key
npm config get oss_upload_tool_bucket
npm config get oss_upload_tool_region
# cos-oss
npm config get oss_upload_tool_cos_secret_id
npm config get oss_upload_tool_cos_secret_key
npm config get oss_upload_tool_cos_bucket
npm config get oss_upload_tool_cos_region
# ali-oss
npm config get oss_upload_tool_alioss_secret_id
npm config get oss_upload_tool_alioss_secret_key
npm config get oss_upload_tool_alioss_bucket
npm config get oss_upload_tool_alioss_region
npm config get oss_upload_tool_alioss_endpoint
# s3-oss
npm config get oss_upload_tool_s3_secret_id
npm config get oss_upload_tool_s3_secret_key
npm config get oss_upload_tool_s3_bucket
npm config get oss_upload_tool_s3_region

Get parameter priority parameters > process.env.[key] > npm config get [key].

Usage in CLI

oss-upload-tool -t "./lib/**" -d "./__xxx","__xxx1/" --bucket "***" --region "***" --oss "S3"

Usage in Node

const ossUpload = require('oss-upload-tool');

// upload cos-oss
await ossUpload({
  targets: {
    src: './lib/**/*',
    dest: ['__xxx/', '__xxx1/'],
  },
  uploadParams: {
    Bucket: '***',
    Region: '***',
  },
  COSOptions: {
    SecretId: '***',
    SecretKey: '***',
  },
});

// upload ali-oss
await ossUpload({
  targets: {
    src: './lib/**/*',
    dest: ['__xxx/', '__xxx1/'],
  },
  ALIOptions: {
    accessKeyId: '***',
    accessKeySecret: '***',
    bucket: '***',
    region: '***',
    endpoint: '***',
  },
});

// upload s3-oss
ossUpload({
  targets: {
    src: './lib/**/*',
    dest: ['__xxx/', '__xxx1/'],
  },
  uploadParams: {
    Bucket: '***',
  },
  S3Options: {
    credentials: {
      accessKeyId: '***',
      secretAccessKey: '***',
    },
    region: '***',
  },
})

Options

targets

Upload configuration

  • Type: array | object
    • src: string | string[] globby patterns.
    • dest: string | string[] Upload path, If it is an array, it will upload to multiple directories.
    • flatten: bool Delete the directory structure of uploaded files.
    • rename: string | (path: string, ext: string) => string Uploaded file name.
    • transform: (Buffer) => Buffer | string Upload file content.

type

  • Type: COS | ALI | S3 default COS

uploadParams

  • COS import('cos-nodejs-sdk-v5').SliceUploadFileParams
  • ALI import('ali-oss').PutObjectOptions
  • S3 import('aws-sdk').S3.Types.PutObjectRequest

COSOptions

  • Type: object https://github.com/tencentyun/cos-nodejs-sdk-v5

ALIOptions

  • Type: object https://github.com/ali-sdk/ali-oss#node-usage

S3Options

  • Type: object https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html

parallelLimit

  • Type: number default 5
    Number of parallel uploads.

origin

  • Type: string
    The current CDN externally accesses the domain name, which needs to have an agreement.

existCheck check, if the default cdn domain name cannot be accessed, use the open access cdn domain name to check

timeout

  • Type: number default 1000 * 60 * 30
    Single file upload timeout

existCheck

  • Type: boolean | patterns default false
    Specify the file. If the file exists, skip the upload. The judgment is to use etag first. If there is no etag, as long as the request returns 200, it will be skipped.
    By default, the official domain name of oss is used to access. If it cannot be accessed, please specify origin to set a custom domain name.

maxAttempts

  • Type: number default 0
    Maximum number of failed retries.

cwd

  • Type: string default process.cwd()