MM-57512: Disable content extraction during import (#26619)
https://mattermost.atlassian.net/browse/MM-57512 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fc8e537288
Коммит
273d4432b4
@@ -1168,7 +1168,7 @@ func (a *App) importReaction(data *imports.ReactionImportData, post *model.Post)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, post *model.Post, teamID string) *model.AppError {
|
||||
func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, post *model.Post, teamID string, extractContent bool) *model.AppError {
|
||||
var err *model.AppError
|
||||
usernames := []string{}
|
||||
for _, replyData := range data {
|
||||
@@ -1227,7 +1227,7 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po
|
||||
reply.EditAt = *replyData.EditAt
|
||||
}
|
||||
|
||||
fileIDs := a.uploadAttachments(rctx, replyData.Attachments, reply, teamID)
|
||||
fileIDs := a.uploadAttachments(rctx, replyData.Attachments, reply, teamID, extractContent)
|
||||
for _, fileID := range reply.FileIds {
|
||||
if _, ok := fileIDs[fileID]; !ok {
|
||||
a.Srv().Store().FileInfo().PermanentDelete(rctx, fileID)
|
||||
@@ -1272,7 +1272,7 @@ func (a *App) importReplies(rctx request.CTX, data []imports.ReplyImportData, po
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) importAttachment(rctx request.CTX, data *imports.AttachmentImportData, post *model.Post, teamID string) (*model.FileInfo, *model.AppError) {
|
||||
func (a *App) importAttachment(rctx request.CTX, data *imports.AttachmentImportData, post *model.Post, teamID string, extractContent bool) (*model.FileInfo, *model.AppError) {
|
||||
var (
|
||||
name string
|
||||
file io.Reader
|
||||
@@ -1338,7 +1338,7 @@ func (a *App) importAttachment(rctx request.CTX, data *imports.AttachmentImportD
|
||||
|
||||
rctx.Logger().Info("Uploading file with name", mlog.String("file_name", name))
|
||||
|
||||
fileInfo, appErr := a.DoUploadFile(rctx, timestamp, teamID, post.ChannelId, post.UserId, name, fileData)
|
||||
fileInfo, appErr := a.DoUploadFile(rctx, timestamp, teamID, post.ChannelId, post.UserId, name, fileData, extractContent)
|
||||
if appErr != nil {
|
||||
rctx.Logger().Error("Failed to upload file", mlog.Err(appErr), mlog.String("file_name", name))
|
||||
return nil, appErr
|
||||
@@ -1433,7 +1433,7 @@ func getPostStrID(post *model.Post) string {
|
||||
|
||||
// importMultiplePostLines will return an error and the line that
|
||||
// caused it whenever possible
|
||||
func (a *App) importMultiplePostLines(rctx request.CTX, lines []imports.LineImportWorkerData, dryRun bool) (int, *model.AppError) {
|
||||
func (a *App) importMultiplePostLines(rctx request.CTX, lines []imports.LineImportWorkerData, dryRun, extractContent bool) (int, *model.AppError) {
|
||||
if len(lines) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -1530,7 +1530,7 @@ func (a *App) importMultiplePostLines(rctx request.CTX, lines []imports.LineImpo
|
||||
post.IsPinned = *line.Post.IsPinned
|
||||
}
|
||||
|
||||
fileIDs := a.uploadAttachments(rctx, line.Post.Attachments, post, team.Id)
|
||||
fileIDs := a.uploadAttachments(rctx, line.Post.Attachments, post, team.Id, extractContent)
|
||||
for _, fileID := range post.FileIds {
|
||||
if _, ok := fileIDs[fileID]; !ok {
|
||||
a.Srv().Store().FileInfo().PermanentDelete(rctx, fileID)
|
||||
@@ -1618,7 +1618,7 @@ func (a *App) importMultiplePostLines(rctx request.CTX, lines []imports.LineImpo
|
||||
}
|
||||
|
||||
if postWithData.postData.Replies != nil && len(*postWithData.postData.Replies) > 0 {
|
||||
err := a.importReplies(rctx, *postWithData.postData.Replies, postWithData.post, postWithData.team.Id)
|
||||
err := a.importReplies(rctx, *postWithData.postData.Replies, postWithData.post, postWithData.team.Id, extractContent)
|
||||
if err != nil {
|
||||
return postWithData.lineNumber, err
|
||||
}
|
||||
@@ -1629,14 +1629,14 @@ func (a *App) importMultiplePostLines(rctx request.CTX, lines []imports.LineImpo
|
||||
}
|
||||
|
||||
// uploadAttachments imports new attachments and returns current attachments of the post as a map
|
||||
func (a *App) uploadAttachments(rctx request.CTX, attachments *[]imports.AttachmentImportData, post *model.Post, teamID string) map[string]bool {
|
||||
func (a *App) uploadAttachments(rctx request.CTX, attachments *[]imports.AttachmentImportData, post *model.Post, teamID string, extractContent bool) map[string]bool {
|
||||
if attachments == nil {
|
||||
return nil
|
||||
}
|
||||
fileIDs := make(map[string]bool)
|
||||
for _, attachment := range *attachments {
|
||||
attachment := attachment
|
||||
fileInfo, err := a.importAttachment(rctx, &attachment, post, teamID)
|
||||
fileInfo, err := a.importAttachment(rctx, &attachment, post, teamID, extractContent)
|
||||
if err != nil {
|
||||
if attachment.Path != nil {
|
||||
rctx.Logger().Warn(
|
||||
@@ -1742,7 +1742,7 @@ func (a *App) importDirectChannel(rctx request.CTX, data *imports.DirectChannelI
|
||||
|
||||
// importMultipleDirectPostLines will return an error and the line
|
||||
// that caused it whenever possible
|
||||
func (a *App) importMultipleDirectPostLines(rctx request.CTX, lines []imports.LineImportWorkerData, dryRun bool) (int, *model.AppError) {
|
||||
func (a *App) importMultipleDirectPostLines(rctx request.CTX, lines []imports.LineImportWorkerData, dryRun, extractContent bool) (int, *model.AppError) {
|
||||
if len(lines) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -1843,7 +1843,7 @@ func (a *App) importMultipleDirectPostLines(rctx request.CTX, lines []imports.Li
|
||||
post.IsPinned = *line.DirectPost.IsPinned
|
||||
}
|
||||
|
||||
fileIDs := a.uploadAttachments(rctx, line.DirectPost.Attachments, post, "noteam")
|
||||
fileIDs := a.uploadAttachments(rctx, line.DirectPost.Attachments, post, "noteam", extractContent)
|
||||
for _, fileID := range post.FileIds {
|
||||
if _, ok := fileIDs[fileID]; !ok {
|
||||
a.Srv().Store().FileInfo().PermanentDelete(rctx, fileID)
|
||||
@@ -1929,7 +1929,7 @@ func (a *App) importMultipleDirectPostLines(rctx request.CTX, lines []imports.Li
|
||||
}
|
||||
|
||||
if postWithData.directPostData.Replies != nil {
|
||||
if err := a.importReplies(rctx, *postWithData.directPostData.Replies, postWithData.post, "noteam"); err != nil {
|
||||
if err := a.importReplies(rctx, *postWithData.directPostData.Replies, postWithData.post, "noteam", extractContent); err != nil {
|
||||
return postWithData.lineNumber, err
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user