add some common code file extensions as text/plain

This commit is contained in:
ari melody 2026-03-18 09:48:45 +00:00
parent d40dec3566
commit 56d8733a40
Signed by: ari
GPG key ID: CF99829C92678188

View file

@ -42,6 +42,16 @@ type (
}
)
var mimeTypes = map[string]string {
".go": "text/plain",
".rs": "text/plain",
".c": "text/plain",
".h": "text/plain",
".cpp": "text/plain",
".hpp": "text/plain",
".java": "text/plain",
}
//go:embed dir.html
var dirTemplateSrc string
var dirTemplate = template.Must(template.New("dir").Parse(dirTemplateSrc))
@ -83,8 +93,12 @@ func Handler(app *AppState) http.HandlerFunc {
mimeType := "application/octet-stream"
extPos := strings.LastIndex(info.Name(), ".")
ext := string(info.Name()[strings.LastIndex(info.Name(), "."):])
fmt.Println(ext)
if extPos != -1 {
if m := mime.TypeByExtension(info.Name()[extPos:]); m != "" {
if m := mime.TypeByExtension(ext); m != "" {
mimeType = m
} else if m, ok := mimeTypes[ext]; ok {
mimeType = m
}
}