MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
66fc096768
Коммит
17523fa5d9
68
app/file.go
68
app/file.go
@@ -185,7 +185,7 @@ func (a *App) findTeamIdForFilename(post *model.Post, id, filename string) strin
|
||||
name, _ := url.QueryUnescape(filename)
|
||||
|
||||
// This post is in a direct channel so we need to figure out what team the files are stored under.
|
||||
teams, err := a.Srv.Store.Team().GetTeamsByUserId(post.UserId)
|
||||
teams, err := a.Srv().Store.Team().GetTeamsByUserId(post.UserId)
|
||||
if err != nil {
|
||||
mlog.Error("Unable to get teams when migrating post to use FileInfo", mlog.Err(err), mlog.String("post_id", post.Id))
|
||||
return ""
|
||||
@@ -237,7 +237,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
return []*model.FileInfo{}
|
||||
}
|
||||
|
||||
channel, errCh := a.Srv.Store.Channel().Get(post.ChannelId, true)
|
||||
channel, errCh := a.Srv().Store.Channel().Get(post.ChannelId, true)
|
||||
// There's a weird bug that rarely happens where a post ends up with duplicate Filenames so remove those
|
||||
filenames := utils.RemoveDuplicatesFromStringArray(post.Filenames)
|
||||
if errCh != nil {
|
||||
@@ -290,7 +290,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
fileMigrationLock.Lock()
|
||||
defer fileMigrationLock.Unlock()
|
||||
|
||||
result, err := a.Srv.Store.Post().Get(post.Id, false)
|
||||
result, err := a.Srv().Store.Post().Get(post.Id, false)
|
||||
if err != nil {
|
||||
mlog.Error("Unable to get post when migrating post to use FileInfos", mlog.Err(err), mlog.String("post_id", post.Id))
|
||||
return []*model.FileInfo{}
|
||||
@@ -299,7 +299,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
if newPost := result.Posts[post.Id]; len(newPost.Filenames) != len(post.Filenames) {
|
||||
// Another thread has already created FileInfos for this post, so just return those
|
||||
var fileInfos []*model.FileInfo
|
||||
fileInfos, err = a.Srv.Store.FileInfo().GetForPost(post.Id, true, false, false)
|
||||
fileInfos, err = a.Srv().Store.FileInfo().GetForPost(post.Id, true, false, false)
|
||||
if err != nil {
|
||||
mlog.Error("Unable to get FileInfos for migrated post", mlog.Err(err), mlog.String("post_id", post.Id))
|
||||
return []*model.FileInfo{}
|
||||
@@ -314,7 +314,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
savedInfos := make([]*model.FileInfo, 0, len(infos))
|
||||
fileIds := make([]string, 0, len(filenames))
|
||||
for _, info := range infos {
|
||||
if _, err = a.Srv.Store.FileInfo().Save(info); err != nil {
|
||||
if _, err = a.Srv().Store.FileInfo().Save(info); err != nil {
|
||||
mlog.Error(
|
||||
"Unable to save file info when migrating post to use FileInfos",
|
||||
mlog.String("post_id", post.Id),
|
||||
@@ -337,7 +337,7 @@ func (a *App) MigrateFilenamesToFileInfos(post *model.Post) []*model.FileInfo {
|
||||
newPost.FileIds = fileIds
|
||||
|
||||
// Update Posts to clear Filenames and set FileIds
|
||||
if _, err = a.Srv.Store.Post().Update(newPost, post); err != nil {
|
||||
if _, err = a.Srv().Store.Post().Update(newPost, post); err != nil {
|
||||
mlog.Error(
|
||||
"Unable to save migrated post when migrating to use FileInfos",
|
||||
mlog.String("new_file_ids", strings.Join(newPost.FileIds, ",")),
|
||||
@@ -457,43 +457,43 @@ func (a *App) DoUploadFile(now time.Time, rawTeamId string, rawChannelId string,
|
||||
return info, err
|
||||
}
|
||||
|
||||
func UploadFileSetTeamId(teamId string) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetTeamId(teamId string) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.TeamId = filepath.Base(teamId)
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetUserId(userId string) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetUserId(userId string) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.UserId = filepath.Base(userId)
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetTimestamp(timestamp time.Time) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetTimestamp(timestamp time.Time) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.Timestamp = timestamp
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetContentLength(contentLength int64) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetContentLength(contentLength int64) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.ContentLength = contentLength
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetClientId(clientId string) func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetClientId(clientId string) func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.ClientId = clientId
|
||||
}
|
||||
}
|
||||
|
||||
func UploadFileSetRaw() func(t *uploadFileTask) {
|
||||
return func(t *uploadFileTask) {
|
||||
func UploadFileSetRaw() func(t *UploadFileTask) {
|
||||
return func(t *UploadFileTask) {
|
||||
t.Raw = true
|
||||
}
|
||||
}
|
||||
|
||||
type uploadFileTask struct {
|
||||
type UploadFileTask struct {
|
||||
// File name.
|
||||
Name string
|
||||
|
||||
@@ -539,7 +539,7 @@ type uploadFileTask struct {
|
||||
saveToDatabase func(*model.FileInfo) (*model.FileInfo, *model.AppError)
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) init(a *App) {
|
||||
func (t *UploadFileTask) init(a *App) {
|
||||
t.buf = &bytes.Buffer{}
|
||||
t.maxFileSize = *a.Config().FileSettings.MaxFileSize
|
||||
t.limit = *a.Config().FileSettings.MaxFileSize
|
||||
@@ -571,7 +571,7 @@ func (t *uploadFileTask) init(a *App) {
|
||||
|
||||
t.pluginsEnvironment = a.GetPluginsEnvironment()
|
||||
t.writeFile = a.WriteFile
|
||||
t.saveToDatabase = a.Srv.Store.FileInfo().Save
|
||||
t.saveToDatabase = a.Srv().Store.FileInfo().Save
|
||||
}
|
||||
|
||||
// UploadFileX uploads a single file as specified in t. It applies the upload
|
||||
@@ -580,9 +580,9 @@ func (t *uploadFileTask) init(a *App) {
|
||||
// upload, returning a rejection error. In this case FileInfo would have
|
||||
// contained the last "good" FileInfo before the execution of that plugin.
|
||||
func (a *App) UploadFileX(channelId, name string, input io.Reader,
|
||||
opts ...func(*uploadFileTask)) (*model.FileInfo, *model.AppError) {
|
||||
opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError) {
|
||||
|
||||
t := &uploadFileTask{
|
||||
t := &UploadFileTask{
|
||||
ChannelId: filepath.Base(channelId),
|
||||
Name: filepath.Base(name),
|
||||
Input: input,
|
||||
@@ -644,7 +644,7 @@ func (a *App) UploadFileX(channelId, name string, input io.Reader,
|
||||
return t.fileinfo, nil
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) readAll() *model.AppError {
|
||||
func (t *UploadFileTask) readAll() *model.AppError {
|
||||
_, err := t.buf.ReadFrom(t.limitedInput)
|
||||
if err != nil {
|
||||
// Ugly hack: the error is not exported from net/http.
|
||||
@@ -666,7 +666,7 @@ func (t *uploadFileTask) readAll() *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) runPlugins() *model.AppError {
|
||||
func (t *UploadFileTask) runPlugins() *model.AppError {
|
||||
if t.pluginsEnvironment == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -703,7 +703,7 @@ func (t *uploadFileTask) runPlugins() *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) preprocessImage() *model.AppError {
|
||||
func (t *UploadFileTask) preprocessImage() *model.AppError {
|
||||
// If SVG, attempt to extract dimensions and then return
|
||||
if t.fileinfo.MimeType == "image/svg+xml" {
|
||||
svgInfo, err := parseSVG(t.newReader())
|
||||
@@ -767,7 +767,7 @@ func (t *uploadFileTask) preprocessImage() *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *uploadFileTask) postprocessImage() {
|
||||
func (t *UploadFileTask) postprocessImage() {
|
||||
// don't try to process SVG files
|
||||
if t.fileinfo.MimeType == "image/svg+xml" {
|
||||
return
|
||||
@@ -845,7 +845,7 @@ func (t *uploadFileTask) postprocessImage() {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func (t uploadFileTask) newReader() io.Reader {
|
||||
func (t UploadFileTask) newReader() io.Reader {
|
||||
if t.teeInput != nil {
|
||||
return io.MultiReader(bytes.NewReader(t.buf.Bytes()), t.teeInput)
|
||||
} else {
|
||||
@@ -853,7 +853,7 @@ func (t uploadFileTask) newReader() io.Reader {
|
||||
}
|
||||
}
|
||||
|
||||
func (t uploadFileTask) pathPrefix() string {
|
||||
func (t UploadFileTask) pathPrefix() string {
|
||||
return t.Timestamp.Format("20060102") +
|
||||
"/teams/" + t.TeamId +
|
||||
"/channels/" + t.ChannelId +
|
||||
@@ -861,7 +861,7 @@ func (t uploadFileTask) pathPrefix() string {
|
||||
"/" + t.fileinfo.Id + "/"
|
||||
}
|
||||
|
||||
func (t uploadFileTask) newAppError(id string, details interface{}, httpStatus int, extra ...interface{}) *model.AppError {
|
||||
func (t UploadFileTask) newAppError(id string, details interface{}, httpStatus int, extra ...interface{}) *model.AppError {
|
||||
params := map[string]interface{}{
|
||||
"Name": t.Name,
|
||||
"Filename": t.Name,
|
||||
@@ -950,7 +950,7 @@ func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, ra
|
||||
return nil, data, err
|
||||
}
|
||||
|
||||
if _, err := a.Srv.Store.FileInfo().Save(info); err != nil {
|
||||
if _, err := a.Srv().Store.FileInfo().Save(info); err != nil {
|
||||
return nil, data, err
|
||||
}
|
||||
|
||||
@@ -1094,7 +1094,7 @@ func (a *App) generatePreviewImage(img image.Image, previewPath string, width in
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfo(fileId string) (*model.FileInfo, *model.AppError) {
|
||||
return a.Srv.Store.FileInfo().Get(fileId)
|
||||
return a.Srv().Store.FileInfo().Get(fileId)
|
||||
}
|
||||
|
||||
func (a *App) GetFile(fileId string) ([]byte, *model.AppError) {
|
||||
@@ -1117,7 +1117,7 @@ func (a *App) CopyFileInfos(userId string, fileIds []string) ([]string, *model.A
|
||||
now := model.GetMillis()
|
||||
|
||||
for _, fileId := range fileIds {
|
||||
fileInfo, err := a.Srv.Store.FileInfo().Get(fileId)
|
||||
fileInfo, err := a.Srv().Store.FileInfo().Get(fileId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1128,7 +1128,7 @@ func (a *App) CopyFileInfos(userId string, fileIds []string) ([]string, *model.A
|
||||
fileInfo.UpdateAt = now
|
||||
fileInfo.PostId = ""
|
||||
|
||||
if _, err := a.Srv.Store.FileInfo().Save(fileInfo); err != nil {
|
||||
if _, err := a.Srv().Store.FileInfo().Save(fileInfo); err != nil {
|
||||
return newFileIds, err
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user