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

lyman-egg-full-qiniu

v1.0.5

Published

封装七牛云SDK,方便在egg中使用,包含文件上传,资源管理,CDN推送

Downloads

8

Readme

egg-full-qiniu

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

依赖

[email protected]

安装

$ npm i egg-full-qiniu --save

使用

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

配置

// {app_root}/config/config.default.js
exports.fullQiniu = {
  default: {
    ak: '', // Access Key
    sk: '', // Secret Key
    useCdnDomain: true,
    isLog: true,
  },
  app: true,
  agent: false,

  // 单实例
  // 通过 app.fullQiniu 直接使用实例
  // client: {
  //     zone: '', // Zone_z0 华东, Zone_z1 华北, Zone_z2 华南, Zone_na0 北美
  //     bucket: '',
  //     baseUrl: null, // 用于拼接已上传文件的完整地址
  // }

  // 多实例
  // clients: {
  //     // 可以通过 app.fullQiniu.get('myImage'), app.fullQiniu.get('myText') 获取实例
  //     myImage: {
  //         zone: '', // Zone_z0 华东, Zone_z1 华北, Zone_z2 华南, Zone_na0 北美
  //         bucket: '',
  //     baseUrl: null, // 用于拼接已上传文件的完整地址
  //     },
  //     myText: {
  //         zone: '', // Zone_z0 华东, Zone_z1 华北, Zone_z2 华南, Zone_na0 北美
  //         bucket: '',
  //     baseUrl: null, // 用于拼接已上传文件的完整地址
  //     },
  // },
};

请到 config/config.default.js 查看详细配置项说明。

使用

  • 通过app.fullQiniu调用函数,在配置文件中已经固定bucket

  • 在多实例中进行movecopy时,可以通过getBucket()获取本实例的bucket

  • 单实例中:

    app.fullQiniu.uploadFile(key, file);
  • 多实例中

    const image = app.fullQiniu.get('myImage');
    const imageBak = app.fullQiniu.get('myImageBak');
    
    const result = image.copy('p1.png', imageBak.getBucket(), 'p1_bak.png', true);

