Skip to content

Commit

Permalink
Merge branch 'master' into ts/ObjectUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed May 17, 2023
2 parents 9f9f36e + ff0e3cc commit 9932948
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 42 deletions.
26 changes: 23 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,30 @@ Fork [minio-js upstream](https://github.com/minio/minio-js/fork) source reposito
```bash
$ git clone https://github.com/$USER_ID/minio-js
$ cd minio-js
```

### Install npm dependencies

```bash
$ npm install
$ npm test
$ npm build
...
```

### Format code (with prettier)

```shell
$ npm run format
```

### Check Code Style

```shell
$ npm run lint
```

### Tests

```shell
$ npm run test
```

### Developer Guidelines
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ npm install -g

## Using with TypeScript

```sh
npm install --save-dev @types/minio
```
`minio>7.1.0` is shipped with builtin type definition, `@types/minio` is no longer needed.

## Initialize MinIO Client

Expand Down Expand Up @@ -244,5 +242,4 @@ The full API Reference is available here.

[Contributors Guide](https://github.com/minio/minio-js/blob/master/CONTRIBUTING.md)

[![Build Status](https://travis-ci.org/minio/minio-js.svg)](https://travis-ci.org/minio/minio-js)
[![Build status](https://ci.appveyor.com/api/projects/status/1d05e6nvxcelmrak?svg=true)](https://ci.appveyor.com/project/harshavardhana/minio-js)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/minio/minio-js/nodejs.yml)
4 changes: 1 addition & 3 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ MinIO JavaScript Client SDK提供简单的API来访问任何Amazon S3兼容的

## 使用NPM下载

```sh
npm install --save minio
```
`minio>7.1.0` 拥有自带的类型定义,不再需要安装 `@types/minio`

## 下载并安装源码

Expand Down
27 changes: 24 additions & 3 deletions docs/zh_CN/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
### 设置你的minio-js Github仓库
Fork [minio-js upstream](https://github.com/minio/minio-js/fork) 源码仓库到你的个人仓库。

MinIO Javascript使用[gulp](http://gulpjs.com/)来管理它的依赖。
### 克隆代码

```bash
$ git clone https://github.com/$USER_ID/minio-js
$ cd minio-js
```

### 安装依赖

```bash
$ npm install
$ gulp
...
```

### 格式化代码

```shell
$ npm run format
```

### 检查代码风格

```shell
$ npm run lint
```

### 运行测试

```shell
$ npm run test
```

### 开发者指南
Expand Down
19 changes: 9 additions & 10 deletions src/AssumeRoleProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface AssumeRoleProviderOptions {
transportAgent?: http.Agent
}

const defaultExpiry = 900
const defaultExpirySeconds = 900

export class AssumeRoleProvider extends CredentialProvider {
private readonly stsEndpoint: URL
Expand All @@ -77,7 +77,7 @@ export class AssumeRoleProvider extends CredentialProvider {
stsEndpoint,
accessKey,
secretKey,
durationSeconds = defaultExpiry,
durationSeconds = defaultExpirySeconds,
sessionToken,
policy,
region = '',
Expand Down Expand Up @@ -106,8 +106,8 @@ export class AssumeRoleProvider extends CredentialProvider {
this.durationSeconds = parseInt(durationSeconds as unknown as string)

let expirySeconds = this.durationSeconds
if (this.durationSeconds < defaultExpiry) {
expirySeconds = defaultExpiry
if (this.durationSeconds < defaultExpirySeconds) {
expirySeconds = defaultExpirySeconds
}
this.expirySeconds = expirySeconds // for calculating refresh of credentials.

Expand Down Expand Up @@ -241,13 +241,12 @@ export class AssumeRoleProvider extends CredentialProvider {
}

async getCredentials(): Promise<Credentials> {
let credConfig: Credentials | null
if (!this._credentials || (this._credentials && this.isAboutToExpire())) {
credConfig = await this.refreshCredentials()
} else {
credConfig = this._credentials
if (this._credentials && !this.isAboutToExpire()) {
return this._credentials
}
return credConfig

this._credentials = await this.refreshCredentials()
return this._credentials
}

isAboutToExpire() {
Expand Down
31 changes: 15 additions & 16 deletions src/internal/request.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type * as http from 'node:http'
import type * as https from 'node:https'
import type * as stream from 'node:stream'
import { pipeline } from 'node:stream'

import type { Transport } from './type.ts'

export async function request(
transport: typeof http | typeof https,
transport: Transport,
opt: https.RequestOptions,
body: Buffer | string | stream.Readable | null = null,
): Promise<http.IncomingMessage> {
Expand All @@ -12,25 +15,21 @@ export async function request(
resolve(resp)
})

requestObj.on('error', (e: unknown) => {
reject(e)
})

if (!body) {
requestObj.end(null)
return
}
if (!body || Buffer.isBuffer(body) || typeof body === 'string') {
requestObj
.on('error', (e: unknown) => {
reject(e)
})
.end(body)

if (Buffer.isBuffer(body) || typeof body === 'string') {
requestObj.end(body)
return
}

// stream.Readable
body.pipe(requestObj)
body.on('error', (err) => {
requestObj.destroy(err)
reject(err)
// pump readable stream
pipeline(body, requestObj, (err) => {
if (err) {
reject(err)
}
})
})
}
3 changes: 2 additions & 1 deletion src/internal/response.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type http from 'node:http'
import type stream from 'node:stream'

export async function readAsBuffer(res: stream.Readable): Promise<Buffer> {
Expand All @@ -10,7 +11,7 @@ export async function readAsBuffer(res: stream.Readable): Promise<Buffer> {
})
}

export async function readAsString(res: stream.Readable): Promise<string> {
export async function readAsString(res: http.IncomingMessage): Promise<string> {
const body = await readAsBuffer(res)
return body.toString()
}
Expand Down
2 changes: 1 addition & 1 deletion src/signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export function presignSignatureV4(
request: IRequest,
accessKey: string,
secretKey: string,
sessionToken: string,
sessionToken: string | undefined,
region: string,
requestDate: Date,
expires: number,
Expand Down

0 comments on commit 9932948

Please sign in to comment.