fix mime type checking, write our own file extension fetcher

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
development
kim (grufwub) 4 years ago
parent ee92133c47
commit 39aac0eac8

@ -6,4 +6,4 @@ import "syscall"
// Temporary check on Linux to ensure
// correct Go version being used
var _ = syscall.AllThreadsSyscall
var _ = syscall.AllThreadsSyscall

@ -21,7 +21,7 @@ func SplitBy(input, delim string) (string, string) {
return input[:index], input[index+len(delim):]
}
// SplitBy takes an input string and a delimiter, returning resulting two string from split with the delim at beginning of 2nd
// SplitByBefore takes an input string and a delimiter, returning resulting two string from split with the delim at beginning of 2nd
func SplitByBefore(input, delim string) (string, string) {
index := strings.Index(input, delim)
if index == -1 {
@ -38,3 +38,17 @@ func SplitByLast(input, delim string) (string, string) {
}
return input[:index], input[index+len(delim):]
}
// FileExt returns the file extension of a file with a supplied path, doesn't include '.'
func FileExt(path string) string {
i := len(path) - 1
for ; i >= 0; i-- {
switch path[i] {
case '/':
return ""
case '.':
return path[i+1:]
}
}
return ""
}

@ -2,7 +2,6 @@ package gemini
import (
"gophi/core"
"path"
)
const gemMimeType = "text/gemini"
@ -14,7 +13,7 @@ func getFileStatusMeta(p *core.Path) string {
}
// Get file extension
ext := path.Ext(p.Relative())
ext := core.FileExt(p.Relative())
// Try get the mime type, or use default unknown (application octet-stream)
mimeType, ok := mimeTypes[ext]

Loading…
Cancel
Save