We move these fields to Channels: ``` uploadLockMapMut sync.Mutex uploadLockMap map[string]bool imgDecoder *imaging.Decoder imgEncoder *imaging.Encoder dndTaskMut sync.Mutex dndTask *model.ScheduledTask ``` I think this PR should conclue the initial phase of migrating stuff from Server to Channels. The remaining task would be to focus on continue to create the remaining services from the common things like users, teams, push notifications, clustering for other products to consume. https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4/87df1e15-588e-49ff-8bd1-ffa9651b8c82 ```release-note NONE ```
84 строки
2.4 KiB
Go
84 строки
2.4 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"mime/multipart"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/mattermost/mattermost-server/v6/model"
|
|
)
|
|
|
|
const (
|
|
BrandFilePath = "brand/"
|
|
BrandFileName = "image.png"
|
|
)
|
|
|
|
func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
|
|
if *a.Config().FileSettings.DriverName == "" {
|
|
return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.storage.app_error", nil, "", http.StatusNotImplemented)
|
|
}
|
|
|
|
file, err := imageData.Open()
|
|
if err != nil {
|
|
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.open.app_error", nil, err.Error(), http.StatusBadRequest)
|
|
}
|
|
defer file.Close()
|
|
|
|
if err = checkImageLimits(file, *a.Config().FileSettings.MaxImageResolution); err != nil {
|
|
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.check_image_limits.app_error", nil, err.Error(), http.StatusBadRequest)
|
|
}
|
|
|
|
img, _, err := a.ch.imgDecoder.Decode(file)
|
|
if err != nil {
|
|
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.decode.app_error", nil, err.Error(), http.StatusBadRequest)
|
|
}
|
|
|
|
buf := new(bytes.Buffer)
|
|
err = a.ch.imgEncoder.EncodePNG(buf, img)
|
|
if err != nil {
|
|
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.encode.app_error", nil, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
|
|
t := time.Now()
|
|
a.MoveFile(BrandFilePath+BrandFileName, BrandFilePath+t.Format("2006-01-02T15:04:05")+".png")
|
|
|
|
if _, err := a.WriteFile(buf, BrandFilePath+BrandFileName); err != nil {
|
|
return model.NewAppError("SaveBrandImage", "brand.save_brand_image.save_image.app_error", nil, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (a *App) GetBrandImage() ([]byte, *model.AppError) {
|
|
if *a.Config().FileSettings.DriverName == "" {
|
|
return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.storage.app_error", nil, "", http.StatusNotImplemented)
|
|
}
|
|
|
|
img, err := a.ReadFile(BrandFilePath + BrandFileName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return img, nil
|
|
}
|
|
|
|
func (a *App) DeleteBrandImage() *model.AppError {
|
|
filePath := BrandFilePath + BrandFileName
|
|
|
|
fileExists, err := a.FileExists(filePath)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if !fileExists {
|
|
return model.NewAppError("DeleteBrandImage", "api.admin.delete_brand_image.storage.not_found", nil, "", http.StatusNotFound)
|
|
}
|
|
|
|
return a.RemoveFile(filePath)
|
|
}
|