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

seiue-c3-file

v1.0.1

Published

Seiue Chalk 3.0 File SDK

Downloads

5

Readme

Seiue Chalk3.0 File

Seiue Chalk 3 文件上传机制

Get Started

初始化

// File 依赖于 Session
import { SeiueSession } from 'seiue-c3-session'
import { seiueFiles, SeiueFiles } from "seiue-c3-file";

// 设置 Session 的环境变量
SeiueSession.setEnv({
  SERVER_PASSPORT: 'Seiue Passport 服务地址"',
  CLIENT_WEB_CLIENT_ID: "客户端 ID"
})

SeiueSession.create().then(res => {
  // 登录成功后,res 将会返回登录信息,然后注册 File
  SeiueFiles.init({
    env: {
      RID: res.rid,
      SERVER_CHALK: "Seiue Chalk 服务地址",
      SERVER_PLATFORM: "Seiue Platform 服务地址",
      SERVER_PASSPORT: "Seiue Passport 服务地址",
      REFRESH_TOKEN_IF_NEEDED: SeiueSession.refreshOAuthTokenIfNeeded,
    },
  });
})

上传

function Upload() {
  return (
    <div>
      <input
        type="file"
        onChange={async e => {
          // 直接上传文件
          const result = await seiueFiles.uploadDirect(e.target.files[0])

          // 获取 Hash,然后再通过 seiueFiles.hashToUrl 得到完整的文件地址

          console.log(seiueFiles.hashToUrl(result.hash))
        }}
      />
    </div>
  )
}

SeiueFiles Apis

SeiueFiles 文件上传类

仅在初始化时使用

SeiueFiles.init({ envs }) 初始化与配置环境变量

在使用其他 Api 前,请先完整配置环境变量。注意在 Session 初始化完毕后,再进行本 SDK 的初始化。

参数

envs: {
  // Seiue Chalk 服务地址
  SERVER_CHALK: string
  // Seiue Platform 服务地址
  SERVER_PLATFORM: string
  // Seiue Rid 登录的用户 rid,可从 Session.create 中取出
  RID: number
  // 是否是本地部署
  LOCAL_DEPLOY: boolean
  // 当 Token 过期时的刷新方法,可以直接传入 SeiueSession.refreshOAuthTokenIfNeeded
  REFRESH_TOKEN_IF_NEEDED: () => Promise<OAuthToken>
}

返回值

void

seiueFile 文件上传单例

将 SeiueFiles 初始化后,可以从 'seiue-c3-file' export 出 seiueFile,进而进行一系列上传操作

seiueFile.uploadDirect(file) 直接上传文件

参数

file - File - 文件本件,通常从 input(type="file") 中获取

返回值

result: {
  hash: string // 文件的唯一标识
  name: string // 文件名
  size: number // 文件大小
}

seiueFile.uploadImageDataUrl(dataUrl) 上传 dataUrl 形态的图片文件

参数

dataUrl - string - dataUrl,通常借助 Canvas 生成

返回值

hash: string // 文件的唯一标识

seiueFile.hashToUrl(hash, { compress }) 将文件标识转化为可访问地址

参数

hash: string // 文件唯一标识
compress: {
  zoom?: ['lfit' | 'fill', number | null, number | null] // 图片缩放配置,分别为 [等比/填充,宽,高]
  quality?: number // 图片的压缩质量
}

返回值

url: string // 文件的可访问地址

seiue.uploaderFactory(file, onChange) 文件上传构造器

额外的接受一个 onChange 参数,通过 onChange,可以获取到文件上传前,中,后的各种进度和状态

Notes

  • 目前仅适用于会部署在希悦内部的项目

Bug and Discussions

如果你遇到 bug,可以通过相关微信群或者联系 [email protected]