From 9330d8546fff5e0397b4eec1a24bf37277a6b745 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Wed, 6 Sep 2023 09:02:37 -0600 Subject: contrib/fs.GuessGopherItemType -> gopher.GuessItemType --- contrib/fs/gopher.go | 46 ++-------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) (limited to 'contrib') diff --git a/contrib/fs/gopher.go b/contrib/fs/gopher.go index e902b4e..0594730 100644 --- a/contrib/fs/gopher.go +++ b/contrib/fs/gopher.go @@ -3,8 +3,6 @@ package fs import ( "context" "io/fs" - "mime" - "path" "strings" "text/template" @@ -26,7 +24,7 @@ func GopherFileHandler(fileSystem fs.FS) sr.Handler { return nil } - return gopher.File(GuessGopherItemType(filepath), file) + return gopher.File(gopher.GuessItemType(filepath), file) }) } @@ -99,7 +97,7 @@ func GopherDirectoryListing(fileSystem fs.FS, tpl *template.Template) sr.Handler // - GuessItemType: return a gopher item type for a file based on its path/name. var GopherTemplateFunctions = template.FuncMap{ "GuessItemType": func(filepath string) string { - return string([]byte{byte(GuessGopherItemType(filepath))}) + return string([]byte{byte(gopher.GuessItemType(filepath))}) }, } @@ -128,43 +126,3 @@ i {{ $hostname }} {{ $port }} ), ), ) - -// GuessGopherItemType attempts to find the best gopher item type for a file based on its name. -func GuessGopherItemType(filepath string) sr.Status { - ext := path.Ext(filepath) - switch ext { - case ".gophermap": - return gopher.MenuType - case ".txt", ".gmi": - return gopher.TextFileType - case ".gif", ".png", ".jpg", ".jpeg": - return gopher.ImageFileType - case ".mp4", ".mov": - return gopher.MovieFileType - case ".mp3", ".aiff", ".aif", ".aac", ".ogg", ".flac", ".alac", ".wma": - return gopher.SoundFileType - case ".bmp": - return gopher.BitmapType - case ".doc", ".docx", ".odt": - return gopher.DocumentType - case ".html", ".htm": - return gopher.HTMLType - case ".rtf": - return gopher.RtfDocumentType - case ".wav": - return gopher.WavSoundFileType - case ".pdf": - return gopher.PdfDocumentType - case ".xml": - return gopher.XmlDocumentType - case ".": - return gopher.BinaryFileType - } - - mtype := mime.TypeByExtension(ext) - if strings.HasPrefix(mtype, "text/") { - return gopher.TextFileType - } - - return gopher.BinaryFileType -} -- cgit v1.2.3