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

tool-aliyun-cdn

v1.0.2

Published

aliyun cdn api tool

Downloads

7

Readme

tool-aliyun-cdn

阿里云 cdn 工具包

feature

  • 刷新并推送 CDN
  • 查询 CDN 使用情况

quickstart

  1. 安装 npm

    npm install tool-aliyun-cdn --save
  2. 创建 AliyunCDN 对象

    const AliyunCDN = require('tool-aliyun-cdn');
    // https://usercenter.console.aliyun.com/
    const cdn = new AliyunCDN({
    	AccessKeyId: 'AccessKeyId', //阿里云颁发给用户的访问服务所用的密钥ID
    	AccessKeySecret: 'AccessKeySecret' //签名结果串,关于签名的计算方法,请参见签名机制。
    });
  3. 通用 API 调用

    cdn.request

    所有 AliyunCDN 方法返回都是 promise 规范,请求参数和 aliyun 一致阿里云 新版 API 参考

    cdn
    	.request({
    		url: cdn.buildAliyunApi({
    			Action: 'RefreshObjectCaches',
    			ObjectPath: `imagecdn.xx.cn/cdn/test/cdn1.png\r\nimagecdn.xx.cn/test/cdn2.png`,
    			ObjectType: 'File'
    		})
    	})
    	.then(data => {})
    	.catch(err => {});

刷新预热接口

cdn.refresh

刷新 CDN 缓存

| 参数 | 类型 | 说明 | | ------ | --------------- | ------------------------------------------------------------------------------------------------------ | | path | string | Array | 刷新路径、(多)文件 domain/file.png | ['domain/cdn/file1.png', 'domain/file2.png'] |domain/dirtory/ | | isFile | boolean | 文件、路径 |

目录方式

cdn.refresh({
	path: 'imagecdn.xx.cn/cdn/test',
	isFile: false
});

文件方式

cdn.refresh({
	path: ['imagecdn.xx.cn/cdn/test/cdn1.png', 'imagecdn.xx.cn/test/cdn2.png'],
	isFile: true
});

返回结果:

{
	RefreshTaskId: '4399915570',
	RequestId: '09B2C20B-9B9A-41D2-A22F-8F00191211EA'
}

cdn.preloadRefresh

预热 CDN

| 参数 | 类型 | 说明 | | ---- | --------------- | ---------------------------------------------- | | path | string | Array | 刷新文件(支持数组类型多文件),不支持目录预热 | | area | string | 区域 domestic|overseas |

cdn.preloadRefresh({
	path: ['imagecdn.xx.cn/cdn/test/cdn1.png', 'imagecdn.xx.cn/test/cdn2.png'],
	area: 'domestic'
});

返回结果:

{
	RefreshTaskId: '4399915570',
	RequestId: '09B2C20B-9B9A-41D2-A22F-8F00191211EA'
}

refreshHistory

CDN 历史刷新记录

| 参数 | 类型 | 说明 | | ---------- | ------ | ----------------------------------------- | | path | string | 精确路径 | | domain | string | 域名 | | type | string | 文件类型 preload | file | directory | | status | string | 刷新状态 Complete | Refreshing | Failed | | startTime | string | 北京时间(2019-02-19 17:00:00) | | endTime | string | 北京时间(2019-02-19 18:00:00) | | pageSize | number | 每页条数 | | pageNumber | number | 页数 |

cdn.refreshHistory({
	path: 'http://imagecdn.xx.cn/cdntest/cdn3.png',
	domain: 'imagecdn.xx.cn',
	type: 'file',
	startTime: '2019-02-19 17:00:00',
	endTime: '2019-02-19 18:00:00'
});

返回结果:

{
	PageNumber: 1,
	TotalCount: 17,
	PageSize: 20,
	RequestId: '0B94550C-F92D-4ACE-88DB-70A6B90BE559',
	Tasks:
	{
		CDNTask:[{
			CreationTime: '2019-02-19T07:57:58Z',
			ObjectPath: 'http://imagecdn.xx.cn/cdn/test/cdn1.png',
			Status: 'Complete',
			ObjectType: 'file',
			Process: '100%',
			TaskId: '4399109860'
		}]
	}
}

cdn.useInfo

CDN 套餐使用情况说明

cdn.useInfo();

返回结果:

{
	DirQuota: '100',
	PreloadRemain: '500',
	DirRemain: '99',
	blockRemain: '100',
	RequestId: 'E6882C9F-0054-4A0B-A237-00F217AE4DAE',
	UrlQuota: '2000',
	UrlRemain: '1980',
	BlockQuota: '100',
	PreloadQuota: '500'
}