Skip to content

Commit ccfd427

Browse files
author
Kelvin Luck
committed
feat: Introduce a getActiveRevision method
This loads the head object and then calls `listAllObjects` with the new `until` parameter and stops as soon as it has found an object which matches the `ETag` of the active revision. It returns the active revision in the same format that `fetchRevisions` would - for backward compatibility with use-cases which were depending on that.
1 parent 951e863 commit ccfd427

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/s3.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ module.exports = CoreObject.extend({
152152
.then((response) => response.Contents.find((element) => element.Key === revisionPrefix));
153153
},
154154

155+
getActiveRevision(options) {
156+
var client = this._client;
157+
var bucket = options.bucket;
158+
var prefix = options.prefix;
159+
var revisionPrefix = joinUriSegments(prefix, options.filePattern + ":");
160+
var indexKey = joinUriSegments(prefix, options.filePattern);
161+
162+
return headObject(client, { Bucket: bucket, Key: indexKey })
163+
.then((current) => this.listAllObjects(
164+
{ Bucket: bucket, Prefix: revisionPrefix },
165+
(element) => element.ETag === current.ETag
166+
)
167+
.then((elements) => {
168+
let activeRevision = elements.find((element) => element.ETag === current.ETag);
169+
if (!activeRevision) {
170+
return;
171+
}
172+
173+
var revision = activeRevision.Key.substr(revisionPrefix.length);
174+
return { active: true, revision, timestamp: activeRevision.LastModified };
175+
})
176+
);
177+
178+
},
179+
155180
fetchRevisions: function(options) {
156181
var client = this._client;
157182
var bucket = options.bucket;

0 commit comments

Comments
 (0)