Skip to content

Commit e1d0158

Browse files
committed
refactor typesniffer functions
1 parent 5fc9c00 commit e1d0158

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

modules/typesniffer/typesniffer.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ func (ct SniffedType) IsRepresentableAsText() bool {
7070
return ct.IsText() || ct.IsSvgImage()
7171
}
7272

73-
// IsBrowsableType returns whether the file content can be displayed in a browser
74-
// note, this excludes text types
75-
func (ct SniffedType) IsBrowsableType() bool {
73+
// IsBrowsableType returns whether a non-text type can be displayed in a browser
74+
func (ct SniffedType) IsBrowsableBinaryType() bool {
7675
return ct.IsImage() || ct.IsSvgImage() || ct.IsPDF() || ct.IsVideo() || ct.IsAudio()
7776
}
7877

79-
// GetContentType returns the contentType
80-
func (ct SniffedType) GetContentType() string {
81-
return ct.contentType
78+
// GetMimeType returns the mime type
79+
func (ct SniffedType) GetMimeType() string {
80+
return ct.contentType[:strings.Index(ct.contentType, ";")]
8281
}
8382

8483
// DetectContentType extends http.DetectContentType with more content types. Defaults to text/unknown if input is empty.

routers/common/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
7373
}
7474

7575
if mimeType == "" {
76-
if st.IsBrowsableType() {
77-
mimeType = st.GetContentType()
76+
if st.IsBrowsableBinaryType() {
77+
mimeType = st.GetMimeType()
7878
} else if isPlain {
7979
mimeType = "text/plain"
8080
} else {

0 commit comments

Comments
 (0)