npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nsrd/file-storage-sdk

v1.1.0-alpha.7

Published

an encapsulation of a file store.

Downloads

12

Readme

文件存储file-storage-sdk

  • vite 打包

  • typescript 语法

  • 支持多入口打包 详见 vite.build.mjs - entryList

  • 对接文件存储服务

使用

说明

该组件库依赖于 axios spark-md5, 安装依赖时会自动安装,异常情况请确认依赖已安装

安装

npm npm install @nsrd/file-storage-sdk -S

yarn yarn add @nsrd/file-storage-sdk

pnpm pnpm install @nsrd/file-storage-sdk -S

引入

  • 第一种import FileStorage from "@nsrd/file-storage-sdk" 【推荐】

  • 第二种 const FileStorage = require("@nsrd/file-storage-sdk")

使用示例

import FileStorage from "@nsrd/file-storage-sdk";

const FS = new FileStorage({
  base: 'http://172.30.3.152/file-storage/rest/v2'
})

const voucherId = "asdad213qdwasd123" // 业务系统提供的操作凭证

FS.upload({
    chunk: true,
    voucherId: voucherId,
    file: file.value,
    onProgress: (res) => {
        console.log(res);
    }
}).then(res => {
    console.log('upload result', res);
})

API

构造函数

const FS = new FileStorage(options)
  • options(constructor): object构造函数参数

| 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ------------- | ------ | -------- | ------- | ------------------------------------------------------------ | | base | string | 否 | ./ | 文件存储地址服务地址,支持相对地址、绝对地址、完整地址。例如 http://172.30.3.152/file-storage/rest/v2。 | | chunkSize | number | 否 | 5242880 | 分片上传时分片大小默认5MB,请输入大于5MB的字节数 | | errorNum | number | 否 | 20 | 允许的上传出现错误总数 默认 20 | | chunkErrorNum | number | 否 | 5 | 同一分片上传错误次数 默认 5 | | timeout | number | 否 | 60000 | 单个接口超时时间 默认60s |

方法

1.upload 上传
FS.upload(options)
  • options: object上传函数参数

| 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ------------- | -------- | -------- | ------ | ------------------------------------------------------- | | voucherId | string | 是 | - | 业务系统获取的操作凭证 | | file | File | 是 | - | 要上传的文件 | | errorNum | number | 否 | - | 允许上传出现错误总数,默认为 options.errorNum | | chunkErrorNum | number | 否 | - | 允许同一分片上传错误次数,默认为 options.chunkErrorNum | | onProgress | Function | 否 | - | 上传进度回调返回值详见下文onProgress |

  • options.onProgress#返回值 : object

| 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ------- | ----------------------------------------- | -------- | ------ | ------------------------------------------------------- | | status | 'preloading' | 'uploading' | 'complete' | 是 | - | preloading: 前置处理中 uploading: 上传中 complete: 完成 | | current | number | 否 | - | 当前已完成分片数 | | total | number | 否 | - | 总分片数 |

  • 返回值 FS.upload : Promise<object>

    • fulfilled

    | 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ---------------- | ------ | -------- | ------ | --------------------------------- | | code | string | 是 | - | 状态码:'00000':正常;其他异常 | | message | string | 是 | - | 接口说明 | | uniqueId | string | 是 | - | 文件标识 | | publicUniqueName | string | 否 | - | 文件公开访问标识用于文件url访问 |

    • rejected

    | 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ------- | ------ | -------- | ------ | ------------------ | | code | string | 是 | - | 状态码:非 "00000" | | message | string | 是 | - | 接口说明 |

2.download 下载
FS.download(options)
  • options: object下载函数参数

| 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ---------------- | ------- | ----------------------------------- | ------ | ------------------------------------------- | | stream | boolean | 否 | false | true:获取文件Filefalse:直接下载文件 | | voucherId | string | voucherId/publicUniqueName 存在一个 | - | 下载操作凭证 | | publicUniqueName | string | voucherId/publicUniqueName 存在一个 | - | 公开访问标识 |

  • 返回值 FS.download: Promise<object>
    • fulfilled

      | 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ------- | ------ | -------- | ------ | ------------------------------- | | code | string | 是 | - | 状态码:'00000':正常;其他异常 | | message | string | 是 | - | 接口说明 | | url | string | 否 | - | 下载地址 | | file | File | 否 | - | 下载的文件 |

    • rejected

      | 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ------- | ------ | -------- | ------ | ------------------ | | code | string | 是 | - | 状态码:非 '00000' | | message | string | 是 | - | 接口说明 |

3.getDownloadUri 获取下载地址
FS.getDownloadUri(options)
  • options: object获取下载地址函数参数

| 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ---------------- | ------ | ---------------------------------- | ------ | ------------ | | voucherId | string | voucherId/publicUniqueName 存在一个 | - | 下载操作凭证 | | publicUniqueName | string | voucherId/publicUniqueName 存在一个 | - | 公开访问标识 |

  • 返回值 FS.getDownloadUri: Promise<object>

    • fulfilled

      | 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ------- | ------ | -------- | ------ | ------------------------------- | | code | string | 是 | - | 状态码:'00000':正常;其他异常 | | message | string | 是 | - | 接口说明 | | url | string | 是 | - | 下载地址 |

    • rejected

      | 属性名 | 类型 | 是否必填 | 默认值 | 说明 | | ------- | ------ | -------- | ------ | ------------------ | | code | string | 是 | - | 状态码:非 '00000' | | message | string | 是 | - | 接口说明 |

develop

  1. scripts命令

    {
        "alpha": "打签:alpha 版本",
        "build": "仓库打包",
        "commit": "提交代码",
        "dev": "启动项目",
        "eslint": "eslint格式化代码",
        "postinstallmac": "苹果环境配置",
        "pre-commit": "预提交",
        "prepare": "环境配置",
        "release": "打签:release 版本",
        "sort": "package.json排序"
    }
  2. 安装依赖

    yarn install
    # npm install
    # pnpm install
  3. 本地启动

    npm run dev
  4. 代码提交

    预提交检查代码

    npm run pre-commit

    提交代码

    npm run commit
  5. 发布

  • tag

    alpha版本

    npm run alpha

    release版本

    npm run release
  • publish

    npm publish