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

ztodo-file-client

v0.1.3

Published

this is my library

Downloads

16

Readme

文件服务 SDK 文档

1、安装

本 sdk 使用 ts 开发,支持 node.js/浏览器环境使用,用npm install来安装 sdk

npm install ztodo-file-client

2、初始化与认证

  • 在 node.js 环境中,使用TDNodeClient
//以下API用于node.js环境运行
//初始化
import { TDNodeClient } from "ztodo-file-client";
TDNodeClient.init(
  {
    api: "https://api.xxxx.com",
    issuer: "TODO_DEV",
  },
  true
);
const client = new TDNodeClient();
//用户token jwt认证,商户用户身份 使用文件接口
const token = "xxxxxxxx";
client.jwt(token);

//管理access_token 平台对接 用于管理商户配置
const access_token = "xxxxxxxx";
client.access_token(access_token);
  • 在浏览器环境中,使用TDWebClient
//以下API用于浏览器环境运行
//初始化
import { TDWebClient } from "ztodo-file-client";
TDWebClient.init(
  {
    api: "https://api.xxxx.com",
    issuer: "TODO_DEV",
  },
  true
);
const client = new TDWebClient();
//用户token jwt认证,商户用户身份 使用文件接口
const token = "xxxxxxxx";
client.jwt(token);

//管理access_token 平台对接 用于管理商户配置
const access_token = "xxxxxxxx";
client.access_token(access_token);

3、文件接口

3.1 文件上传

文件上传接口,小于 4M 的小文件通过服务器中转上传到供应商,大文件直接分片上传到服务供应商。

移动云 EOS、腾讯云 COS 需要在配置跨域访问 CORS

import { FileDto, ResultDataDto } from "ztodo-file-client";
const path = "/test/1000/test.jpg"; //上传到存储的文件路径,资源key
const file: File = document.getElementById("test").files[0]; // HTML 页面选择的文件
//文件上传
client
  .Post(path, file, `{'orderid':'1021232'}`, true, (percent: number) => {
    //上传进度
    console.log(`上传进度:${percent}/100`);
  })
  .then((result: ResultDataDto<FileDto>) => {
    console.log(`upload success: ${result.data.path}`);
  })
  .catch((reason) => {
    console.log(`upload error: ${JSON.stringify(reason)}`);
  });

3.2 文件查询

import { FileDto, ResultDataDto } from "ztodo-file-client";
const path = "/test/1000/test.jpg"; //上传到存储的文件路径,资源key
//文件查询,支持批量查询
client
  .Get([path], [])
  .then((result: ResultDataDto<FileDto>) => {
    console.log(`get success: ${result.data.path}`);
  })
  .catch((reason) => {
    console.log(`get error: ${JSON.stringify(reason)}`);
  });

3.3 文件删除

import { ResultDto } from "ztodo-file-client";
const path = "/test/1000/test.jpg"; //上传到存储的文件路径,资源key
//文件删除,支持批量
client
  .Delete([path], [])
  .then((result: ResultDto) => {
    console.log(`del success: ${result.data.path}`);
  })
  .catch((reason) => {
    console.log(`del error: ${JSON.stringify(reason)}`);
  });

3.4 文件打包下载 zip

import { ResultDataDto } from "ztodo-file-client";
const path1 = "/test/1000/test.jpg"; //上传到存储的文件路径,资源key
const path2 = "/test/1000/test2.jpg"; //上传到存储的文件路径,资源key
//文件zip打包下载,支持多个文件
client
  .Zip([path1, path2], [])
  .then((result: ResultDataDto<string>) => {
    console.log(`zip success: ${result.data}`);
  })
  .catch((reason) => {
    console.log(`zip error: ${JSON.stringify(reason)}`);
  });

3.5 文件分享

文件分享接口支持传入多个文件,创建一个分享链接,接口返回分享信息(包括分享链接、提取码、分享描述)复制发送给其他人,其他人可以直接下载分享的文件列表

服务端记录分享链接的下载次数、客户端 ip 等

import { ResultDataDto, ShareDto } from "ztodo-file-client";
const path1 = "/test/1000/test.jpg"; //上传到存储的文件路径,资源key
const path2 = "/test/1000/test2.jpg"; //上传到存储的文件路径,资源key
//文件分享,支持多个文件
client
  .Share([path1, path2], [], "我给你分享了文件,赶紧下载吧!")
  .then((result: ResultDataDto<ShareDto>) => {
    console.log(`share success: ${result.data}`);
  })
  .catch((reason) => {
    console.log(`share error: ${JSON.stringify(reason)}`);
  });

4、管理接口

4.1 查询商户配置

商户配置信息目前包括:状态、最大容量、默认存储供应商

import { EnterpriseConfDto, ResultDataDto } from "ztodo-file-client";
const owner_id = "1000"; //业务系统 商户id
client
  .GetConf(owner_id)
  .then((result: ResultDataDto<EnterpriseConfDto>) => {
    console.log(`getconf success: ${JSON.stringify(result)}`);
  })
  .catch((reason) => {
    console.log(`getconf error: ${JSON.stringify(reason)}`);
  });

4.2 修改商户配置

商户配置信息目前包括:状态、最大容量、默认存储供应商

import { ResultDto } from "ztodo-file-client";
const conf = {
  owner_id: "1000", //业务系统 商户id
  provider: "Eos", //默认存储供应商
  quota: 10240, //最大容量,单位MB
  status: 1,
};
client
  .SetConf(owner_id)
  .then((result: ResultDto) => {
    console.log(`setconf success: ${JSON.stringify(result)}`);
  })
  .catch((reason) => {
    console.log(`setconf error: ${JSON.stringify(reason)}`);
  });

4.3 查询商户用量统计

商户用量统计包括:已用容量、最大用量、文件数量、供应商使用统计(已用容量、文件数量)

import { EnterpriseStatDto, ResultDataDto } from "ztodo-file-client";
const owner_id = "1000"; //业务系统 商户id
client
  .Stat(owner_id)
  .then((result: ResultDataDto<EnterpriseStatDto>) => {
    console.log(`Stat success: ${JSON.stringify(result)}`);
  })
  .catch((reason) => {
    console.log(`Stat error: ${JSON.stringify(reason)}`);
  });