Skip to content

Commit 28cdd66

Browse files
committed
Update README.md (+4 squashed commits)
Squashed commits: [4ea2bef] Update index.html [8f5a7c2] Update index.html [94d44a4] Update index.html [35fe34f] Update README.md
1 parent 9b430fb commit 28cdd66

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Single HTML file to browse AWS S3 buckets
77
## Installation
88

99
#### Self-Hosted
10-
* Just download [`index.html`](https://raw.githubusercontent.com/qoomon/aws-s3-bucket-browser/master/index.html) and put at root level of S3 bucket.
11-
* Adjust [config](index.html#L8-L38) within `index.html` if needed, e.g.
10+
* Just download [`index.html`](index.html) and upload it to your bucket.
11+
* Adjust [config](index.html#L8-L37) within `index.html` if needed, e.g.
1212
```js
1313
const config = {
14-
title: 'S3 Bucket Browser',
14+
title: 'Bucket Browser',
1515
subtitle: 'made with ♥ by qoomon',
1616
logo: 'https://qoomon.github.io/aws-s3-bucket-browser/logo.png',
1717
favicon: 'https://qoomon.github.io/aws-s3-bucket-browser/favicon.ico',
@@ -20,20 +20,19 @@ Single HTML file to browse AWS S3 buckets
2020
bucketUrl: undefined,
2121
// If bucketUrl is undefined, this script tries to determine bucket Rest API URL from this file location itself.
2222
// This will only work for locations like these
23-
// * https://s3.eu-central-1.amazonaws.com/example-bucket/index.html
24-
// * http://example-bucket.s3-website-eu-west-1.amazonaws.com/index.html
25-
// * http://example-bucket.s3-website.eu-central-1.amazonaws.com/index.html
26-
// If bucketUrl is set manually, ensure this is the bucket Rest API URL.
27-
// e.g bucketUrl: "https://s3.BUCKET-REGION.amazonaws.com/BUCKET-NAME"
23+
// * https://s3.BUCKET-REGION.amazonaws.com/BUCKET-NAME/index.html
24+
// * http://BUCKET-NAME.s3-website-BUCKET-REGION.amazonaws.com/index.html
25+
// * https://storage.googleapis.com/BUCKET-NAME/index.html
26+
// If bucketUrl is set manually, ensure this is the bucket Rest API URL, e.g.
27+
// * https://s3.BUCKET-REGION.amazonaws.com/BUCKET-NAME
28+
// * https://storage.googleapis.com/BUCKET-NAME
2829
// The URL should return an XML document with <ListBucketResult> as root element.
2930
rootPrefix: undefined, // e.g. 'subfolder/'
3031
keyExcludePatterns: [/^index\.html$/],
3132
pageSize: 50,
3233

3334
bucketMaskUrl: undefined,
34-
// If bucketMaskUrl is set file urls will be changed from ${bucketUrl}/${s3_file} to ${bucketMaskUrl}/${s3_file}
35-
// bucketMaskUrl: undefined
36-
// => https://s3.eu-central-1.amazonaws.com/example-bucket/foo/bar.txt
35+
// If bucketMaskUrl is set file urls will be changed from ${bucketUrl}/${file} to ${bucketMaskUrl}/${file}
3736
// bucketMaskUrl: 'https://example.org'
3837
// => https://example.org/foo/bar.txt
3938
// bucketMaskUrl: document.location.origin

index.html

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<!-- S3 Bucket Explorer Version: 1.7.3 -->
1+
<!-- S3 Bucket Explorer Version: 1.8.0 -->
22

33
<!DOCTYPE html>
44
<html lang="en" style="overflow-y: auto;">
55

66
<head>
77
<script>
88
const config = {
9-
title: 'S3 Bucket Browser',
9+
title: 'Bucket Browser',
1010
subtitle: 'made with ♥ by qoomon',
1111
logo: 'https://qoomon.github.io/aws-s3-bucket-browser/logo.png',
1212
favicon: 'https://qoomon.github.io/aws-s3-bucket-browser/favicon.ico',
@@ -15,20 +15,19 @@
1515
bucketUrl: undefined,
1616
// If bucketUrl is undefined, this script tries to determine bucket Rest API URL from this file location itself.
1717
// 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
2324
// The URL should return an XML document with <ListBucketResult> as root element.
2425
rootPrefix: undefined, // e.g. 'subfolder/'
2526
keyExcludePatterns: [/^index\.html$/],
2627
pageSize: 50,
2728

2829
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}
3231
// bucketMaskUrl: 'https://example.org'
3332
// => https://example.org/foo/bar.txt
3433
// bucketMaskUrl: document.location.origin
@@ -277,30 +276,48 @@ <h2 class="subtitle">{{config.subtitle}}</h2>
277276

278277
// try adjusting bucket url to bucket rest api endpoint
279278
let match
279+
let type
280+
280281
if (!match) {
282+
type = 'AWS'
281283
// check for urls like https://s3.eu-central-1.amazonaws.com/example-bucket/index.html
282284
match = config.bucketUrl.match(/(?<protocol>[^:]+):\/\/s3\.(?<region>[^.]+)\.amazonaws.com\/(?<name>[^/]+)/)
283285
}
284286
if (!match) {
287+
type = 'AWS'
285288
// check for urls like http://example-bucket.s3-website-eu-west-1.amazonaws.com/index.html
286289
match = config.bucketUrl.match(/(?<protocol>[^:]+):\/\/(?<name>[^.]+)\.s3-website-(?<region>[^.]+)\.amazonaws\.com/)
287290
}
288291
if (!match) {
292+
type = 'AWS'
289293
// check for urls like http://example-bucket.s3-website.eu-central-1.amazonaws.com/index.html
290294
match = config.bucketUrl.match(/(?<protocol>[^:]+):\/\/(?<name>[^.]+)\.s3-website\.(?<region>[^.]+)\.amazonaws\.com/)
291295
}
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+
292302
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+
}
294311
}
295-
296-
console.log("S3 Bucket REST API: " + config.bucketUrl)
312+
313+
console.log("Bucket REST API: " + config.bucketUrl)
297314

298315
config.rootPrefix = config.rootPrefix || ''
299316
if (config.rootPrefix) {
300317
if (!config.rootPrefix.endsWith('/')) {
301318
config.rootPrefix += '/'
302319
}
303-
console.log("S3 Bucket Root Prefix: " + config.rootPrefix)
320+
console.log("Bucket Root Prefix: " + config.rootPrefix)
304321
}
305322

306323
document.title = config.title

0 commit comments

Comments
 (0)