Add FileInfoStore and Cloud services for Focalboard multi product architecture (#20546)
* add FileInfoStore and Cloud services
Этот коммит содержится в:
13
app/cloud.go
13
app/cloud.go
@@ -8,10 +8,23 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
type cloudWrapper struct {
|
||||
cloud einterfaces.CloudInterface
|
||||
}
|
||||
|
||||
func (c *cloudWrapper) GetCloudLimits() (*model.ProductLimits, error) {
|
||||
if c.cloud != nil {
|
||||
return c.cloud.GetCloudLimits("")
|
||||
}
|
||||
|
||||
return &model.ProductLimits{}, nil
|
||||
}
|
||||
|
||||
func (a *App) getSysAdminsEmailRecipients() ([]*model.User, *model.AppError) {
|
||||
userOptions := &model.UserGetOptions{
|
||||
Page: 0,
|
||||
|
||||
22
app/file.go
22
app/file.go
@@ -47,6 +47,14 @@ const (
|
||||
maxContentExtractionSize = 1024 * 1024 // 1MB
|
||||
)
|
||||
|
||||
type fileInfoWrapper struct {
|
||||
srv *Server
|
||||
}
|
||||
|
||||
func (f *fileInfoWrapper) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||
return f.srv.getFileInfo(fileID)
|
||||
}
|
||||
|
||||
func (a *App) FileBackend() filestore.FileBackend {
|
||||
return a.ch.filestore
|
||||
}
|
||||
@@ -1125,8 +1133,8 @@ func (a *App) generateMiniPreviewForInfos(fileInfos []*model.FileInfo) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||
fileInfo, err := a.Srv().Store.FileInfo().Get(fileID)
|
||||
func (s *Server) getFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||
fileInfo, err := s.Store.FileInfo().Get(fileID)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
@@ -1136,11 +1144,17 @@ func (a *App) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||
return nil, model.NewAppError("GetFileInfo", "app.file_info.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
a.generateMiniPreview(fileInfo)
|
||||
return fileInfo, nil
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||
fileInfo, err := a.Srv().getFileInfo(fileID)
|
||||
if err == nil {
|
||||
a.generateMiniPreview(fileInfo)
|
||||
}
|
||||
return fileInfo, err
|
||||
}
|
||||
|
||||
func (a *App) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||
fileInfos, err := a.Srv().Store.FileInfo().GetWithOptions(page, perPage, opt)
|
||||
if err != nil {
|
||||
|
||||
@@ -86,19 +86,21 @@ var SentryDSN = "placeholder_sentry_dsn"
|
||||
type ServiceKey string
|
||||
|
||||
const (
|
||||
ChannelKey ServiceKey = "channel"
|
||||
ConfigKey ServiceKey = "config"
|
||||
LicenseKey ServiceKey = "license"
|
||||
FilestoreKey ServiceKey = "filestore"
|
||||
ClusterKey ServiceKey = "cluster"
|
||||
PostKey ServiceKey = "post"
|
||||
TeamKey ServiceKey = "team"
|
||||
UserKey ServiceKey = "user"
|
||||
PermissionsKey ServiceKey = "permissions"
|
||||
RouterKey ServiceKey = "router"
|
||||
BotKey ServiceKey = "bot"
|
||||
LogKey ServiceKey = "log"
|
||||
HooksKey ServiceKey = "hooks"
|
||||
ChannelKey ServiceKey = "channel"
|
||||
ConfigKey ServiceKey = "config"
|
||||
LicenseKey ServiceKey = "license"
|
||||
FilestoreKey ServiceKey = "filestore"
|
||||
FileInfoStoreKey ServiceKey = "fileinfostore"
|
||||
ClusterKey ServiceKey = "cluster"
|
||||
CloudKey ServiceKey = "cloud"
|
||||
PostKey ServiceKey = "post"
|
||||
TeamKey ServiceKey = "team"
|
||||
UserKey ServiceKey = "user"
|
||||
PermissionsKey ServiceKey = "permissions"
|
||||
RouterKey ServiceKey = "router"
|
||||
BotKey ServiceKey = "bot"
|
||||
LogKey ServiceKey = "log"
|
||||
HooksKey ServiceKey = "hooks"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
@@ -379,6 +381,14 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
srv: s,
|
||||
}
|
||||
|
||||
fileInfoWrapper := &fileInfoWrapper{
|
||||
srv: s,
|
||||
}
|
||||
|
||||
cloudWrapper := &cloudWrapper{
|
||||
cloud: s.Cloud,
|
||||
}
|
||||
|
||||
s.teamService, err = teams.New(teams.ServiceConfig{
|
||||
TeamStore: s.Store.Team(),
|
||||
ChannelStore: s.Store.Channel(),
|
||||
@@ -393,13 +403,15 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
}
|
||||
|
||||
serviceMap := map[ServiceKey]interface{}{
|
||||
ChannelKey: channelWrapper,
|
||||
ConfigKey: s.configStore,
|
||||
LicenseKey: s.licenseWrapper,
|
||||
FilestoreKey: s.filestore,
|
||||
ClusterKey: s.clusterWrapper,
|
||||
UserKey: New(ServerConnector(s.Channels())),
|
||||
LogKey: s.GetLogger(),
|
||||
ChannelKey: channelWrapper,
|
||||
ConfigKey: s.configStore,
|
||||
LicenseKey: s.licenseWrapper,
|
||||
FilestoreKey: s.filestore,
|
||||
FileInfoStoreKey: fileInfoWrapper,
|
||||
ClusterKey: s.clusterWrapper,
|
||||
UserKey: New(ServerConnector(s.Channels())),
|
||||
LogKey: s.GetLogger(),
|
||||
CloudKey: cloudWrapper,
|
||||
}
|
||||
|
||||
// Step 8: Initialize products.
|
||||
|
||||
@@ -134,3 +134,17 @@ type FilestoreService interface {
|
||||
WriteFile(fr io.Reader, path string) (int64, error)
|
||||
RemoveFile(path string) error
|
||||
}
|
||||
|
||||
// FileInfoStoreService is the API for accessing the file info store.
|
||||
//
|
||||
// The service shall be registered via app.FileInfoStoreKey service key.
|
||||
type FileInfoStoreService interface {
|
||||
GetFileInfo(fileID string) (*model.FileInfo, *model.AppError)
|
||||
}
|
||||
|
||||
// CloudService is the API for accessing the cloud service APIs.
|
||||
//
|
||||
// The service shall be registered via app.CloudKey service key.
|
||||
type CloudService interface {
|
||||
GetCloudLimits() (*model.ProductLimits, error)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user