From c6941f1336b30d3e7895e6b14bd53515f12ff4d7 Mon Sep 17 00:00:00 2001 From: Seednode Date: Mon, 9 Oct 2023 09:47:17 -0500 Subject: [PATCH] Rename mime types to media types, change endpoints accordingly --- README.md | 2 +- cmd/info.go | 20 ++++++++++---------- cmd/root.go | 2 +- cmd/web.go | 6 +++--- types/audio/audio.go | 2 +- types/code/code.go | 2 +- types/flash/flash.go | 2 +- types/images/images.go | 2 +- types/text/text.go | 2 +- types/types.go | 14 +++++++------- types/video/video.go | 2 +- 11 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 1e0f492..467973c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ If `--page-length` is also set, these can be viewed in paginated form by appendi This can prove useful when confirming whether the index is generated successfully, or whether a given file is in the index. -The remaining four endpoints—`/available_extensions`, `/enabled_extensions`, `/available_mime_types` and `/enabled_mime_types`—return information about the registered file types. +The remaining four endpoints—`/available/extensions`, `/enabled/extensions`, `/available/types` and `/enabled/types`—return information about the registered file types. ## Refresh If the `--refresh` flag is passed and a positive-value `refresh=` query parameter is provided, the page will reload after that interval. diff --git a/cmd/info.go b/cmd/info.go index e89dcce..5bba3c5 100644 --- a/cmd/info.go +++ b/cmd/info.go @@ -255,19 +255,19 @@ func serveEnabledExtensions(formats types.Types, errorChannel chan<- error) http } } -func serveAvailableMimeTypes(errorChannel chan<- error) httprouter.Handle { +func serveAvailableMediaTypes(errorChannel chan<- error) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { w.Header().Set("Content-Type", "text/plain") startTime := time.Now() - written, err := w.Write([]byte(types.SupportedFormats.GetMimeTypes())) + written, err := w.Write([]byte(types.SupportedFormats.GetMediaTypes())) if err != nil { errorChannel <- err } if Verbose { - fmt.Printf("%s | SERVE: Available MIME type list (%s) to %s in %s\n", + fmt.Printf("%s | SERVE: Available media type list (%s) to %s in %s\n", startTime.Format(logDate), humanReadableSize(written), realIP(r), @@ -277,19 +277,19 @@ func serveAvailableMimeTypes(errorChannel chan<- error) httprouter.Handle { } } -func serveEnabledMimeTypes(formats types.Types, errorChannel chan<- error) httprouter.Handle { +func serveEnabledMediaTypes(formats types.Types, errorChannel chan<- error) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { w.Header().Set("Content-Type", "text/plain") startTime := time.Now() - written, err := w.Write([]byte(formats.GetMimeTypes())) + written, err := w.Write([]byte(formats.GetMediaTypes())) if err != nil { errorChannel <- err } if Verbose { - fmt.Printf("%s | SERVE: Registered MIME type list (%s) to %s in %s\n", + fmt.Printf("%s | SERVE: Registered media type list (%s) to %s in %s\n", startTime.Format(logDate), humanReadableSize(written), realIP(r), @@ -312,8 +312,8 @@ func registerInfoHandlers(mux *httprouter.Router, args []string, index *fileInde } } - registerHandler(mux, Prefix+"/available_extensions", serveAvailableExtensions(errorChannel)) - registerHandler(mux, Prefix+"/enabled_extensions", serveEnabledExtensions(formats, errorChannel)) - registerHandler(mux, Prefix+"/available_mime_types", serveAvailableMimeTypes(errorChannel)) - registerHandler(mux, Prefix+"/enabled_mime_types", serveEnabledMimeTypes(formats, errorChannel)) + registerHandler(mux, Prefix+"/available/extensions", serveAvailableExtensions(errorChannel)) + registerHandler(mux, Prefix+"/enabled/extensions", serveEnabledExtensions(formats, errorChannel)) + registerHandler(mux, Prefix+"/available/types", serveAvailableMediaTypes(errorChannel)) + registerHandler(mux, Prefix+"/enabled/types", serveEnabledMediaTypes(formats, errorChannel)) } diff --git a/cmd/root.go b/cmd/root.go index 8f5393c..101f412 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,7 +12,7 @@ import ( ) const ( - ReleaseVersion string = "2.8.1" + ReleaseVersion string = "2.9.0" ) var ( diff --git a/cmd/web.go b/cmd/web.go index bb27901..4affb4f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -297,7 +297,7 @@ func serveMedia(paths []string, regexes *regexes, index *fileIndex, formats type return } - mimeType := format.MimeType(path) + mediaType := format.MediaType(path) fileUri := Prefix + generateFileUri(path) @@ -314,7 +314,7 @@ func serveMedia(paths []string, regexes *regexes, index *fileIndex, formats type htmlBody.WriteString(faviconHtml) htmlBody.WriteString(fmt.Sprintf(``, format.Css())) - title, err := format.Title(rootUrl, fileUri, path, fileName, Prefix, mimeType) + title, err := format.Title(rootUrl, fileUri, path, fileName, Prefix, mediaType) if err != nil { errorChannel <- err @@ -328,7 +328,7 @@ func serveMedia(paths []string, regexes *regexes, index *fileIndex, formats type htmlBody.WriteString(refreshFunction(rootUrl, refreshTimer)) } - body, err := format.Body(rootUrl, fileUri, path, fileName, Prefix, mimeType) + body, err := format.Body(rootUrl, fileUri, path, fileName, Prefix, mediaType) if err != nil { errorChannel <- err diff --git a/types/audio/audio.go b/types/audio/audio.go index a6b7c5b..0273c51 100644 --- a/types/audio/audio.go +++ b/types/audio/audio.go @@ -44,7 +44,7 @@ func (t Format) Extensions() map[string]string { } } -func (t Format) MimeType(extension string) string { +func (t Format) MediaType(extension string) string { extensions := t.Extensions() value, exists := extensions[extension] diff --git a/types/code/code.go b/types/code/code.go index 3171420..2941a6e 100644 --- a/types/code/code.go +++ b/types/code/code.go @@ -210,7 +210,7 @@ func (t Format) Extensions() map[string]string { } } -func (t Format) MimeType(extension string) string { +func (t Format) MediaType(extension string) string { extensions := t.Extensions() value, exists := extensions[extension] diff --git a/types/flash/flash.go b/types/flash/flash.go index b434320..c028e21 100644 --- a/types/flash/flash.go +++ b/types/flash/flash.go @@ -43,7 +43,7 @@ func (t Format) Extensions() map[string]string { } } -func (t Format) MimeType(extension string) string { +func (t Format) MediaType(extension string) string { extensions := t.Extensions() value, exists := extensions[extension] diff --git a/types/images/images.go b/types/images/images.go index 93a69a0..59766cb 100644 --- a/types/images/images.go +++ b/types/images/images.go @@ -97,7 +97,7 @@ func (t Format) Validate(filePath string) bool { return true } -func (t Format) MimeType(extension string) string { +func (t Format) MediaType(extension string) string { extensions := t.Extensions() value, exists := extensions[extension] diff --git a/types/text/text.go b/types/text/text.go index cbcf780..3c6a993 100644 --- a/types/text/text.go +++ b/types/text/text.go @@ -51,7 +51,7 @@ func (t Format) Extensions() map[string]string { } } -func (t Format) MimeType(extension string) string { +func (t Format) MediaType(extension string) string { extensions := t.Extensions() value, exists := extensions[extension] diff --git a/types/types.go b/types/types.go index b2bc101..366dfb0 100644 --- a/types/types.go +++ b/types/types.go @@ -31,7 +31,7 @@ type Type interface { // Given a file extension, returns the corresponding MIME type, // if one exists. Otherwise, returns an empty string. - MimeType(extension string) string + MediaType(extension string) string // Optional function used to validate whether a given file matches this format. // If no validation checks are needed, this function should always return true. @@ -92,23 +92,23 @@ func (t Types) GetExtensions() string { return output.String() } -func (t Types) GetMimeTypes() string { +func (t Types) GetMediaTypes() string { var output strings.Builder - var mimeTypes []string + var mediaTypes []string for _, j := range t { extensions := j.Extensions() for _, v := range extensions { - mimeTypes = append(mimeTypes, v) + mediaTypes = append(mediaTypes, v) } } - mimeTypes = removeDuplicateStr(mimeTypes) + mediaTypes = removeDuplicateStr(mediaTypes) - slices.Sort(mimeTypes) + slices.Sort(mediaTypes) - for _, v := range mimeTypes { + for _, v := range mediaTypes { output.WriteString(v + "\n") } diff --git a/types/video/video.go b/types/video/video.go index 823b652..fc3874c 100644 --- a/types/video/video.go +++ b/types/video/video.go @@ -48,7 +48,7 @@ func (t Format) Extensions() map[string]string { } } -func (t Format) MimeType(path string) string { +func (t Format) MediaType(path string) string { extensions := t.Extensions() extension := filepath.Ext(path)