diff options
author | FChannel <> | 2022-04-30 22:17:32 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 503a6637b8294aeb8e5e5546f8acbd2b3d6c4744 (patch) | |
tree | 56614d955df0d3e7284baa997bbf1a8dcc2e78f5 /util/util.go | |
parent | 1892327cee2c3fa1d3bea729bd08eb63c2189a96 (diff) |
first steps in posting connected. can make reply with no quote or quote OP
do not recommend working on this branch for the time being since
things are being moved around a lot
Diffstat (limited to 'util/util.go')
-rw-r--r-- | util/util.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/util/util.go b/util/util.go index 381db94..ade5eae 100644 --- a/util/util.go +++ b/util/util.go @@ -4,6 +4,8 @@ import ( "crypto/sha256" "encoding/hex" "fmt" + "mime/multipart" + "net/http" "os" "regexp" "strings" @@ -225,3 +227,27 @@ func CreateUniqueID(actor string) (string, error) { return newID, nil } + +func GetFileContentType(out multipart.File) (string, error) { + buffer := make([]byte, 512) + + _, err := out.Read(buffer) + if err != nil { + return "", err + } + + out.Seek(0, 0) + + contentType := http.DetectContentType(buffer) + + return contentType, nil +} + +func GetContentType(location string) string { + elements := strings.Split(location, ";") + if len(elements) > 0 { + return elements[0] + } else { + return location + } +} |