MM-68439 Centralize filename handling for FileInfo (#36223) (#36255)

Automatic Merge
Этот коммит содержится в:
Mattermost Build
2026-04-24 09:17:57 +02:00
коммит произвёл GitHub
родитель e5593b6489
Коммит 61d68d2d6e
5 изменённых файлов: 173 добавлений и 2 удалений

Просмотреть файл

@@ -23,6 +23,11 @@ import (
const minFirstPartSize = 5 * 1024 * 1024 // 5MB
func (a *App) genFileInfoFromReader(name string, file io.ReadSeeker, size int64) (*model.FileInfo, error) {
name = model.SanitizeFilename(name)
if name == "" {
return nil, model.NewAppError("genFileInfoFromReader", "app.upload.gen_file_info.invalid_filename.app_error", nil, "", http.StatusBadRequest)
}
ext := strings.ToLower(filepath.Ext(name))
info := &model.FileInfo{
@@ -276,7 +281,13 @@ func (a *App) UploadData(c request.CTX, us *model.UploadSession, rd io.Reader) (
info, genErr := a.genFileInfoFromReader(us.Filename, file, us.FileSize)
file.Close()
if genErr != nil {
return nil, model.NewAppError("UploadData", "app.upload.upload_data.gen_info.app_error", nil, "", http.StatusInternalServerError).Wrap(genErr)
var appErr *model.AppError
switch {
case errors.As(genErr, &appErr):
return nil, appErr
default:
return nil, model.NewAppError("UploadData", "app.upload.upload_data.gen_info.app_error", nil, "", http.StatusInternalServerError).Wrap(genErr)
}
}
info.CreatorId = us.UserId