# faceplatform

> requesting utils for face platform

Latest version **0.6.3** (published 2018-03-12) · ISC license · 0 weekly downloads

## Install

```sh
npm install faceplatform
pnpm add faceplatform
yarn add faceplatform
bun add faceplatform
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.3 |
| Published | 2018-03-12 |
| First published | 2017-10-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | K |
| Maintainers | dalaorz |

## Links

- npm: https://www.npmjs.com/package/faceplatform
- Repository: git@olive.yitu-inc.com:BTS-DJ/faceplatform.js
- npm.io page: https://npm.io/package/faceplatform

## Dependencies (5)

- [async](https://npm.io/package/async.md) ^2.6.0
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [request](https://npm.io/package/request.md) ^2.81.0
- [request-promise-native](https://npm.io/package/request-promise-native.md) ^1.0.4

## Recent versions

- 0.6.3 (latest) — 2018-03-12
- 0.6.2 — 2018-01-23
- 0.6.1 — 2018-01-09
- 0.6.0 — 2018-01-09
- 0.5.6 — 2017-12-29
- 0.5.5 — 2017-12-29
- 0.5.4 — 2017-12-21
- 0.5.3 — 2017-12-21
- 0.5.2 — 2017-12-19
- 0.5.1 — 2017-12-19
- 0.5.0 — 2017-12-19
- 0.4.0 — 2017-11-13
- 0.3.2 — 2017-10-14
- 0.3.1 — 2017-10-14
- 0.3.0 — 2017-10-14
- … 1 more at https://npm.io/package/faceplatform/versions

## README

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 函数

---
_Source: https://npm.io/package/faceplatform · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
