mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-06-25 22:08:03 +02:00
Preview URL
This commit is contained in:
parent
38788bb2e9
commit
2930c4ff62
5 changed files with 63 additions and 38 deletions
util
15
util/util.go
15
util/util.go
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -163,3 +164,17 @@ func ExpandHome(path string) string {
|
|||
func ShortTopicURL(s string) string {
|
||||
return strings.TrimPrefix(strings.TrimPrefix(s, "https://"), "http://")
|
||||
}
|
||||
|
||||
// ExtensionByType is a wrapper around mime.ExtensionByType with a few sensible corrections
|
||||
func ExtensionByType(contentType string) string {
|
||||
switch contentType {
|
||||
case "image/jpeg":
|
||||
return ".jpg"
|
||||
default:
|
||||
exts, err := mime.ExtensionsByType(contentType)
|
||||
if err == nil && len(exts) > 0 {
|
||||
return exts[0]
|
||||
}
|
||||
return ".bin"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue