diff --git a/README.md b/README.md index d730fa6..26a5893 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ AWS_SECRET_ACCESS_KEY | AWS `secret key` for API access. | AWS_API_ENDPOINT | The endpoint for AWS API for local development. | | - INDEX_DOCUMENT | Name of your index document. | | index.html DIRECTORY_LISTINGS | List files when a specified URL ends with /. | | false -DIRECTORY_LISTINGS_FORMAT | Configures directory listing to be `html` (spider parsable) | | - +DIRECTORY_LISTINGS_FORMAT | Configures directory listing to be `html` (spider parsable) or `shtml` (pip compatible) | | - HTTP_CACHE_CONTROL | Overrides S3's HTTP `Cache-Control` header. | | S3 Object metadata HTTP_EXPIRES | Overrides S3's HTTP `Expires` header. | | S3 Object metadata BASIC_AUTH_USER | User for basic authentication. | | - diff --git a/internal/controllers/s3.go b/internal/controllers/s3.go index 7243e7c..1e2c0ef 100644 --- a/internal/controllers/s3.go +++ b/internal/controllers/s3.go @@ -158,6 +158,12 @@ func s3listFiles(w http.ResponseWriter, r *http.Request, client service.AWS, buc fmt.Fprintln(w, toHTML(files, updatedAt)) return } + if strings.EqualFold(config.Config.DirListingFormat, "shtml") { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + fmt.Fprintln(w, toSimpleHTML(files)) + return + } + // Output as a JSON bytes, merr := json.Marshal(files) if merr != nil { @@ -210,3 +216,12 @@ func toHTML(files []string, updatedAt map[string]time.Time) string { } return html + "" } + +func toSimpleHTML(files []string) string { + + html := "" + for _, file := range files { + html += "" + file + "
" + } + return html + "" +} \ No newline at end of file