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

multipart_upload

v1.2.5

Published

`该包旨在简化OSS上传使用流程`

Downloads

4

Readme

SimpleOSS

该包旨在简化OSS上传使用流程

说明

SimpleOSS是构造函数,使用前需要先进行实例化。

该包已发布到公司私有镜像,npmjs留存一份。

该包使用alicdn动态引入ali-oss依赖,极大程度上减小webpack打包体积及打包时间。

一、实例化

| 参数 | 类型 | 描述 | 默认值 | | --------- | -------- | ---------- | -------------------------- | | userId | string | 租户 ID | | partSize | string | 分片大小 | 1 (单位 MB) | | progress | Function | 进度回调 | (response: object) => void | | onPreview | Function | 预览图回调 | (src: string) => void |

import { SimpleOSS } from "multipart_upload";
const oss = new SimpleOSS({
  userId: ".........",
  partSize: 1,
  progress: (percentage) => {
    console.log(`当前进度: ${percentage}%`);
  },
  onPreview: (imgSrc) => {
    console.log(`当前预览图地址: ${imgSrc}`);
  },
});

二、上传调用

| 参数 | 类型 | 描述 | | ------- | ------ | -------- | | file | File | 文件对象 | | options | Object | 配置对象 |

options

| 参数 | 类型 | 可选值 | 描述 | 默认值 | | ------------ | ------------------- | --------------------------------------------- | -------------------------------------------------- | -------- | | tokenValue | Object | | OSS 配置(必传) | | | validation | Function | boolean | | 文件校验方法,或者使用组件内部的校验方法(非必填) | true | | sizeMap | Object | | 文件大小校验规则 [validation 为 true 时, 必传] | | | accept | String | image/* | video/* | audio/* | vector/* | 接受的文件类型 (非必传) (不传代表直接放弃类型校验) | '' | | fileName | String | | 上传文件名 (非必传)(用于覆盖或自定义上传名) | | | responsePath | String | absolute | relative | 响应路径 (非必传) | absolute |

validation传递false时, sizeMap和accept都不需要传

tokenValue

| 参数 | 类型 | 描述 | | --------------- | ------ | -------------- | | accessKeyId | string | OSS 账号 | | accessKeySecret | string | OSS 临时密码 | | securityToken | string | OSS 临时 Token | | region | string | OSS 区域 | | bucket | string | OSS 桶 | | dir | string | OSS 路径 |

sizeMap

| 参数 | 类型 | 描述 | | -------- | ------ | ------------------ | | maxValue | number | 文件最大值(体积) | | minValue | number | 文件最小值(体积) | | minPixel | number | 文件最小值(分辨率) |

// 例如:
oss.upload({
  file: files,
  options: {
    tokenValue: {
      accessKeyId: "STS.NTWXHx9Ua7X19KYTLUBNNP5ca",
      securityToken: "CAIS/QF1q6Ft5B2yfSjI.....",
      bucket: "test-dam-feiyuantu",
      accessKeySecret: "4mDSxN5Uefq1QrKG6WMPkAm5JPbyi7sW5BeNDv9hxZnU",
      region: "oss-cn-beijing",
      expireTime: "2020-10-23T08:27:21Z",
      dir: "vdam-php/others/111129/",
    },
    validation: true,
    sizeMap: {
      minValue: 0, // MB
      maxValue: 2, // MB
      minPixel: 2000, // px
    },
    accept: "image/*",
  },
});
// 使用自定义校验方法

// 校验成功 code: 1, 校验失败 code: 0 -- 固定格式!!!!!
const customValidator = (file) => {
  const { name } = file;
  if (name.length > 5)
    return { code: 0, message: `自定义校验方法: 文件名长度 ${name.length}` };
  return {
    code: 1,
    message: `自定义校验方法: 文件名长度 ${name.length}`,
    src: "...",
  };
};

oss.upload({
  file: files,
  options: {
    tokenValue: {
      accessKeyId: "...",
      securityToken: "...",
      bucket: "...",
      accessKeySecret: "...",
      region: "...",
      expireTime: "...",
      dir: "...",
    },
    validation: customValidator,
  },
});

三、暂停、取消调用

oss.cancel();

四、续传调用

oss.multipartUpload();

生成校验规则

该方法旨在简化生成文件 [大小,分辨率] 校验规则流程

import { verificationRules } from "multipar_upload";

const { store } = context;
const {
  runtime: { customerInfo },
} = store();
const { config } = customerInfo || {};

const sizeMap = verificationRules(config, file);
console.log(sizeMap);
// 此时的sizeMap可用于 SimpleOSS 校验规则中