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

@openfuse/ufs-js-client

v3.0.1

Published

ufs js客户端的sdk

Downloads

4

Readme

UFS JS SDK

安装

npm install @openfuse/ufs-js-client

使用

使用帮助见:https://docs.bingosoft.net/fuse/ufs-sdk/docs/intro/fast-started.html

1、初始化UFS Client

UfsClient是UFS的客户端,用于管理存储预览文件等操作。在进行所有UFS服务操作前,您都需先初始化一个UfsClient实例,以下代码用于创建UfsClient,一个工程中可以有一个或多个UfsClient,UfsClient支持并发使用

let client = new UfsClient({
    basePath: endpoint,  //如:'http://10.200.21.47:31365/ufsapi',
    accessToken: async () => {
        return getTokenFromSession();
    }
});

/**
 * 一般从前端的会话中获取token
 */
function getTokenFromSession(){
    // 如果使用fly-vue框架,可使用以下代码
    // import { Session } from '@fly-vue/core';
    // return Session.getToken();
    return "token_in_session";
}

新建UfsClient时, 需要指定Endpoint和AccessToken

  • Endpoint: Endpoint的信息需要从UFS负责人处获取
  • AccessToken: UFS接口调用凭据,一般有两种获取方式:
    • 方式一:从当前会话中获取,应用接入SSO后,用户从SSO登录成功后,会得到一个访问令牌,应用可以使用该令牌进行UFS相关操作
    • 方式二:使用应用的clientId和clientSecret生成应用的访问令牌,获取方式详见SSO获取AccessToken接口,(注:使用该类型的Token进行的操作,不包含操作人信息)
    • Token使用一段时间会自动过期,Token刷新方案详见SSO刷新token接口

2、文件上传

// 待上传的文件,一般为通过<input type="file">选择的文件,
const textFile = document.getElementById("fileInput").files[0];
const formData = new FormData();
formData.append('file', textFile);
    
const contentLengthPromise = new Promise<number>((resolve, reject) => {
    formData.getLength(async (_err, contentLength) => {
        if (_err) {
            reject(_err)
        } else {
            resolve(contentLength)
        }
    })
});
//这里注意:必须附加Content-Length头,否则会报错
const contentLength = await contentLengthPromise;

const fileAttrs = {
    filename: 'text.txt'
};
const signRequest: UploadSignRequest = { ...fileAttrs };
const commitRequest = { ...fileAttrs };
const res = await client.file()
    .upload(formData, signRequest, commitRequest, {
        headers: { 'Content-Length': contentLength }
    })
    .catch((err) => {
        console.log(err.response)
    });

// 处理文件上传结果
if (res) {
    let fileStatus: FileStatus = res.data
    return fileStatus;
}

3、文件下载

const fileId="xxxx";
const signedRes = await client.file()
    .downloadSign(fileId, {});
if(signedRes){
    // 获取文件下载地址,并下载文件
    const url=signedRes.data.url;
    window.open(url);
}

4、获取文件信息

const fileId="xxxx";
const res = await client.file().status(fileId);
if(res){
    console.log(res.data);
}