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

@xylink/xy-upload-sdk

v0.0.3

Published

XY upload

Downloads

1

Readme

XY Upload SDK

一、简介

XY Upload SDK 是为集成小鱼OSS上传提供的JS SDK,支持分片上传、断点续传

二、安装

$ yarn add @xylink/xy-upload-sdk --dev
or
$ npm install @xylink/xy-upload-sdk --dev

三、API详述

1. 创建上传实例

重点说明:每上传一个文件都应创建一个上传实例,切勿用一个上传实例,连续上传多个文件

import xyUpload from '@xylink/xy-upload-sdk';

const client = xyUpload.createClient({
  server,
  enterpriseId,
  jsCode,
  uploadNonce,
  storeType
});

interface IConfig {
  // 必填:api 服务地址
  server: string;
  // 必填:企业id
  enterpriseId: string;
  // 必填:临时jsCode
  jsCode: string; 
  // 必填:随机字符
  uploadNonce: string; 
  // 必填:storeType
  storeType: string;
  // 选填:上传文件类型限制 例:['video/mp4','image/jpeg'],若不设置,可上传任何格式文件
  supportFileTypes?: string[];
}

2. 监听上传过程中的事件、状态变化

// 上传成功
client.on('success', (res: IResource) => { 
});

// 上传异常
client.on('error', (err: IError) => { 
});

// 监听上传进度 例:0.1 0.2 ..., 可转化成百分比
client.on('progress', (progress: number) => { 
});

// 上传暂停
client.on('pause', () => {
});

// 上传取消,会删除正在进行的上传,并且已经上传完成的片段也会被删除
client.on('abort', () => {
});

// 上传开始 开始上传或恢复上传后会触发
client.on('start', () => {
});

// 上传成功返回数据类型
interface IResource {
  preresourceId: string;
  resourceId: string;
  url: string;  // 资源路径
}

// 错误信息格式
interface IError {
  errorCode: number;
  errorMessage: string;
}

3. 开始上传

开始上传后,会触发start事件

// file 为将要上传的文件对象
client.startUpload(file: File);

4. 暂停上传

上传暂停后,会触发pause事件

client.pauseUpload();

5. 恢复上传

恢复上传后会触发start事件

client.resumeUpload();

6. 取消上传

  • 取消上传后会触发abort事件
  • 取消上传只能在当前上传暂停或者进行中调用,如果上传已经成功,则无法取消
client.abortUpload();

四、异常处理

监控异常请在error事件中监听

1. 操作异常

| errorCode | errorMessage | | --- | --- | | 40001 | 文件类型不在允许上传类型范围内 | | 40002 | 上传已经开始过,无法再重新开始 | | 40003 | 文件没有正在上传,无法暂停 | | 40004 | 文件上传完成或者还未开始,无法清除上传 | | 40005 | 文件上传不是暂停状态,无法恢复上传 |

2. 服务端异常

服务端异常只有在传参错误的情况下才会发生

| errorCode | errorMessage | | --- | --- | | 2002 | 参数无效 | | 2003 | 数据不存在 | | 2004 | 数据已删除 | | 2011 | 服务主用户不存在 | | 2012 | 该仓库未开通STS授权 | | 2013 | 不允许上传该类型的文件 | | 2014 | 申请STS授权失败 | | 40443 | jsCode失效 | | 60001 | 传入的enterpriseId有误 | | 60003 | API签名不正确 |

五、demo

github地址:https://github.com/xylink-com/xylink-upload-demo

六、版本说明

| 版本 | 功能说明 | 更新时间 | 备注 | | :---: | --- | --- | --- | | v0.0.1 | 1. 支持监听上传开始、暂停、取消、成功等状态变化1. 支持监听上传进度1. 支持开始上传、暂停上传、恢复上传、取消上传等方法 | 2020-12-29 | | | v0.0.2 | 增加40006错误码,表示正在和服务端正在数据交互,不能再进行其它操作| 2021-1-4 | | | v0.0.3 | 1. 创建上传实例参数变更1. 增加40443错误码 | 2021-2-7 | |