@acheetahk/cloudtools 中文文档教程
#
@acheetahk/cloudtools
@acheetahk/cloudtools ☁️ . Cloud server tools.
请使用2.0.0以上的版本
Methods Nav
Installation
npm install @acheetahk/cloudtools
cnpm install @acheetahk/cloudtools
yarn add @acheetahk/cloudtools
Dependencies
{
"@types/ali-oss": "^6.0.5",
"ali-oss": "^6.11.2",
"aliyun-sdk": "^1.12.3"
}
Usage
IP
validationIp
/**
* Is a correct IP address
*
* @param ipStr `string` ipv4 or ipv6
*
* @returns boolean
*/
validationIp('2001:3CA1:010F:001A:121B:0000:0000:0010') // true
getIpByRequest
/**
* Get the IP from the request
*
* @param requset `Request`
*
* @returns string
*/
getIpByRequest(request) // ip string
SLS
import { SLS } from '@acheetahk/cloudtools';
const logger = new SLS.SLSLogger('TOPIC', options);
SLS.SLSLogger args
|param|type|require| |:-:|:-:|:-:| |主题
|字符串
|true| |选项
|SLSOptions
|true|
SLS.SLSLogger SLSOptions
参见:阿里云文档
accessKeyId: string; // access secret you create
secretAccessKey: string; // access secret you create
endpoint?: string; // sls region domain. It takes priority over region.
apiVersion?: string; // 2015-06-01
project: string;
logStore: string;
SLS.SLSLogger method (logger level)
// log put =====> aliyun sls
logger.info('simple logger', 'info');
logger.error('simple logger');
logger.debug('simple logger');
logger.fatal('simple logger');
logger.trace('simple logger');
logger.fatal('simple logger');
logger.warn('simple logger');
SLS.SLSLogger method args
|param|type|require| |:-:|:-:|:-:| |值
|字符串
|true| |来源
|字符串
|true|
OSS
import { OSS } from '@acheetahk/cloudtools';
import { fileToBuffer } from '@acheetahk/request';
const storage = new OSS.BaseOSS(options);
const buffer = await fileToBuffer('http://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png');
// const buffer = fs.readFileSync(<path>);
OSS.BaseOSS options
accessKeyId: string; // access secret you create
accessKeySecret: string; // access secret you create
stsToken?: string; // used by temporary authorization
bucket?: string; // the default bucket you want to access If you don't have any bucket, please use putBucket() create one first.
endpoint?: string; // oss region domain. It takes priority over region.
region?: string; // the bucket data region location, please see Data Regions, default is oss-cn-hangzhou.
internal?: boolean; // access OSS with aliyun internal network or not, default is false. If your servers are running on aliyun too, you can set true to save lot of money.
secure?: boolean; // instruct OSS client to use HTTPS (secure: true) or HTTP (secure: false) protocol.
timeout?: string | number; // instance level timeout for all operations, default is 60s
cname?: boolean; // use custom domain name
OSS.BaseOSS upload
// upload
const result = await storage.upload('/test/test.png', buffer);
const result1 = await storage.upload('/test/test1.png', buffer, 'put');
const result2 = await storage.upload('/test/test2.png', buffer, 'putStream');
OSS.BaseOSS upload args
|参数|类型|要求| |:-:|:-:|:-:| |路径
|字符串
|true| |fileBuffer
|Buffer
|true| |类型
|类型:'put' | 'putStream'
|true|
OSS.BaseOSS delete
// delete
await storage.delete('/test/test.png');
OSS.BaseOSS delete args
|参数|类型|要求| |:-:|:-:|:-:| |路径
|字符串
|true|
#
@acheetahk/cloudtools
@acheetahk/cloudtools ☁️ . Cloud server tools.
Please use version greater than 2.0.0
Methods Nav
about
ip
aliyun
Installation
npm install @acheetahk/cloudtools
cnpm install @acheetahk/cloudtools
yarn add @acheetahk/cloudtools
Dependencies
{
"@types/ali-oss": "^6.0.5",
"ali-oss": "^6.11.2",
"aliyun-sdk": "^1.12.3"
}
Usage
IP
validationIp
/**
* Is a correct IP address
*
* @param ipStr `string` ipv4 or ipv6
*
* @returns boolean
*/
validationIp('2001:3CA1:010F:001A:121B:0000:0000:0010') // true
getIpByRequest
/**
* Get the IP from the request
*
* @param requset `Request`
*
* @returns string
*/
getIpByRequest(request) // ip string
SLS
import { SLS } from '@acheetahk/cloudtools';
const logger = new SLS.SLSLogger('TOPIC', options);
SLS.SLSLogger args
|param|type|require| |:-:|:-:|:-:| |topic
|string
|true| |options
|SLSOptions
|true|
SLS.SLSLogger SLSOptions
see: aliyun doc
accessKeyId: string; // access secret you create
secretAccessKey: string; // access secret you create
endpoint?: string; // sls region domain. It takes priority over region.
apiVersion?: string; // 2015-06-01
project: string;
logStore: string;
SLS.SLSLogger method (logger level)
// log put =====> aliyun sls
logger.info('simple logger', 'info');
logger.error('simple logger');
logger.debug('simple logger');
logger.fatal('simple logger');
logger.trace('simple logger');
logger.fatal('simple logger');
logger.warn('simple logger');
SLS.SLSLogger method args
|param|type|require| |:-:|:-:|:-:| |value
|string
|true| |source
|string
|true|
OSS
import { OSS } from '@acheetahk/cloudtools';
import { fileToBuffer } from '@acheetahk/request';
const storage = new OSS.BaseOSS(options);
const buffer = await fileToBuffer('http://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png');
// const buffer = fs.readFileSync(<path>);
OSS.BaseOSS options
accessKeyId: string; // access secret you create
accessKeySecret: string; // access secret you create
stsToken?: string; // used by temporary authorization
bucket?: string; // the default bucket you want to access If you don't have any bucket, please use putBucket() create one first.
endpoint?: string; // oss region domain. It takes priority over region.
region?: string; // the bucket data region location, please see Data Regions, default is oss-cn-hangzhou.
internal?: boolean; // access OSS with aliyun internal network or not, default is false. If your servers are running on aliyun too, you can set true to save lot of money.
secure?: boolean; // instruct OSS client to use HTTPS (secure: true) or HTTP (secure: false) protocol.
timeout?: string | number; // instance level timeout for all operations, default is 60s
cname?: boolean; // use custom domain name
OSS.BaseOSS upload
// upload
const result = await storage.upload('/test/test.png', buffer);
const result1 = await storage.upload('/test/test1.png', buffer, 'put');
const result2 = await storage.upload('/test/test2.png', buffer, 'putStream');
OSS.BaseOSS upload args
|param|type|require| |:-:|:-:|:-:| |path
|string
|true| |fileBuffer
|Buffer
|true| |type
|type: 'put' | 'putStream'
|true|
OSS.BaseOSS delete
// delete
await storage.delete('/test/test.png');
OSS.BaseOSS delete args
|param|type|require| |:-:|:-:|:-:| |path
|string
|true|