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

qiniu-tool

v2.1.1

Published

Qiniu Resource Storage SDK for Node.js (七牛云上传工具 Node.js)

Downloads

38

Readme

安装

npm install qiniu-tool
yarn add qiniu-tool

测试

npm run test

使用方法(仅限V2.0.0版本)

const {fetch, refresh, upload} = require('qiniu-tool')
/**
 * 上传资源
 * 第一参数: 七牛配置参数
 * 第二参数: file path/buffer/base64
 * 第三参数: 上传后的CDN路径
 */
const result01 = await upload({
  ak: '',
  sk: '',
  scope: '',
  zone: '', // 七牛空间(默认Zone_z1)
}, '/Users/kyle/zhuangkai/qiniu-tool/test.png', 'test/2020-10-12/demo.png')
// 刷新资源
const result02 = await refresh({
  ak: '',
  sk: ''
}, [
  'https://static.domain.com/demo01.png',
  'https://static.domain.com/demo01.png'
])
// 拉取网络资源
const result03 = await fetch({
  ak: '',
  sk: '',
  scope: '',
}, 'https://img2.domain.com/3ae0df90_400.png', 'test/tsUpload/aa2.png')

使用方法(仅限V1.*版本,1.*所有版本将于2022/01/01起全部停止维护)

上传资源(上传文件夹)

let qiniuTool = require('qiniu-tool')
qiniuTool.config({
  ak: '', // 七牛AccessKey
  sk: '', // 七牛SecretKey
  scope: 'myscope', // 七牛存储空间名称
  /**
   * 机房    Zone对象
   * 华东    qiniu.zone.Zone_z0
   * 华北    qiniu.zone.Zone_z1
   * 华南    qiniu.zone.Zone_z2
   * 北美    qiniu.zone.Zone_na0
   */
  zone: 'Zone_z1', // 七牛空间(默认Zone_z1)
  type: '.css|.js', // 允许上传的文件类型(详情请查看下文文档)
  pathCDN: 'test/', // 上传到CDN的路径
  pathLocal: '/Users/kyle/filesDir/', // 源文件夹路径(相对路径和绝对路径都行)
  random: false, // 是否产生随机数
  randomNumber: '66666', //随机数,默认自动生成,有randomNumber则不自动生成random
})
qiniuTool.upload()

上传资源(上传单个文件 v1.1.0新增)

let qiniuTool = require('qiniu-tool')
qiniuTool.config({
  ak: '', // 七牛AccessKey
  sk: '', // 七牛SecretKey
  scope: 'myscope', // 七牛存储空间名称
  /**
   * 机房    Zone对象
   * 华东    qiniu.zone.Zone_z0
   * 华北    qiniu.zone.Zone_z1
   * 华南    qiniu.zone.Zone_z2
   * 北美    qiniu.zone.Zone_na0
   */
  zone: 'Zone_z1', // 七牛空间(默认Zone_z1)
  pathCDN: 'test/', // 上传到CDN的路径
  pathLocal: '/Users/kyle/filesDir/demo.js', // 源文件路径(相对路径和绝对路径都行)
  onlyPath: 'demo/dd.js'
})
qiniuTool.uploadOnly() // /Users/kyle/filesDir/demo.js => [CDN Path]/test/demo/dd.js

刷新资源

let qiniuTool = require('qiniu-tool')
qiniuTool.config({
  ak: '', // 七牛AccessKey
  sk: '', // 七牛SecretKey
})
qiniuTool.refresh([
  'https://static.webascii.cn/test/0011220033/dir/dir2/f05.css',
  'https://static.webascii.cn/test/0011220033/dir/dir2/f06.css',
])

拉取网络资源(v1.2.0新增)

let qiniuTool = require('qiniu-tool')
qiniuTool.config({
  ak: '', // 七牛AccessKey
  sk: '', // 七牛SecretKey
  scope: '', // 七牛存储空间名称
  /**
   * 机房    Zone对象
   * 华东    qiniu.zone.Zone_z0
   * 华北    qiniu.zone.Zone_z1
   * 华南    qiniu.zone.Zone_z2
   * 北美    qiniu.zone.Zone_na0
   */
  zone: 'Zone_z1', // 七牛空间(默认Zone_z1)
  pathCDN: 'test/demo/' //上传文件路径(开头请不要添加/)
})

