2.4.5 • Published 3 years ago

@acheetahk/cloudtools v2.4.5

Weekly downloads
2
License
BSD-2-Clause
Repository
-
Last release
3 years ago

codecov build npm npm.io npm.io

Please use version greater than 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

paramtyperequire
topicstringtrue
optionsSLSOptionstrue
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

paramtyperequire
valuestringtrue
sourcestringtrue

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

paramtyperequire
pathstringtrue
fileBufferBuffertrue
typetype: 'put' | 'putStream'true

OSS.BaseOSS delete

// delete
await storage.delete('/test/test.png');

OSS.BaseOSS delete args

paramtyperequire
pathstringtrue
2.4.5

3 years ago

2.4.3

3 years ago

2.4.2

3 years ago

2.4.4

3 years ago

2.4.1

3 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.0

3 years ago

1.17.0

3 years ago

1.16.0

3 years ago

1.15.0

3 years ago

1.14.0

3 years ago

1.13.0

3 years ago

1.12.0

3 years ago

1.9.2

3 years ago

1.11.0

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago