-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some mp3/mp4 media files show as Raw #18458
Conversation
Codecov Report
@@ Coverage Diff @@
## main #18458 +/- ##
==========================================
- Coverage 46.27% 46.27% -0.01%
==========================================
Files 842 842
Lines 121178 121184 +6
==========================================
- Hits 56075 56073 -2
- Misses 58292 58304 +12
+ Partials 6811 6807 -4
Continue to review full report at Codecov.
|
Should mp3/mp4 be viewed as normal file? IIRC Gitlab/Github still haves them under |
It depends on how you use it. |
You can use |
modules/setting/mime_type_map.go
Outdated
@@ -21,6 +24,7 @@ func newMimeTypeMap() { | |||
m := make(map[string]string, len(keys)) | |||
for _, key := range keys { | |||
m[strings.ToLower(key.Name())] = key.Value() | |||
_ = mime.AddExtensionType(key.Name(), key.Value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should ignore a error here.
modules/typesniffer/typesniffer.go
Outdated
func DetectContentTypeExtFirst(name string, readSeekerOrBytes interface{}) (SniffedType, error) { | ||
// we can merge `setting.MimeTypeMap` by mime.AddExtensionType() | ||
ct := mime.TypeByExtension(filepath.Ext(name)) | ||
if ct != "" && !strings.Contains(ct, "text/") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to change Contains -> HasPrefix?
modules/typesniffer/typesniffer.go
Outdated
if nil != err { | ||
return SniffedType{}, err | ||
} | ||
_, err = r.Seek(0, io.SeekStart) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is Seek
needed?
routers/common/repo.go
Outdated
@@ -63,6 +63,7 @@ func ServeData(ctx *context.Context, name string, size int64, reader io.Reader) | |||
// Google Chrome dislike commas in filenames, so let's change it to a space | |||
name = strings.ReplaceAll(name, ",", " ") | |||
|
|||
// st, err := typesniffer.DetectContentTypeExtFirst(name, buf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code is confusing and we shouldn't have it. If you want to retain it for future reference, it's better to add a sentence or two about it.
Build is failing. I'll fix this after another pull request #18448 is finished. |
// ServeBlob download a git.Blob | ||
func setCommonHeaders(ctx *context.Context, name string, data interface{}) error { | ||
// Google Chrome dislike commas in filenames, so let's change it to a space | ||
name = strings.ReplaceAll(name, ",", " ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed actually, from what I remember about this weird bug, if you quote the filename(as being done in this function) chromium won't error about it.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions. |
Please resolve the conflicts. |
from
to