Skip to content

Commit 9c30820

Browse files
authored
Remove unnecessary storage shim. (#102)
1 parent 6f88666 commit 9c30820

File tree

3 files changed

+4
-51
lines changed

3 files changed

+4
-51
lines changed

spec/providers/storage.spec.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -70,40 +70,6 @@ describe('storage.FunctionBuilder', () => {
7070
expect(() => storage.bucket('bad/bucket/format')).to.throw(Error);
7171
});
7272

73-
it('should correct nested media links using a single literal slash', () => {
74-
let cloudFunction = storage.object().onChange((event) => {
75-
return event.data.mediaLink;
76-
});
77-
let badMediaLinkEvent = {
78-
data: {
79-
mediaLink: 'https://www.googleapis.com/storage/v1/b/mybucket.appspot.com'
80-
+ '/o/nestedfolder/myobject.file?generation=12345&alt=media',
81-
},
82-
};
83-
return cloudFunction(badMediaLinkEvent).then(result => {
84-
expect(result).equals(
85-
'https://www.googleapis.com/storage/v1/b/mybucket.appspot.com'
86-
+ '/o/nestedfolder%2Fmyobject.file?generation=12345&alt=media');
87-
});
88-
});
89-
90-
it('should correct nested media links using multiple literal slashes', () => {
91-
let cloudFunction = storage.object().onChange((event) => {
92-
return event.data.mediaLink;
93-
});
94-
let badMediaLinkEvent = {
95-
data: {
96-
mediaLink: 'https://www.googleapis.com/storage/v1/b/mybucket.appspot.com'
97-
+ '/o/nestedfolder/anotherfolder/myobject.file?generation=12345&alt=media',
98-
},
99-
};
100-
return cloudFunction(badMediaLinkEvent).then(result => {
101-
expect(result).equals(
102-
'https://www.googleapis.com/storage/v1/b/mybucket.appspot.com'
103-
+ '/o/nestedfolder%2Fanotherfolder%2Fmyobject.file?generation=12345&alt=media');
104-
});
105-
});
106-
10773
it('should not mess with media links using non-literal slashes', () => {
10874
let cloudFunction = storage.object().onChange((event) => {
10975
return event.data.mediaLink;

src/providers/analytics.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export class AnalyticsEventBuilder {
6363
handler: (event: Event<AnalyticsEvent>) => PromiseLike<any> | any
6464
): CloudFunction<AnalyticsEvent> {
6565
const dataConstructor = (raw: Event<any>) => {
66+
if (raw.data instanceof AnalyticsEvent) {
67+
return raw.data;
68+
}
6669
return new AnalyticsEvent(raw.data);
6770
};
6871
return makeCloudFunction({

src/providers/storage.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ export class BucketBuilder {
5252
}
5353
}
5454

55-
// A RegExp that matches on a GCS media link that points at a _nested_ object (one that uses a path/with/slashes).
56-
const nestedMediaLinkRE = new RegExp('https://www.googleapis.com/storage/v1/b/([^/]+)/o/(.*)');
57-
5855
export class ObjectBuilder {
5956
/** @internal */
6057
constructor(private resource) { }
@@ -63,21 +60,8 @@ export class ObjectBuilder {
6360
* Handle any change to any object.
6461
*/
6562
onChange(handler: (event: Event<ObjectMetadata>) => PromiseLike<any> | any): CloudFunction<ObjectMetadata> {
66-
// This is a temporary shim to fix the 'mediaLink' for nested objects.
67-
// BUG(37962789): clean this up when backend fix for bug is deployed.
68-
let correctMediaLink = (event: Event<ObjectMetadata>) => {
69-
let deconstructedNestedLink = event.data.mediaLink.match(nestedMediaLinkRE);
70-
if (deconstructedNestedLink != null) {
71-
// The media link for a nested object uses an illegal URL (using literal slashes instead of "%2F".
72-
// Fix up the URL.
73-
let bucketName = deconstructedNestedLink[1];
74-
let fixedTail = deconstructedNestedLink[2].replace(/\//g, '%2F'); // "/\//g" means "all forward slashes".
75-
event.data.mediaLink = 'https://www.googleapis.com/storage/v1/b/' + bucketName + '/o/' + fixedTail;
76-
}
77-
return handler(event);
78-
};
7963
return makeCloudFunction(
80-
{ provider, handler: correctMediaLink, resource: this.resource, eventType: 'object.change' });
64+
{ provider, handler: handler, resource: this.resource, eventType: 'object.change' });
8165
}
8266
}
8367

0 commit comments

Comments
 (0)