summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/fs/gopher.go46
1 files changed, 2 insertions, 44 deletions
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
-}