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

vcloud-sdk-nodejs

v1.3.23

Published

vcloud nodejs sdk

Downloads

125

Readme

视频云对外 sdk 的 nodejs 版本。

vcloud-sdk-nodejs

封装了签名、发送请求等核心业务逻辑 ; 同时内置了 Vod和ImageX 标准 API

安装

//use npm
npm install vcloud-sdk-nodejs --save
//use yarn
yarn add vcloud-sdk-nodejs

基本使用方式:

const Client = require('vcloud-sdk-nodejs');

const clientOptions = {
  service: '<serviceName>',
  accesskey: '<accessKeyId>',
  secretkey: '<accessKeySecret>',
  version: '<apiVersion>'
  endpoint?: '<endpoint>', //默认是 https://open.bytedanceapi.com
}

const client = new Client(clientOptions);

const requestOptions = {
  method: string;  // set the http method, default is GET
  version: string; // api version; default is service apiVersion
  logId?: string; // requestId
  lockTime?: boolean; // aws签名时是否锁定时间戳, 默认是fase
  body?: any; //请求体,当method为get、options等无body的请求方法时设置无效
  query?: {  //url请求参数
    [key: string]: any;
  };
  headers?: {  //自定义请求头
    [key: string]: string;
  };
};

client.request(action, requestOptions);

添加拦截器

支持在 client 请求接口的前后添加拦截器, 继续以上文声明的 client 实例为例

//添加前置拦截器
client.addPreHandler({
  resolve: ({action, params}) => Promise({action, params}),
  reject: err => {}
});

//添加后置拦截器
client.addPostHandler({
  resolve: (response) => Promise(response),
  reject: err => {}
})

standard sdk

standard sdk 指的是和具体服务相关的 sdk,提供给用户更快捷的使用方式。以 Vod 服务的使用为例:

const VodClient = require('vcloud-sdk-nodejs/services/vod');

const client = new VodClient({
    accesskey: '<accessKeyId>',
    secretkey: '<accessKeySecret>',
  });

  const res = await client.GetPlayInfo();
}

API

SignUploadSts2([expire])

  • expire: 过期时间(ms), 可不传,默认1小时
const Client = require("vcloud-sdk-nodejs");

const client = new Client({
    accesskey: '<accessKeyId>',
    secretkey: '<accessKeySecret>',
});

client.SignUploadSts2();  //无参数,expire将使用默认值

client.SignUploadSts2(600 * 1000); //只传递expire时间

方法返回值是一个对象类型, 包含了 aws 签名所需信息, 如下所示:

{
  CurrentTime: '20191121T102857Z',
  ExpiredTime: '20191121T112857Z',
  SessionToken: 'xxx',
  AccessKeyId: 'xxx',
  SecretAccessKey: 'xxx'
}
  • CurrentTime: sessionToken 起始时间
  • ExpiredTime: sessionToken 的过期时间
  • SessionToken: aws v4 签名的 Session Token
  • AccessKeyId: aws v4 签名的 AccessKey
  • SecretAccessKey: aws v4 签名的 SecretKey