Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed May 21, 2023
2 parents 9932948 + 5144d0d commit d348204
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 37 deletions.
4 changes: 2 additions & 2 deletions examples/compose-object-test-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const os = require('os')
const splitFile = require('split-file')
const fs = require('fs')

var Minio = require('../dist/main/minio')
var Helpers = require('../dist/main/helpers')
var Minio = require('minio')
var Helpers = require('minio/dist/main/helpers')

var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
Expand Down
4 changes: 2 additions & 2 deletions examples/compose-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname
// are dummy values, please replace them with original values.

var Minio = require('../dist/main/minio')
var Helpers = require('../dist/main/helpers')
var Minio = require('minio')
var Helpers = require('minio/dist/main/helpers')

var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
Expand Down
2 changes: 1 addition & 1 deletion examples/minio/listen-bucket-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Note that `listenBucketNotification` is only available for MinIO, and not
// Amazon.

const Minio = require('../')
const Minio = require('minio')

var s3Client = new Minio.Client({
endPoint: '...',
Expand Down
2 changes: 1 addition & 1 deletion examples/select-object-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname
// and my-objectname are dummy values, please replace them with original values.

var Minio = require('../dist/main/minio')
var Minio = require('minio')

var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
Expand Down
8 changes: 8 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export interface ICopyDestinationOptions {
*/
RetainUntilDate?: string
Mode?: RETENTION_MODES
MetadataDirective?: 'COPY' | 'REPLACE'
}

export class CopyDestinationOptions {
Expand All @@ -185,6 +186,7 @@ export class CopyDestinationOptions {
private readonly LegalHold?: 'on' | 'off'
private readonly RetainUntilDate?: string
private readonly Mode?: RETENTION_MODES
private readonly MetadataDirective?: string

constructor({
Bucket,
Expand All @@ -195,6 +197,7 @@ export class CopyDestinationOptions {
LegalHold,
RetainUntilDate,
Mode,
MetadataDirective,
}: ICopyDestinationOptions) {
this.Bucket = Bucket
this.Object = Object
Expand All @@ -204,6 +207,7 @@ export class CopyDestinationOptions {
this.LegalHold = LegalHold
this.Mode = Mode // retention mode
this.RetainUntilDate = RetainUntilDate
this.MetadataDirective = MetadataDirective
}

getHeaders(): RequestHeaders {
Expand Down Expand Up @@ -238,6 +242,10 @@ export class CopyDestinationOptions {
}
}

if (this.MetadataDirective) {
headerOptions[`X-Amz-Metadata-Directive`] = this.MetadataDirective
}

if (this.Encryption) {
const encryptionHeaders = getEncryptionHeaders(this.Encryption)
for (const [key, value] of Object.entries(encryptionHeaders)) {
Expand Down
41 changes: 20 additions & 21 deletions src/internal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface ClientOptions {
pathStyle?: boolean
credentialsProvider?: CredentialProvider
s3AccelerateEndpoint?: string
transportAgent?: http.Agent | https.Agent
transportAgent?: http.Agent
}

export type RequestOption = Partial<IRequest> & {
Expand Down Expand Up @@ -211,7 +211,6 @@ export class TypedClient {

if (params.credentialsProvider) {
this.credentialsProvider = params.credentialsProvider
void this.checkAndRefreshCreds()
}

this.regionMap = {}
Expand Down Expand Up @@ -256,6 +255,24 @@ export class TypedClient {
this.reqOptions = _.pick(options, requestOptionProperties)
}

/**
* This is s3 Specific and does not hold validity in any other Object storage.
*/
private getAccelerateEndPointIfSet(bucketName?: string, objectName?: string) {
if (!isEmpty(this.s3AccelerateEndpoint) && !isEmpty(bucketName) && !isEmpty(objectName)) {
// http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html
// Disable transfer acceleration for non-compliant bucket names.
if (bucketName.includes('.')) {
throw new Error(`Transfer Acceleration is not supported for non compliant bucket:${bucketName}`)
}
// If transfer acceleration is requested set new host.
// For more details about enabling transfer acceleration read here.
// http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html
return this.s3AccelerateEndpoint
}
return false
}

/**
* returns options object that can be used with http.request()
* Takes care of constructing virtual-host-style or path-style hostname
Expand Down Expand Up @@ -296,7 +313,7 @@ export class TypedClient {

// For Amazon S3 endpoint, get endpoint based on region.
if (isAmazonEndpoint(host)) {
const accelerateEndPoint = this.getAccelerateEndPointIfSet(bucketName!, objectName)
const accelerateEndPoint = this.getAccelerateEndPointIfSet(bucketName, objectName)
if (accelerateEndPoint) {
host = `${accelerateEndPoint}`
} else {
Expand Down Expand Up @@ -355,24 +372,6 @@ export class TypedClient {
} satisfies https.RequestOptions
}

/**
* This is s3 Specific and does not hold validity in any other Object storage.
*/
private getAccelerateEndPointIfSet(bucketName: string, objectName?: string) {
if (!isEmpty(this.s3AccelerateEndpoint) && !isEmpty(bucketName) && !isEmpty(objectName)) {
// http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html
// Disable transfer acceleration for non-compliant bucket names.
if (bucketName.includes('.')) {
throw new Error(`Transfer Acceleration is not supported for non compliant bucket:${bucketName}`)
}
// If transfer acceleration is requested set new host.
// For more details about enabling transfer acceleration read here.
// http://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html
return this.s3AccelerateEndpoint
}
return false
}

public async setCredentialsProvider(credentialsProvider: CredentialProvider) {
if (!(credentialsProvider instanceof CredentialProvider)) {
throw new Error('Unable to get credentials. Expected instance of CredentialProvider')
Expand Down
3 changes: 1 addition & 2 deletions src/internal/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type * as http from 'node:http'
import type * as https from 'node:https'

export type Binary = string | Buffer

Expand Down Expand Up @@ -46,7 +45,7 @@ export enum LEGAL_HOLD_STATUS {
DISABLED = 'OFF',
}

export type Transport = typeof http | typeof https
export type Transport = Pick<typeof http, 'request'>

export interface IRequest {
protocol: string
Expand Down
4 changes: 1 addition & 3 deletions src/minio.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// imported from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/93cfb0ec069731dcdfc31464788613f7cddb8192/types/minio/index.d.ts
/* eslint-disable @typescript-eslint/no-explicit-any */

import { EventEmitter } from 'node:events'
import type { RequestOptions } from 'node:https'
import type { Readable as ReadableStream } from 'node:stream'

import type {
Expand Down Expand Up @@ -637,8 +637,6 @@ export class Client extends TypedClient {
// Other
newPostPolicy(): PostPolicy

setRequestOptions(options: RequestOptions): void

// Minio extensions that aren't necessary present for Amazon S3 compatible storage servers
extensions: {
listObjectsV2WithMetadata(
Expand Down
4 changes: 1 addition & 3 deletions src/minio.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@ export class Client extends TypedClient {
(result, cb) => {
objStat = result
// Create any missing top level directories.
fs.mkdir(path.dirname(filePath), { recursive: true }, (err) => {
cb(err)
})
fs.mkdir(path.dirname(filePath), { recursive: true }, (err) => cb(err))
},
(cb) => {
partFile = `${filePath}.${objStat.etag}.part.minio`
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4136,7 +4136,7 @@ describe('functional tests', function () {

step('Clean up temp directory part files', (done) => {
if (isSplitSuccess) {
fs.rmSync(tmpSubDir, { recursive: true, force: true })
fs.rmdirSync(tmpSubDir)
}
done()
})
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"sourceMap": true,
"outDir": "./dist/main/",
"rootDir": "./src"
}
},
"exclude": ["dist/**/*", "node_modules/**/*"]
}

0 comments on commit d348204

Please sign in to comment.