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"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
"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) {
|
func (a *App) getSysAdminsEmailRecipients() ([]*model.User, *model.AppError) {
|
||||||
userOptions := &model.UserGetOptions{
|
userOptions := &model.UserGetOptions{
|
||||||
Page: 0,
|
Page: 0,
|
||||||
|
|||||||
22
app/file.go
22
app/file.go
@@ -47,6 +47,14 @@ const (
|
|||||||
maxContentExtractionSize = 1024 * 1024 // 1MB
|
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 {
|
func (a *App) FileBackend() filestore.FileBackend {
|
||||||
return a.ch.filestore
|
return a.ch.filestore
|
||||||
}
|
}
|
||||||
@@ -1125,8 +1133,8 @@ func (a *App) generateMiniPreviewForInfos(fileInfos []*model.FileInfo) {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
func (s *Server) getFileInfo(fileID string) (*model.FileInfo, *model.AppError) {
|
||||||
fileInfo, err := a.Srv().Store.FileInfo().Get(fileID)
|
fileInfo, err := s.Store.FileInfo().Get(fileID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
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)
|
return nil, model.NewAppError("GetFileInfo", "app.file_info.get.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a.generateMiniPreview(fileInfo)
|
|
||||||
return fileInfo, nil
|
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) {
|
func (a *App) GetFileInfos(page, perPage int, opt *model.GetFileInfosOptions) ([]*model.FileInfo, *model.AppError) {
|
||||||
fileInfos, err := a.Srv().Store.FileInfo().GetWithOptions(page, perPage, opt)
|
fileInfos, err := a.Srv().Store.FileInfo().GetWithOptions(page, perPage, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -86,19 +86,21 @@ var SentryDSN = "placeholder_sentry_dsn"
|
|||||||
type ServiceKey string
|
type ServiceKey string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ChannelKey ServiceKey = "channel"
|
ChannelKey ServiceKey = "channel"
|
||||||
ConfigKey ServiceKey = "config"
|
ConfigKey ServiceKey = "config"
|
||||||
LicenseKey ServiceKey = "license"
|
LicenseKey ServiceKey = "license"
|
||||||
FilestoreKey ServiceKey = "filestore"
|
FilestoreKey ServiceKey = "filestore"
|
||||||
ClusterKey ServiceKey = "cluster"
|
FileInfoStoreKey ServiceKey = "fileinfostore"
|
||||||
PostKey ServiceKey = "post"
|
ClusterKey ServiceKey = "cluster"
|
||||||
TeamKey ServiceKey = "team"
|
CloudKey ServiceKey = "cloud"
|
||||||
UserKey ServiceKey = "user"
|
PostKey ServiceKey = "post"
|
||||||
PermissionsKey ServiceKey = "permissions"
|
TeamKey ServiceKey = "team"
|
||||||
RouterKey ServiceKey = "router"
|
UserKey ServiceKey = "user"
|
||||||
BotKey ServiceKey = "bot"
|
PermissionsKey ServiceKey = "permissions"
|
||||||
LogKey ServiceKey = "log"
|
RouterKey ServiceKey = "router"
|
||||||
HooksKey ServiceKey = "hooks"
|
BotKey ServiceKey = "bot"
|
||||||
|
LogKey ServiceKey = "log"
|
||||||
|
HooksKey ServiceKey = "hooks"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
@@ -379,6 +381,14 @@ func NewServer(options ...Option) (*Server, error) {
|
|||||||
srv: s,
|
srv: s,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileInfoWrapper := &fileInfoWrapper{
|
||||||
|
srv: s,
|
||||||
|
}
|
||||||
|
|
||||||
|
cloudWrapper := &cloudWrapper{
|
||||||
|
cloud: s.Cloud,
|
||||||
|
}
|
||||||
|
|
||||||
s.teamService, err = teams.New(teams.ServiceConfig{
|
s.teamService, err = teams.New(teams.ServiceConfig{
|
||||||
TeamStore: s.Store.Team(),
|
TeamStore: s.Store.Team(),
|
||||||
ChannelStore: s.Store.Channel(),
|
ChannelStore: s.Store.Channel(),
|
||||||
@@ -393,13 +403,15 @@ func NewServer(options ...Option) (*Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serviceMap := map[ServiceKey]interface{}{
|
serviceMap := map[ServiceKey]interface{}{
|
||||||
ChannelKey: channelWrapper,
|
ChannelKey: channelWrapper,
|
||||||
ConfigKey: s.configStore,
|
ConfigKey: s.configStore,
|
||||||
LicenseKey: s.licenseWrapper,
|
LicenseKey: s.licenseWrapper,
|
||||||
FilestoreKey: s.filestore,
|
FilestoreKey: s.filestore,
|
||||||
ClusterKey: s.clusterWrapper,
|
FileInfoStoreKey: fileInfoWrapper,
|
||||||
UserKey: New(ServerConnector(s.Channels())),
|
ClusterKey: s.clusterWrapper,
|
||||||
LogKey: s.GetLogger(),
|
UserKey: New(ServerConnector(s.Channels())),
|
||||||
|
LogKey: s.GetLogger(),
|
||||||
|
CloudKey: cloudWrapper,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 8: Initialize products.
|
// Step 8: Initialize products.
|
||||||
|
|||||||
@@ -134,3 +134,17 @@ type FilestoreService interface {
|
|||||||
WriteFile(fr io.Reader, path string) (int64, error)
|
WriteFile(fr io.Reader, path string) (int64, error)
|
||||||
RemoveFile(path string) 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