|
1 | 1 | /**
|
2 | 2 | * @license
|
3 |
| - * Copyright 2017 Google Inc. |
| 3 | + * Copyright 2017 Google LLC |
4 | 4 | *
|
5 | 5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | 6 | * you may not use this file except in compliance with the License.
|
@@ -76,23 +76,42 @@ export class Location {
|
76 | 76 | }
|
77 | 77 | }
|
78 | 78 | const gsPath = '(/(.*))?$';
|
79 |
| - const path = '(/([^?#]*).*)?$'; |
80 | 79 | const gsRegex = new RegExp('^gs://' + bucketDomain + gsPath, 'i');
|
81 | 80 | const gsIndices = { bucket: 1, path: 3 };
|
82 | 81 |
|
83 | 82 | function httpModify(loc: Location): void {
|
84 | 83 | loc.path_ = decodeURIComponent(loc.path);
|
85 | 84 | }
|
86 | 85 | const version = 'v[A-Za-z0-9_]+';
|
87 |
| - const hostRegex = DEFAULT_HOST.replace(/[.]/g, '\\.'); |
88 |
| - const httpRegex = new RegExp( |
89 |
| - `^https?://${hostRegex}/${version}/b/${bucketDomain}/o${path}`, |
| 86 | + const firebaseStorageHost = DEFAULT_HOST.replace(/[.]/g, '\\.'); |
| 87 | + const firebaseStoragePath = '(/([^?#]*).*)?$'; |
| 88 | + const firebaseStorageRegExp = new RegExp( |
| 89 | + `^https?://${firebaseStorageHost}/${version}/b/${bucketDomain}/o${firebaseStoragePath}`, |
90 | 90 | 'i'
|
91 | 91 | );
|
92 |
| - const httpIndices = { bucket: 1, path: 3 }; |
| 92 | + const firebaseStorageIndices = { bucket: 1, path: 3 }; |
| 93 | + |
| 94 | + const cloudStorageHost = |
| 95 | + '(?:storage.googleapis.com|storage.cloud.google.com)'; |
| 96 | + const cloudStoragePath = '([^?#]*)'; |
| 97 | + const cloudStorageRegExp = new RegExp( |
| 98 | + `^https?://${cloudStorageHost}/${bucketDomain}/${cloudStoragePath}`, |
| 99 | + 'i' |
| 100 | + ); |
| 101 | + const cloudStorageIndices = { bucket: 1, path: 2 }; |
| 102 | + |
93 | 103 | const groups = [
|
94 | 104 | { regex: gsRegex, indices: gsIndices, postModify: gsModify },
|
95 |
| - { regex: httpRegex, indices: httpIndices, postModify: httpModify } |
| 105 | + { |
| 106 | + regex: firebaseStorageRegExp, |
| 107 | + indices: firebaseStorageIndices, |
| 108 | + postModify: httpModify |
| 109 | + }, |
| 110 | + { |
| 111 | + regex: cloudStorageRegExp, |
| 112 | + indices: cloudStorageIndices, |
| 113 | + postModify: httpModify |
| 114 | + } |
96 | 115 | ];
|
97 | 116 | for (let i = 0; i < groups.length; i++) {
|
98 | 117 | const group = groups[i];
|
|
0 commit comments