API

  • uploadFile(key, file)

    上传本地文件到空间中
    
    @param key: 目标文件名
    @param file: 本地文件路径
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "url": 可访问的完整链接
        "hash"
        "key"
      }
  • uploadBytes(key, bytes)

    将内存中的字节数组上传到空间中
    
    @param key: 目标文件名
    @param bytes: 内存中的字节数组
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "url": 可访问的完整链接
        "hash"
        "key"
      }
  • uploadStream(key, stream)

    将客户端传送来的流上传到空间中
    
    @param key: 目标文件名
    @param stream: 文件流
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "url": 可访问的完整链接
        "hash"
        "key"
      }
  • fileInfo(key)

    获取文件信息
    
    @param key: 在空间中的文件名
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "fsize": 198568,
        "hash": "FhfDDtTkyR02fXq87bdlvJd-2HlH",
        "md5": "no0Hr/mBDGU/sMHNbuf05w==",
        "mimeType": "image/jpeg",
        "putTime": 15435661202597688,
        "type": 0, // 0 普通存储, 1 低频存储
      }
  • changeType(key, newType)

    修改文件存储类型
    
    @param key: 在空间中的文件名
    @param newType: 0 普通存储, 1 低频存储
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
      }
  • move(srcKey, destBucket, destKey, isForce = false)

    移动或者重命名文件
    
    @param srcKey: 在源空间中的文件名
    @param destBucket: 目标空间
    @param destKey: 在目标空间中的文件名
    @param isForce: true, 强制覆盖已有同名文件
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
      }
  • copy(srcKey, destBucket, destKey, isForce = false)

    复制文件
    
    @param srcKey: 在源空间中的文件名
    @param destBucket: 目标空间
    @param destKey: 在目标空间中的文件名
    @param isForce: true, 强制覆盖已有同名文件
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
      }
  • delete(key)

    删除文件
    
    @param key: 在空间中的文件名
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
      }
  • deleteAfterDays(key, days)

    设置或更新文件的生存时间
    
    @param key: 在空间中的文件名
    @param days: 有效期天数
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
      }
  • listPrefix({ prefix, marker, limit, delimiter })

    获取指定前缀的文件列表
    
    @param
      {
        prefix: 列举的文件前缀,比如 images-
        marker: 上一次列举返回的位置标记,作为本次列举的起点信息
        limit: 每次返回的最大列举文件数量
        delimiter: 指定目录分隔符
      }
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "marker": "eyJxxxx==",
        "items": [{
          "key": "image-xxxx1.jpg",
          "hash": "FhfDDtTkyR02fXq87bdlvJd-xxxx",
          "fsize": 198568,
          "mimeType": "image/jpeg",
          "putTime": 15435714374444728,
          "type": 0,
          "status": 0
        }, {
          "key": "image-xxxx2.jpeg",
          "hash": "Frk2EdYeI1i-beHzLSMA_xxx",
          "fsize": 5467,
          "mimeType": "image/jpeg",
          "putTime": 15435714197909564,
          "type": 0,
          "status": 0
        }]
      }
      备注: prefix='image-', limit=2
  • fetch(url, key)

    抓取网络资源存放到到空间
    
    @param url: 资源链接
    @param key: 存放到空间时的文件名称
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "fsize": 22827,
        "hash": "Fu4uwAc4LCdmVMzgLKs5EdKLCJMT",
        "key": "fetch_xxx.jpg",
        "mimeType": "image/jpeg"
      }
  • batchFileInfo(url, key)

    批量获取文件信息
    数量不可以超过1000个,如果总数量超过1000,需要分批发送
    
    @param files: 文件名集合, ['', '', ...]
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "list": [{
          "code": 200,
          "data": {
            "fsize": 22827,
            "hash": "Fu4uwAc4LCdmVMzgLKs5EdKLCJMT",
            "md5": "ahWerXWV0Co3Yqujwi4pEw==",
            "mimeType": "image/jpeg",
            "putTime": 15435720064197850,
            "type": 0
          }
        }, {
          "code": 200,
          "data": {
            "fsize": 198568,
            "hash": "FhfDDtTkyR02fXq87bdlvJd-2HlH",
            "md5": "no0Hr/mBDGU/sMHNbuf05w==",
            "mimeType": "image/jpeg",
            "putTime": 15435714374444728,
            "type": 0
          }
        }]
      }
  • batchDelete(files)

    批量删除文件
    数量不可以超过1000个,如果总数量超过1000,需要分批发送
    
    @param files: 文件名集合, ['', '', ...]
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "list": [{
          "code": 200
        }, {
          "code": 200
        }]
      }
  • refreshUrls(urls)

    CDN 文件刷新
    单次请求链接不可以超过100个,如果超过,请分批发送请求
    
    @param urls: 完整链接的集合, ['', '', ...]
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "code": 200,
        "error": "success",
        "requestId": "5c0110fe43d7231d08abe16c",
        "taskIds": {
          "http://imagecdn.xxxx.cn/image-xxx1.jpeg": "5c0110fe43d7231d08xxxx",
          "http://imagecdn.xxxx.cn/image-xxx2.jpg": "5c0110fe43d7231d08xxxx"
        },
        "invalidUrls": null,
        "invalidDirs": null,
        "urlQuotaDay": 500,
        "urlSurplusDay": 496,
        "dirQuotaDay": 10,
        "dirSurplusDay": 10
      }
  • prefetchUrls(urls)

    CDN 文件预取
    单次请求链接不可以超过100个,如果超过,请分批发送请求
    
    @param urls: 完整链接的集合, ['', '', ...]
    @return
      {
        "ok": true | false,
        "err": 当 ok 为 false 时
        "code": 200,
        "error": "success",
        "requestId": "5c011212ae4f843390abaa57",
        "taskIds": {
          "http://imagecdn.xxxx.cn/image-xxxx1.jpeg": "5c011212ae4f843390xxxx",
          "http://imagecdn.xxxx.cn/image-xxxx2.jpg": "5c011212ae4f843390xxxx"
        },
        "invalidUrls": null,
        "quotaDay": 100,
        "surplusDay": 98
      }

License

MIT