Files
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

94 lines
2.5 KiB
Go

package pluginapi
import (
"bytes"
"io"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/public/plugin"
)
// FileService exposes methods to manipulate files, most often as post attachments.
type FileService struct {
api plugin.API
}
// Get gets content of a file by id.
//
// Minimum server version: 5.8
func (f *FileService) Get(id string) (io.Reader, error) {
contentBytes, appErr := f.api.GetFile(id)
if appErr != nil {
return nil, normalizeAppErr(appErr)
}
return bytes.NewReader(contentBytes), nil
}
// GetByPath reads a file by its path on the dist.
//
// Minimum server version: 5.3
func (f *FileService) GetByPath(path string) (io.Reader, error) {
contentBytes, appErr := f.api.ReadFile(path)
if appErr != nil {
return nil, normalizeAppErr(appErr)
}
return bytes.NewReader(contentBytes), nil
}
// GetInfo gets a file's info by id.
//
// Minimum server version: 5.3
func (f *FileService) GetInfo(id string) (*model.FileInfo, error) {
info, appErr := f.api.GetFileInfo(id)
return info, normalizeAppErr(appErr)
}
// SetSearchableContent update the File Info searchable text for full text search
//
// Minimum server version: 9.1
func (f *FileService) SetSearchableContent(id string, content string) error {
appErr := f.api.SetFileSearchableContent(id, content)
return normalizeAppErr(appErr)
}
// GetLink gets the public link of a file by id.
//
// Minimum server version: 5.6
func (f *FileService) GetLink(id string) (string, error) {
link, appErr := f.api.GetFileLink(id)
return link, normalizeAppErr(appErr)
}
// Upload uploads a file to a channel to be later attached to a post.
//
// Minimum server version: 5.6
func (f *FileService) Upload(content io.Reader, fileName, channelID string) (*model.FileInfo, error) {
contentBytes, err := io.ReadAll(content)
if err != nil {
return nil, err
}
info, appErr := f.api.UploadFile(contentBytes, channelID, fileName)
return info, normalizeAppErr(appErr)
}
// CopyInfos duplicates the FileInfo objects referenced by the given file ids, recording
// the given user id as the new creator and returning the new set of file ids.
//
// The duplicate FileInfo objects are not initially linked to a post, but may now be passed
// on creation of a post.
// Use this API to duplicate a post and its file attachments without actually duplicating
// the uploaded files.
//
// Minimum server version: 5.2
func (f *FileService) CopyInfos(ids []string, userID string) ([]string, error) {
newIDs, appErr := f.api.CopyFileInfos(userID, ids)
return newIDs, normalizeAppErr(appErr)
}