@aligreen/sdk
v1.2.0
Published
Unofficial Node SDK for aligreen.
Downloads
9
Readme
aligreen-node-sdk
Unofficial Node SDK for aligreen.
阿里云 - 云盾 - 内容安全 API 非官方 NodeJS SDK
Note: Node >= v8 LTS
Install
npm i @aligreen/sdk uuid -S
or
yarn add @aligreen/sdk uuid
uuid
is optional
Usage
const uuidV4 = require('uuid/v4');
const AliGreenSDK = require('@aligreen/sdk');
// Initialize a client
const client = new AliGreenSDK({
accessKeyId: '<ak>',
accessKeySecret: '<sk>',
regionId: 'cn-shanghai',
});
(async () => {
// detect with url
const result1 = await client.request('ImageSyncScanRequest', {
scenes: ['porn'],
tasks: [
{
dataId: uuidV4(), // unique
url: 'https://img.alicdn.com/tfs/TB1urBOQFXXXXbMXFXXXXXXXXXX-1442-257.png',
}
],
});
console.log(result1);
// detect with local file
const url = await client.upload('/path/of/file');
const result2 = await client.request('ImageSyncScanRequest', {
scenes: ['porn'],
tasks: [
{
dataId: uuidV4(),
url,
}
],
});
console.log(result2);
})();
API
Here action
is the same in Python SDK, here's a relation map between action
and path
.
For more details, please read the official documents.
export = AliGreenSDK;
declare class AliGreenSDK {
constructor(options: IOptions);
/**
* Make a detect request
* @param action Request action name or url path
* @param params Request parameters
*/
request(action: string, params?: IJSON): Promise<any>;
/**
* Upload local file to OSS
* @param filepath Absolute local file path
*/
upload(filepath: string): Promise<string>;
}
interface IJSON {
[k: string]: any;
}
interface IOptions {
accessKeyId: string;
accessKeySecret: string;
regionId: string;
// Optinal, default: 2018-05-09
apiVersion?: string;
// Optinal, default: {}
clientInfo?: IClientInfo;
}
// Ref: https://help.aliyun.com/document_detail/53413.html#h2-url-2
interface IClientInfo {
sdkVersion?: string;
cfgVersion?: string;
userType?: 'taobao' | 'others';
userId?: string;
userNick?: string;
avatar?: string;
imei?: string;
imsi?: string;
umid?: string;
ip?: string;
os?: string;
channel?: string;
hostAppName?: string;
hostPackage?: string;
hostVersion?: string;
}
Developement
git clone https://github.com/int64ago/aligreen-node-sdk.git
cd aligreen-node-sdk
npm install
npm run generate
AK=<AK> SK=<SK> npm test
LICENSE
MIT