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

@feng-j/midwayjs-minio

v1.0.2

Published

用于连接MinIO的MidwayJS的组件

Downloads

5

Readme

MidwayJS-MinIO

用于在MidwayJS项目中快捷访问MinIO,支持多客户端连接。

安装使用

$ npm install minio @feng-j/midwayjs-minio

在configuration中引入minIO

import * as minIO from '@feng-j/midwayjs-minio';
// ......

@Configuration({
  imports: [
    // ......
    minIO,
  ],
  importConfigs: [join(__dirname, './config')],
})
export class MainConfiguration {
  @App('koa')
  app: koa.Application;

  async onReady() {
    this.app.useMiddleware([ReportMiddleware]);
  }
}

在配置文件中添加minIO相关的配置

export default {
  // ......
  minIO: {
    client: {
      endPoint: 'play.min.io',
      port: 9000,
      useSSL: true,
      accessKey: 'Q3AM3UQ867SPQQA43P2F',
      secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
    },
  },
} as MidwayConfig;

然后就可以通过Inject来注入MinIOService了

import { Inject, Controller, Get, Query } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { UserService } from '../service/user.service';
import { MinIOService } from '@feng-j/midwayjs-minio';

@Controller('/api')
export class APIController {
  @Inject()
  ctx: Context;

  @Inject()
  userService: UserService;

  @Inject()
  minIOService: MinIOService;

  @Get('/get_user')
  async getUser(@Query('uid') uid) {
    const user = await this.userService.getUser({ uid });
    return { success: true, message: 'OK', data: user };
  }

  @Get('/buckets')
  async getBuckets() {
    return {
      success: true,
      message: 'OK',
      data: await this.minIOService.listBuckets(),
    };
  }
}

启动开发服务器npm run dev,使用浏览器访问http://127.0.0.1:7001/api/buckets查看效果。

更多方法可以见MinIO SDK文档

多客户端连接

在配置中配置多个client即可

export default {
  // ......
	minIO: {
    clients: {
      bucket1: {
        endPoint: 'play.min.io',
        port: 9000,
        useSSL: true,
        accessKey: 'Q3AM3UQ867SPQQA43P2F',
        secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
      },
      bucket2: {
        endPoint: 'play.min.io',
        port: 9000,
        useSSL: true,
        accessKey: 'Q3AM3UQ867SPQQA43P2F',
        secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG',
      },
    },
  },
} as MidwayConfig; 

通过工厂类获取具体的client

import { Inject, Controller, Get, Param } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { MinIOServiceFactory } from '@feng-j/midwayjs-minio';

@Controller('/api')
export class APIController {
  @Inject()
  ctx: Context;


  @Inject()
  minIOServiceFactory: MinIOServiceFactory;

  @Get('/buckets/:bucketName')
  async getBucket(@Param('bucketName') bucketName: string) {
    const bucket = this.minIOServiceFactory.get(bucketName);
    return {
      success: true,
      message: 'OK',
      data: await bucket.listBuckets(),
    };
  }
}