|
1 | | -<!-- S3 Bucket Explorer Version: 1.7.3 --> |
| 1 | +<!-- S3 Bucket Explorer Version: 1.8.0 --> |
2 | 2 |
|
3 | 3 | <!DOCTYPE html> |
4 | 4 | <html lang="en" style="overflow-y: auto;"> |
5 | 5 |
|
6 | 6 | <head> |
7 | 7 | <script> |
8 | 8 | const config = { |
9 | | - title: 'S3 Bucket Browser', |
| 9 | + title: 'Bucket Browser', |
10 | 10 | subtitle: 'made with ♥ by qoomon', |
11 | 11 | logo: 'https://qoomon.github.io/aws-s3-bucket-browser/logo.png', |
12 | 12 | favicon: 'https://qoomon.github.io/aws-s3-bucket-browser/favicon.ico', |
|
15 | 15 | bucketUrl: undefined, |
16 | 16 | // If bucketUrl is undefined, this script tries to determine bucket Rest API URL from this file location itself. |
17 | 17 | // This will only work for locations like these |
18 | | - // * https://s3.eu-central-1.amazonaws.com/example-bucket/index.html |
19 | | - // * http://example-bucket.s3-website-eu-west-1.amazonaws.com/index.html |
20 | | - // * http://example-bucket.s3-website.eu-central-1.amazonaws.com/index.html |
21 | | - // If bucketUrl is set manually, ensure this is the bucket Rest API URL. |
22 | | - // e.g bucketUrl: "https://s3.BUCKET-REGION.amazonaws.com/BUCKET-NAME" |
| 18 | + // * https://s3.BUCKET-REGION.amazonaws.com/BUCKET-NAME/index.html |
| 19 | + // * http://BUCKET-NAME.s3-website-BUCKET-REGION.amazonaws.com/index.html |
| 20 | + // * https://storage.googleapis.com/BUCKET-NAME/index.html |
| 21 | + // If bucketUrl is set manually, ensure this is the bucket Rest API URL, e.g. |
| 22 | + // * https://s3.BUCKET-REGION.amazonaws.com/BUCKET-NAME |
| 23 | + // * https://storage.googleapis.com/BUCKET-NAME |
23 | 24 | // The URL should return an XML document with <ListBucketResult> as root element. |
24 | 25 | rootPrefix: undefined, // e.g. 'subfolder/' |
25 | 26 | keyExcludePatterns: [/^index\.html$/], |
26 | 27 | pageSize: 50, |
27 | 28 |
|
28 | 29 | bucketMaskUrl: undefined, |
29 | | - // If bucketMaskUrl is set file urls will be changed from ${bucketUrl}/${s3_file} to ${bucketMaskUrl}/${s3_file} |
30 | | - // bucketMaskUrl: undefined |
31 | | - // => https://s3.eu-central-1.amazonaws.com/example-bucket/foo/bar.txt |
| 30 | + // If bucketMaskUrl is set file urls will be changed from ${bucketUrl}/${file} to ${bucketMaskUrl}/${file} |
32 | 31 | // bucketMaskUrl: 'https://example.org' |
33 | 32 | // => https://example.org/foo/bar.txt |
34 | 33 | // bucketMaskUrl: document.location.origin |
@@ -277,30 +276,48 @@ <h2 class="subtitle">{{config.subtitle}}</h2> |
277 | 276 |
|
278 | 277 | // try adjusting bucket url to bucket rest api endpoint |
279 | 278 | let match |
| 279 | + let type |
| 280 | + |
280 | 281 | if (!match) { |
| 282 | + type = 'AWS' |
281 | 283 | // check for urls like https://s3.eu-central-1.amazonaws.com/example-bucket/index.html |
282 | 284 | match = config.bucketUrl.match(/(?<protocol>[^:]+):\/\/s3\.(?<region>[^.]+)\.amazonaws.com\/(?<name>[^/]+)/) |
283 | 285 | } |
284 | 286 | if (!match) { |
| 287 | + type = 'AWS' |
285 | 288 | // check for urls like http://example-bucket.s3-website-eu-west-1.amazonaws.com/index.html |
286 | 289 | match = config.bucketUrl.match(/(?<protocol>[^:]+):\/\/(?<name>[^.]+)\.s3-website-(?<region>[^.]+)\.amazonaws\.com/) |
287 | 290 | } |
288 | 291 | if (!match) { |
| 292 | + type = 'AWS' |
289 | 293 | // check for urls like http://example-bucket.s3-website.eu-central-1.amazonaws.com/index.html |
290 | 294 | match = config.bucketUrl.match(/(?<protocol>[^:]+):\/\/(?<name>[^.]+)\.s3-website\.(?<region>[^.]+)\.amazonaws\.com/) |
291 | 295 | } |
| 296 | + if (!match) { |
| 297 | + type = 'GCP' |
| 298 | + // check for urls like https://storage.googleapis.com/example-bucket/index.html |
| 299 | + match = config.bucketUrl.match(/(?<protocol>[^:]+):\/\/storage\.googleapis\.com\/(?<name>[^.]+)/) |
| 300 | + } |
| 301 | + |
292 | 302 | if (match) { |
293 | | - config.bucketUrl = `${match.groups.protocol}://s3.${match.groups.region}.amazonaws.com/${match.groups.name}` |
| 303 | + switch (type) { |
| 304 | + case 'AWS': |
| 305 | + config.bucketUrl = `${match.groups.protocol}://s3.${match.groups.region}.amazonaws.com/${match.groups.name}` |
| 306 | + break; |
| 307 | + case 'GCP': |
| 308 | + config.bucketUrl = `${match.groups.protocol}://storage.googleapis.com/${match.groups.name}` |
| 309 | + break; |
| 310 | + } |
294 | 311 | } |
295 | | - |
296 | | - console.log("S3 Bucket REST API: " + config.bucketUrl) |
| 312 | + |
| 313 | + console.log("Bucket REST API: " + config.bucketUrl) |
297 | 314 |
|
298 | 315 | config.rootPrefix = config.rootPrefix || '' |
299 | 316 | if (config.rootPrefix) { |
300 | 317 | if (!config.rootPrefix.endsWith('/')) { |
301 | 318 | config.rootPrefix += '/' |
302 | 319 | } |
303 | | - console.log("S3 Bucket Root Prefix: " + config.rootPrefix) |
| 320 | + console.log("Bucket Root Prefix: " + config.rootPrefix) |
304 | 321 | } |
305 | 322 |
|
306 | 323 | document.title = config.title |
|
0 commit comments