Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions spec/providers/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,40 +70,6 @@ describe('storage.FunctionBuilder', () => {
expect(() => storage.bucket('bad/bucket/format')).to.throw(Error);
});

it('should correct nested media links using a single literal slash', () => {
let cloudFunction = storage.object().onChange((event) => {
return event.data.mediaLink;
});
let badMediaLinkEvent = {
data: {
mediaLink: 'https://www.googleapis.com/storage/v1/b/mybucket.appspot.com'
+ '/o/nestedfolder/myobject.file?generation=12345&alt=media',
},
};
return cloudFunction(badMediaLinkEvent).then(result => {
expect(result).equals(
'https://www.googleapis.com/storage/v1/b/mybucket.appspot.com'
+ '/o/nestedfolder%2Fmyobject.file?generation=12345&alt=media');
});
});

it('should correct nested media links using multiple literal slashes', () => {
let cloudFunction = storage.object().onChange((event) => {
return event.data.mediaLink;
});
let badMediaLinkEvent = {
data: {
mediaLink: 'https://www.googleapis.com/storage/v1/b/mybucket.appspot.com'
+ '/o/nestedfolder/anotherfolder/myobject.file?generation=12345&alt=media',
},
};
return cloudFunction(badMediaLinkEvent).then(result => {
expect(result).equals(
'https://www.googleapis.com/storage/v1/b/mybucket.appspot.com'
+ '/o/nestedfolder%2Fanotherfolder%2Fmyobject.file?generation=12345&alt=media');
});
});

it('should not mess with media links using non-literal slashes', () => {
let cloudFunction = storage.object().onChange((event) => {
return event.data.mediaLink;
Expand Down
3 changes: 3 additions & 0 deletions src/providers/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export class AnalyticsEventBuilder {
handler: (event: Event<AnalyticsEvent>) => PromiseLike<any> | any
): CloudFunction<AnalyticsEvent> {
const dataConstructor = (raw: Event<any>) => {
if (raw.data instanceof AnalyticsEvent) {
return raw.data;
}
return new AnalyticsEvent(raw.data);
};
return makeCloudFunction({
Expand Down
18 changes: 1 addition & 17 deletions src/providers/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export class BucketBuilder {
}
}

// A RegExp that matches on a GCS media link that points at a _nested_ object (one that uses a path/with/slashes).
const nestedMediaLinkRE = new RegExp('https://www.googleapis.com/storage/v1/b/([^/]+)/o/(.*)');

export class ObjectBuilder {
/** @internal */
constructor(private resource) { }
Expand All @@ -63,21 +60,8 @@ export class ObjectBuilder {
* Handle any change to any object.
*/
onChange(handler: (event: Event<ObjectMetadata>) => PromiseLike<any> | any): CloudFunction<ObjectMetadata> {
// This is a temporary shim to fix the 'mediaLink' for nested objects.
// BUG(37962789): clean this up when backend fix for bug is deployed.
let correctMediaLink = (event: Event<ObjectMetadata>) => {
let deconstructedNestedLink = event.data.mediaLink.match(nestedMediaLinkRE);
if (deconstructedNestedLink != null) {
// The media link for a nested object uses an illegal URL (using literal slashes instead of "%2F".
// Fix up the URL.
let bucketName = deconstructedNestedLink[1];
let fixedTail = deconstructedNestedLink[2].replace(/\//g, '%2F'); // "/\//g" means "all forward slashes".
event.data.mediaLink = 'https://www.googleapis.com/storage/v1/b/' + bucketName + '/o/' + fixedTail;
}
return handler(event);
};
return makeCloudFunction(
{ provider, handler: correctMediaLink, resource: this.resource, eventType: 'object.change' });
{ provider, handler: handler, resource: this.resource, eventType: 'object.change' });
}
}

Expand Down