0.6.3 • Published 6 years ago

faceplatform v0.6.3

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

https://www.npmjs.com/package/faceplatform

If you have no idea what face platform is, you’ve probably come to the wrong place.

这个模块是 FP 的应用层接口封装,需配合内部接口文档使用(主要是确认每个接口要发送的数据格式)。

安装

npm install faceplatform  # 建议 node LTS 版本及以上

使用示例

const fs = require('fs');
const FP = require('faceplatform');

const fp = new FP({
    address: '192.168.10.100',
    version: 'mtx.3',
    auth: {
        name: 'admin',
        password: 'admin'
    },
    request_timeout: 10000
});
/********************************************************************************************
**   构造函数传入的数据可以有以下字段:
**
**  - address: 如 ‘192.168.10.100’, 可选字段, 指大平台 master ip 地址, 默认是 127.0.0.1
**  - version: 如 ‘mtx.2’, 必填字段,必须是 `mtx.2`, `mtx.3`, `pgy` 之一,其他版本待后续更新
**  - auth: 可选字段,可填大平台登录信息,默认是 { name: “admin”, password: “admin” }  (无需md5)
**  - request_timeout: 可选字段, 单位为毫秒, 默认是 60000
********************************************************************************************/

let repoId;

fp.get_repository()       // 获取人像库

    .then(() => {
        for (let repo of fp._r.results) {
            if (repo.name === 'test') {
                repoId = repo.id;
                break;
            }
        }
        console.log('test repo id is ' + repoId);
    })

    // 新建人像库
    .add_repository({ name: "test_repo_2" }, function (err, resp, body) {
        console.log('create reposicoty result:');
        console.log(err);
        console.log(resp.statusCode);
        console.log(body);
    })

    // 上传图片
    .upload_image(fp.w(function () {
        return {
            repository_id: fp._r.id,        // 直接使用上个接口调用的结果
            picture_image_content_base64: fs.readFileSync('test.jpg', 'base64')
        };
    }))

    .then(fp.break)                         // 停止调用

    //  不会被上传
    .upload_image({
        repository_id: repoId,
        picture_image_content_base64: fs.readFileSync('test.jpg', 'base64')
    })

    // 捕获异常
    .catch(err => {
        console.log('catch error: ' + err);
    })

    .exec();            // 每次链式调用从 exec() 结束

如以上示例所示:

  • 接口名字可参考 interfaces.js
  • 接口支持链式调用
  • 传入接口的 object 会被当做 request 请求的 body
  • 接口调用支持传入回调函数
  • 接口调用返回 Promise
  • 接口调用支持传入回调函数的同时返回 Promise
  • 最后一个接口调用必须是 exec
  • exec 可传入一个函数,适合传入回调函数
  • _r 指的是上一个接口的返回数据,但如果要在下一个接口直接调用时访问此对象,需要包在 w 函数中
  • 任意接口均不需要先调用登录接口获取 session_id,这个过程会在内部替你完成并记录
  • 大平台接口返回如果 rtn 不为 0,会被当做错误 reject 出来, 在 catch 方法中可以捕获到
  • break 函数可用于停止某条链式调用
  • 如果要调试,请运行时使用环境变量 DEBUG=faceplatform

TODO

  • test cases
  • examples

CHANGELOG

  • 0.6.3 增加底层 get_alerts 接口
  • 0.6.2 将错误传入 exec 收到的函数
  • 0.6.0 引入 session 池,支持并发
  • 0.5.6 增加 utils,base64 转换及 md5 等
  • 0.5.5 增加 encoding 支持,可保持 binary 响应文件
  • 0.5.4 支持最后调用回调函数
  • 0.5.2 蒲公英支持
  • 0.5.1 DEBUG 支持
  • 0.5.0 引入 session_id 自刷新机制
  • 0.4.0 引入 break 函数
0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago