@@ -33,6 +33,7 @@ import { CredentialProvider } from './CredentialProvider.ts'
33
33
import * as errors from './errors.ts'
34
34
import { extensions } from './extensions.js'
35
35
import { CopyDestinationOptions , CopySourceOptions , DEFAULT_REGION } from './helpers.ts'
36
+ import { CopyConditions } from './internal/copy-conditions.ts'
36
37
import {
37
38
calculateEvenSplits ,
38
39
extractMetadata ,
@@ -66,6 +67,7 @@ import {
66
67
uriEscape ,
67
68
uriResourceEscape ,
68
69
} from './internal/helper.ts'
70
+ import { PostPolicy } from './internal/post-policy.ts'
69
71
import { getS3Endpoint } from './internal/s3-endpoints.ts'
70
72
import { LEGAL_HOLD_STATUS , RETENTION_MODES , RETENTION_VALIDITY_UNITS } from './internal/type.ts'
71
73
import { NotificationConfig , NotificationPoller } from './notification.js'
@@ -74,11 +76,13 @@ import { promisify } from './promisify.js'
74
76
import { postPresignSignatureV4 , presignSignatureV4 , signV4 } from './signing.ts'
75
77
import * as transformers from './transformers.js'
76
78
import { parseSelectObjectContentResponse } from './xml-parsers.js'
77
- // will be replaced by bundler
78
- const Package = { version : process . env . MINIO_JS_PACKAGE_VERSION || 'development' }
79
79
80
80
export * from './helpers.ts'
81
81
export * from './notification.js'
82
+ export { CopyConditions , PostPolicy }
83
+
84
+ // will be replaced by bundler
85
+ const Package = { version : process . env . MINIO_JS_PACKAGE_VERSION || 'development' }
82
86
83
87
export class Client {
84
88
constructor ( params ) {
@@ -3848,134 +3852,3 @@ Client.prototype.setObjectLegalHold = promisify(Client.prototype.setObjectLegalH
3848
3852
Client . prototype . getObjectLegalHold = promisify ( Client . prototype . getObjectLegalHold )
3849
3853
Client . prototype . composeObject = promisify ( Client . prototype . composeObject )
3850
3854
Client . prototype . selectObjectContent = promisify ( Client . prototype . selectObjectContent )
3851
-
3852
- export class CopyConditions {
3853
- constructor ( ) {
3854
- this . modified = ''
3855
- this . unmodified = ''
3856
- this . matchETag = ''
3857
- this . matchETagExcept = ''
3858
- }
3859
-
3860
- setModified ( date ) {
3861
- if ( ! ( date instanceof Date ) ) {
3862
- throw new TypeError ( 'date must be of type Date' )
3863
- }
3864
-
3865
- this . modified = date . toUTCString ( )
3866
- }
3867
-
3868
- setUnmodified ( date ) {
3869
- if ( ! ( date instanceof Date ) ) {
3870
- throw new TypeError ( 'date must be of type Date' )
3871
- }
3872
-
3873
- this . unmodified = date . toUTCString ( )
3874
- }
3875
-
3876
- setMatchETag ( etag ) {
3877
- this . matchETag = etag
3878
- }
3879
-
3880
- setMatchETagExcept ( etag ) {
3881
- this . matchETagExcept = etag
3882
- }
3883
- }
3884
-
3885
- // Build PostPolicy object that can be signed by presignedPostPolicy
3886
- export class PostPolicy {
3887
- constructor ( ) {
3888
- this . policy = {
3889
- conditions : [ ] ,
3890
- }
3891
- this . formData = { }
3892
- }
3893
-
3894
- // set expiration date
3895
- setExpires ( date ) {
3896
- if ( ! date ) {
3897
- throw new errors . InvalidDateError ( 'Invalid date : cannot be null' )
3898
- }
3899
- this . policy . expiration = date . toISOString ( )
3900
- }
3901
-
3902
- // set object name
3903
- setKey ( objectName ) {
3904
- if ( ! isValidObjectName ( objectName ) ) {
3905
- throw new errors . InvalidObjectNameError ( `Invalid object name : ${ objectName } ` )
3906
- }
3907
- this . policy . conditions . push ( [ 'eq' , '$key' , objectName ] )
3908
- this . formData . key = objectName
3909
- }
3910
-
3911
- // set object name prefix, i.e policy allows any keys with this prefix
3912
- setKeyStartsWith ( prefix ) {
3913
- if ( ! isValidPrefix ( prefix ) ) {
3914
- throw new errors . InvalidPrefixError ( `Invalid prefix : ${ prefix } ` )
3915
- }
3916
- this . policy . conditions . push ( [ 'starts-with' , '$key' , prefix ] )
3917
- this . formData . key = prefix
3918
- }
3919
-
3920
- // set bucket name
3921
- setBucket ( bucketName ) {
3922
- if ( ! isValidBucketName ( bucketName ) ) {
3923
- throw new errors . InvalidBucketNameError ( `Invalid bucket name : ${ bucketName } ` )
3924
- }
3925
- this . policy . conditions . push ( [ 'eq' , '$bucket' , bucketName ] )
3926
- this . formData . bucket = bucketName
3927
- }
3928
-
3929
- // set Content-Type
3930
- setContentType ( type ) {
3931
- if ( ! type ) {
3932
- throw new Error ( 'content-type cannot be null' )
3933
- }
3934
- this . policy . conditions . push ( [ 'eq' , '$Content-Type' , type ] )
3935
- this . formData [ 'Content-Type' ] = type
3936
- }
3937
-
3938
- // set Content-Type prefix, i.e image/ allows any image
3939
- setContentTypeStartsWith ( prefix ) {
3940
- if ( ! prefix ) {
3941
- throw new Error ( 'content-type cannot be null' )
3942
- }
3943
- this . policy . conditions . push ( [ 'starts-with' , '$Content-Type' , prefix ] )
3944
- this . formData [ 'Content-Type' ] = prefix
3945
- }
3946
-
3947
- // set Content-Disposition
3948
- setContentDisposition ( value ) {
3949
- if ( ! value ) {
3950
- throw new Error ( 'content-disposition cannot be null' )
3951
- }
3952
- this . policy . conditions . push ( [ 'eq' , '$Content-Disposition' , value ] )
3953
- this . formData [ 'Content-Disposition' ] = value
3954
- }
3955
-
3956
- // set minimum/maximum length of what Content-Length can be.
3957
- setContentLengthRange ( min , max ) {
3958
- if ( min > max ) {
3959
- throw new Error ( 'min cannot be more than max' )
3960
- }
3961
- if ( min < 0 ) {
3962
- throw new Error ( 'min should be > 0' )
3963
- }
3964
- if ( max < 0 ) {
3965
- throw new Error ( 'max should be > 0' )
3966
- }
3967
- this . policy . conditions . push ( [ 'content-length-range' , min , max ] )
3968
- }
3969
-
3970
- // set user defined metadata
3971
- setUserMetaData ( metaData ) {
3972
- if ( ! isObject ( metaData ) ) {
3973
- throw new TypeError ( 'metadata should be of type "object"' )
3974
- }
3975
- Object . entries ( metaData ) . forEach ( ( [ key , value ] ) => {
3976
- const amzMetaDataKey = `x-amz-meta-${ key } `
3977
- this . policy . conditions . push ( [ 'eq' , `$${ amzMetaDataKey } ` , value ] )
3978
- this . formData [ amzMetaDataKey ] = value
3979
- } )
3980
- }
3981
- }
0 commit comments