1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-25 22:08:03 +02:00

Preview URL

This commit is contained in:
Philipp Heckel 2022-01-04 19:45:29 +01:00
parent 38788bb2e9
commit 2930c4ff62
5 changed files with 63 additions and 38 deletions

View file

@ -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"
}
}