@@ -83,10 +83,9 @@ module.exports = CoreObject.extend({
83
83
params . ContentEncoding = 'br' ;
84
84
}
85
85
86
- return this . fetchRevisions ( options )
87
- . then ( function ( revisions ) {
88
- var found = revisions . map ( function ( element ) { return element . revision ; } ) . indexOf ( options . revisionKey ) ;
89
- if ( found >= 0 && ! allowOverwrite ) {
86
+ return this . findRevision ( options )
87
+ . then ( function ( found ) {
88
+ if ( found !== undefined && ! allowOverwrite ) {
90
89
return RSVP . reject ( "REVISION ALREADY UPLOADED! (set `allowOverwrite: true` if you want to support overwriting revisions)" ) ;
91
90
}
92
91
return RSVP . resolve ( ) ;
@@ -131,9 +130,8 @@ module.exports = CoreObject.extend({
131
130
params . ServerSideEncryption = serverSideEncryption ;
132
131
}
133
132
134
- return this . fetchRevisions ( options ) . then ( function ( revisions ) {
135
- var found = revisions . map ( function ( element ) { return element . revision ; } ) . indexOf ( options . revisionKey ) ;
136
- if ( found >= 0 ) {
133
+ return this . findRevision ( options ) . then ( function ( found ) {
134
+ if ( found !== undefined ) {
137
135
return copyObject ( params ) . then ( function ( ) {
138
136
plugin . log ( '✔ ' + revisionKey + " => " + indexKey ) ;
139
137
} ) ;
@@ -143,6 +141,17 @@ module.exports = CoreObject.extend({
143
141
} ) ;
144
142
} ,
145
143
144
+ findRevision : function ( options ) {
145
+ var client = this . _client ;
146
+ var listObjects = RSVP . denodeify ( client . listObjects . bind ( client ) ) ;
147
+ var bucket = options . bucket ;
148
+ var prefix = options . prefix ;
149
+ var revisionPrefix = joinUriSegments ( prefix , options . filePattern + ":" + options . revisionKey ) ;
150
+
151
+ return listObjects ( { Bucket : bucket , Prefix : revisionPrefix } )
152
+ . then ( ( response ) => response . Contents . find ( ( element ) => element . Key === revisionPrefix ) ) ;
153
+ } ,
154
+
146
155
fetchRevisions : function ( options ) {
147
156
var client = this . _client ;
148
157
var bucket = options . bucket ;
0 commit comments