open-index/open-npm huggingface dataset:
npm package: @liblibaix/arms
Description: aliyun arms
Author: liblibai
Latest version: 0.0.7
Deprecated: deprecated

## @liblibaix/arms

aliyun arms

## install

安装

```shell
npm i @liblibaix/arms
```

## use

使用

```javascript
// cjs
const { ARMS } = require('@liblibaix/arms');

// mjs
import { ARMS } from '@liblibaix/arms';
```

## api

## ARMS

引入阿里云ARMS

- options.isProduction
  - 类型: boolean
  - 说明: 是否生产环境，生产环境传true
- options.Script
  - 类型: Script
  - 说明: next.js中的Script
- options.ALIYUN_ARMS_APPID
  - 类型: string
  - 说明: 阿里云arms的应用id
- return
  - 类型: Script
  - 说明: nextjs中封装好的Script

```javascript
<ARMS options={}/>
```
npm package: @liblibaix/ext-oss
Description: oss util
Author: qiaowenbin
Latest version: 1.5.7
Deprecated: private

# @liblibaix/ext-oss

oss工具类

## 使用

```js
// upload
import { singleUploadForSD } from '@liblibaix/ext-oss';

// upload
const singleUploadForSD = Logger('@liblibaix/ext-oss');
```

## singleUploadXX

文件上传，没有分片和断点续传，适合图片上传使用，测试可以看`ui-upload.jsx`

- uuid
  - 类型: string
  - 说明: 用户uuid
- file
  - 类型: file
  - 说明: 待上传文件
- onCalcHashEnd
  - 类型: function
  - 说明: 文件hash计算完毕的回调，返回hash值
- return
  - 类型: object
  - ```js
    {
      file: 'web/image/8418faab24f34f3e904d67168708d7ec/test111test.png',
      url: 'https://model-ai-test.vibrou.com/web/image/8418faab24f34f3e904d67168708d7ec/test111test.png'
    }
    ```

```js
// 上传-生图
await singleUploadForSD(uuid, file, onCalcHashEnd);

// 上传-生图-临时
await singleUploadForSDTmp(uuid, file, onCalcHashEnd);

// 上传-模版工具
await singleUploadForTemplate(uuid, file, onCalcHashEnd);

// 上传-专业工具
await singleUploadForPro(uuid, file, onCalcHashEnd);

// 上传-训练
await singleUploadForTraining(uuid, file, onCalcHashEnd);

// 上传-社区图片
await singleUploadForCommunityImage(uuid, file, onCalcHashEnd);

// 上传-社区其他
await singleUploadForCommunityOther(uuid, file, onCalcHashEnd);
```

## modelUpload

模型上传，仅适用于模型上传，内部使用了分片上传，按1M分片

- uuid
  - 类型: string
  - 说明: 用户uuid
- file
  - 类型: file
  - 说明: 待上传文件
- onCalcHashEnd
  - 类型: function
  - 说明: 文件hash计算完毕的回调，返回hash值
- onUploadProgress
  - 类型: function
  - 说明: 上传文件的进度回调函数，返回percentage, checkpoint, res
- return
  - 类型: object
  - ```js
    {
      bucket:"liblibai-models",
      etag: "\"5ED2D125B7A4FC0CD9AEE8B1E1FA1DDD-50\"",
      file: "web/model/8418faab24f34f3e904d67168708d7ec/8565a714dca840f8652c5bae9249ab05f5fb5a4f9f13fbe23304b10f68252da2.safetensors",
      url: "https://model-ai-test.vibrou.com/web/model/8418faab24f34f3e904d67168708d7ec/8565a714dca840f8652c5bae9249ab05f5fb5a4f9f13fbe23304b10f68252da2.safetensors",
    }
    ```

```js
await modelUpload(uuid, file, onCalcHashEnd, onUploadProgress);

// 示例代码
const file = files[0];
const res = await modelUpload(
  uuid,
  file,
  (hash) => {
    console.log('onCalcHashEnd', hash);
  },
  async (percentage, checkpoint, res) => {
    console.log('onUploadProgress', percentage, checkpoint, res);
  },
);
console.log(res);
```

## copyObjectToTmp

将持久化bucket中的对象复制到临时bucket

- url
  - 类型: string
  - 说明: 待复制的url
- return
  - 类型: object
  - ```js
    {
      file: 'web/image/8418faab24f34f3e904d67168708d7ec/test111test.png',
      url: 'https://model-ai-test.vibrou.com/web/image/8418faab24f34f3e904d67168708d7ec/test111test.png'
    }
    ```

```js
await copyObjectToTmp(copyToTempUrl);
```

## copyObjectToOnline

将临时bucket中的对象复制到持久化bucket

- url
  - 类型: string
  - 说明: 待复制的url
- return
  - 类型: object
  - ```js
    {
      file: 'web/image/8418faab24f34f3e904d67168708d7ec/test111test.png',
      url: 'https://model-ai-test.vibrou.com/web/image/8418faab24f34f3e904d67168708d7ec/test111test.png'
    }
    ```

```js
await copyObjectToOnline(copyToTempUrl);
```
npm package: @liblibaix/model-upload
Description: upload model
Author: liblibai
Latest version: 1.0.5
Deprecated: deprecated, see @liblibaix/ext-oss

## @liblibai/model-upload

upload

## install

安装

```shell
npm i @liblibaix/model-upload
```

## use

使用

```javascript
// cjs
const { multiUpload, singleUpload } = require('@liblibaix/model-upload');

// mjs
import { multiUpload, singleUpload } from '@liblibaix/model-upload';
```

## options

- options.message
  - 类型: Function
  - 说明: antd message组件
- options.calculateHash
  - 类型: Function
  - 说明: 计算哈希函数
- options.cdnHost
  - 类型: string
  - 说明: cdn域名
- options.report
  - 类型: Function
  - 说明: 埋点函数
- options.axios
  - 类型: Axios
  - 说明: axios
- options.apiHost
  - 类型: string
  - 说明: api域名
- options.bucket
  - 类型: string
  - 说明: 桶
- options.bizcode
  - 类型: string
  - 说明: 项目区分
- options.OSS
  - 类型: OSS
  - 说明: OSS类
- options.Cookie
  - 类型: Cookie
  - 说明: Cookie函数
- options.file
  - 类型: File
  - 说明: 文件
- options.progress
  - 类型: Function
  - 说明: 上传进度函数

## code

```javascript
const cdnHost = process.env.NEXT_PUBLIC_OSS_HOST;
const bucket = process.env.NEXT_PUBLIC_OSS_BUCKET;
const bizcode = 'community-web';

const params = {
  message,
  calculateHash,
  cdnHost,
  report,
  axios,
  apiHost,
  bucket,
  bizcode,
  OSS,
  Cookie,
};

// 图片上传
export const postUploadData = async (file: any) => {
  return singleUpload({
    ...params,
    file,
  });
};

// 分片断点续传
export const MultipartUpload = async (file: any, progress: any) => {
  return multiUpload({
    ...params,
    file,
    progress,
  });
};
```