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

@faceunity/storage

v5.1.10

Published

### Usage

Downloads

1

Readme

存储层兼容SDK(OSS与minio)

Usage

npm i @faceunity/storage

示例

OSS

import { Storage, StorageType } from 'storage';

const instance = new Storage(StorageType.OSS, {
    region: process.env.OSS_REGION,
	secure: true,
	accessKeyId: process.env.OSS_KEY,
	accessKeySecret: process.env.OSS_SECRET,
	bucket: process.env.OSS_BUCKET,
	internal: false,
});

(async () => {
    const url = await instance.generatePublicObjectUrl("test.json");
    console.log(url);
    console.log(await instance.exist("test.json"));
})()

minio

minio后端的截图功能使用ffmpeg实现,优先使用本地的ffmpeg,其次使用@ffmpeg-installer/ffmpeg包,都不满足时无法使用截图相关接口与配置

import { Storage, StorageType } from 'storage';

const instance = new Storage(StorageType.OSS, {
    endPoint: process.env.MINIO_ENDPOINT,
	port: 9000,
	accessKey: process.env.MINIO_KEY,
	secretKey: process.env.MINIO_SECRET,
	useSSL: false,
	bucket: process.env.MINIO_BUCKET, //为了兼容OSS行为,除minio实例化必须参数外还需要传入bucket参数指定仓库
});

(async () => {
    const url = await instance.generatePublicObjectUrl("test.json");
    console.log(url);
    console.log(await instance.exist("test.json"));
})()

API

自定义实现

/**
 * 某些特定需求可以通过实例的instance属性获得具体实现的SDK实例
 */
const instance = new Storage(StorageType.OSS,oss_options);
instance.instance

不兼容实现

/**
 * 某些实现方式上无法兼容的方法可以通过实例的client属性调用,等同于封装的自定义实现
 */
const instance = new Storage(StorageType.OSS,oss_options);
instance.client

Storage

/**
 * 存储层后端实现支持StorageType.MINIO或StorageType.OSS
 * options传入各自后端需要的参数即可
 * oss参考https://github.com/ali-sdk/ali-oss#ossoptions
 * minio参考https://docs.min.io/docs/javascript-client-api-reference
 * minio实现除必要参数外需要额外传入bucket参数,参照上方minio实例
 */
const instance = new Storage(StorageType.OSS,oss_options);

list

/**
 * 该函数支持按页迭代与正则匹配
 * 该函数OSS实现从性能考虑不进行全量迭代返回总条数
 * 该函数minio实现由于表现一致性问题需要进行全量内存排序,数量级较大时慎用
 * OSS实现需要获取总条数或大量minio对象list时使用自定义接口
 * @param prefix 前缀匹配
 * @param query 正则过滤
 * @param page 页数
 * @param pageNumber 每页数量
 * @returns string[]
 */
instance.list("prefix", new RegExp("t_"), 2, 5);

exist

/**
 * 判断对象是否存在
 * @param path 对象路径
 */
instance.exist("test.json");

delete

/**
 * 删除对象
 * @param path 对象路径
 */
instance.delete("test.json");

put

/**
 * 上传对象
 * @param path 对象路径
 * @param input 读文件流/Buffer
 */
instance.put("test.json",createReadStream("./out.json"));
instance.put("test.json",readFileSync("./out.json"));

get

/**
 * 获取对象Buffer
 * @param path 对象路径
 */
instance.get("test.json");

deleteMulti

/**
 * 一次删除多个对象
 * @param paths 对象路径
 */
instance.deleteMulti(["test.json","test1.json"]);

copy

instance.copy("test.json","test1.json");

getInfo

该接口用于获得对象信息(包括metadata信息),由于ts的编译器目前尚无法支持泛型类实例方法上的泛型推断,默认返回泛型为OSS返回类型,MINIO作为存储后端时可以使用instance.getInfo<StorageType.MINIO>("test.json");来更正返回类型

instance.getInfo("test.json");
instance.getInfo<StorageType.OSS>("test.json");
instance.getInfo<StorageType.MINIO>("test.json");

不兼容实现(OSS):

generatePublicObjectUrl

/**
 * 获取对象公网URL
 * @param path 对象路径
 */
instance.client.generatePublicObjectUrl("test.json");

generatePrivateObjectUrl

/**
 * 获取对象内网URL
 * @param path 对象路径
 */
instance.client.generatePrivateObjectUrl("test.json");

generatePublicSnapShotUrl

/**
 * 获取对象内网截图URL
 * @param path 对象路径
 */
instance.client.generatePublicSnapShotUrl("test.mp4", SnapShotObjectType.VIDEO);
instance.client.generatePublicSnapShotUrl("test.jpg", SnapShotObjectType.IMAGE);
instance.client.generatePublicSnapShotUrl("test.mp4", SnapShotObjectType.VIDEO, { expire: 3600, width: 300, height: -1 });
instance.client.generatePublicSnapShotUrl("test.jpg", SnapShotObjectType.IMAGE, { expire: 3600, width: 300, height: -1 });

generatePrivateSnapShotUrl

/**
 * 获取对象内网截图URL
 * @param path 对象路径
 */
instance.client.generatePrivateSnapShotUrl("test.mp4", SnapShotObjectType.VIDEO);
instance.client.generatePrivateSnapShotUrl("test.jpg", SnapShotObjectType.IMAGE);
instance.client.generatePrivateSnapShotUrl("test.mp4", SnapShotObjectType.VIDEO, { expire: 3600, width: 300, height: -1 });
instance.client.generatePrivateSnapShotUrl("test.jpg", SnapShotObjectType.IMAGE, { expire: 3600, width: 300, height: -1 });

不兼容实现(Minio):

generateObjectUrl

/**
 * 获取对象URL
 * @param path 对象路径
 */
instance.client.generateObjectUrl("test.json");

generateSnapShotImage

该方法使用FFMPEG生成首帧图(视频/图片),并且支持缩放

/**
 * 获取视频首帧图/对图片进行resize
 * @param path 对象路径
 */
let buf = instance.client.generateSnapShotImage("test.mp4", SnapShotObjectType.VIDEO, { width: -1, height: 300 });
buf = instance.client.generateSnapShotImage("test.png", SnapShotObjectType.IMAGE, { width: -1, height: 300 });
buf = instance.client.generateSnapShotImage("test.mp4", SnapShotObjectType.VIDEO, { width: -1, height: 300 });
buf = instance.client.generateSnapShotImage("test.png", SnapShotObjectType.IMAGE, { width: -1, height: 300 });
buf = instance.client.generateSnapShotImage("test.mp4", SnapShotObjectType.VIDEO, { width: -1, height: 300 });
buf = instance.client.generateSnapShotImage("test.png", SnapShotObjectType.IMAGE, { width: -1, height: 300 });