async function demo() {
  let obj = await qiniuTool.fetch('http://devtools.qiniu.com/qiniu.png', 'kyle/qiniu.png')
  console.log(obj)
}

demo()
// log输出
// { fsize: 163469,
//   hash: 'FpHyF0kkil3sp-SaXXX8TBJY3jDh',
//   key: 'test/demo/kyle/qiniu.png',
//   mimeType: 'image/png',
//   originUrl: 'http://devtools.qiniu.com/qiniu.png' }

版本 v1.1.* 参数详解

ak {String}

必填
七牛SecretKey,请自行查询

sk {String}

必填
七牛云AccessKey,请自行查询

scope {String}

必填
七牛存储空间名称
请自行查询

zone {String}

非必填(默认:Zone_z1)
/**
* 机房	Zone对象
* 华东	qiniu.zone.Zone_z0
* 华北	qiniu.zone.Zone_z1
* 华南	qiniu.zone.Zone_z2
* 北美	qiniu.zone.Zone_na0
**/

type {String}

非必填
允许上传的文件类型
默认:.jpg|.js|.css|.png|.jpeg|.gif|.ico|.svg|.woff|.ttf|.eot
有type则覆盖默认值

pathCDN {String}

非必填(不可'/'开头)
上传到CDN的路径
若比填写则上传至CDN根目录,例如上传了文件‘demo.js’,上传后的路径是:http://cdn.xxx.com/demo.js
若填写http://cdn.xxx.com/[pathCDN]/demo.js

onlyPath {String}

单文件上传(uploadOnly)-必填
当前当前环境根路径(填写的此路径会将pathLocal的此部分路径删除)
例如:
pathLocal: '/Users/kyle/filesDir/demo.js', // 上传到CDN的路径
pathCDN: 'test/', // 上传到CDN的路径
onlyPath: 'demo/dd.js',
上传后得到:[CDN Path]/test/demo/dd.js

pathLocal {String}

必填
qiniuTool.upload():需要上传到CDN的文件夹
qiniuTool.uploadOnly():需要上传到CDN的文件
例如:/Users/kyle/filesDir/

random {Boolean}

非必填
是否自动生成时间戳
若没有randomNumber字段 且 random = true
true: http://cdn.xxx.com/[pathCDN]/[random]/demo.js
否则
true: http://cdn.xxx.com/[pathCDN]/[randomNumber]/demo.js

randomNumber {String}

非必填
是否自动生成时间戳
若没有randomNumber字段 且 random = true
true: http://cdn.xxx.com/[pathCDN]/[random]/demo.js
否则
true: http://cdn.xxx.com/[pathCDN]/[randomNumber]/demo.js

版本 v1.0.* 参数详解

ak {String}

必填
七牛SecretKey,请自行查询

sk {String}

必填
七牛云AccessKey,请自行查询

scope {String}

必填
七牛存储空间名称
请自行查询

zone {String}

非必填(默认:Zone_z1)
/**
* 机房	Zone对象
* 华东	qiniu.zone.Zone_z0
* 华北	qiniu.zone.Zone_z1
* 华南	qiniu.zone.Zone_z2
* 北美	qiniu.zone.Zone_na0
**/

type {String}

非必填
允许上传的文件类型
默认:.jpg|.js|.css|.png|.jpeg|.gif|.ico|.svg|.woff|.ttf|.eot
有type则覆盖默认值

pathCDN {String}

非必填(不可'/'开头)
上传到CDN的路径
若比填写则上传至CDN根目录,例如上传了文件‘demo.js’,上传后的路径是:http://cdn.xxx.com/demo.js
若填写http://cdn.xxx.com/[pathCDN]/demo.js

pathLocal {String}

必填
需要上传到CDN的文件夹
例如:/Users/kyle/filesDir/

random {Boolean}

非必填
是否自动生成时间戳
若没有randomNumber字段 且 random = true
true: http://cdn.xxx.com/[pathCDN]/[random]/demo.js
否则
true: http://cdn.xxx.com/[pathCDN]/[randomNumber]/demo.js

randomNumber {String}

非必填
是否自动生成时间戳
若没有randomNumber字段 且 random = true
true: http://cdn.xxx.com/[pathCDN]/[random]/demo.js
否则
true: http://cdn.xxx.com/[pathCDN]/[randomNumber]/demo.js