[MM-53454] Add export file settings + slash command for public link (#23915)
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -65,6 +65,10 @@ func (a *App) FileBackend() filestore.FileBackend {
|
||||
return a.ch.filestore
|
||||
}
|
||||
|
||||
func (a *App) ExportFileBackend() filestore.FileBackend {
|
||||
return a.ch.exportFilestore
|
||||
}
|
||||
|
||||
func (a *App) CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppError {
|
||||
fileBackendSettings := filestore.NewFileBackendSettingsFromConfig(settings, false, false)
|
||||
err := fileBackendSettings.CheckMandatoryS3Fields()
|
||||
@@ -111,31 +115,56 @@ func (a *App) ReadFile(path string) ([]byte, *model.AppError) {
|
||||
return a.ch.srv.ReadFile(path)
|
||||
}
|
||||
|
||||
func (s *Server) fileReader(path string) (filestore.ReadCloseSeeker, *model.AppError) {
|
||||
result, nErr := s.FileBackend().Reader(path)
|
||||
func fileReader(backend filestore.FileBackend, path string) (filestore.ReadCloseSeeker, *model.AppError) {
|
||||
result, nErr := backend.Reader(path)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("FileReader", "api.file.file_reader.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Server) fileReader(path string) (filestore.ReadCloseSeeker, *model.AppError) {
|
||||
return fileReader(s.FileBackend(), path)
|
||||
}
|
||||
|
||||
func (s *Server) exportFileReader(path string) (filestore.ReadCloseSeeker, *model.AppError) {
|
||||
return fileReader(s.ExportFileBackend(), path)
|
||||
}
|
||||
|
||||
// Caller must close the first return value
|
||||
func (a *App) FileReader(path string) (filestore.ReadCloseSeeker, *model.AppError) {
|
||||
return a.Srv().fileReader(path)
|
||||
}
|
||||
|
||||
// Caller must close the first return value
|
||||
func (a *App) ExportFileReader(path string) (filestore.ReadCloseSeeker, *model.AppError) {
|
||||
return a.Srv().exportFileReader(path)
|
||||
}
|
||||
|
||||
func (a *App) FileExists(path string) (bool, *model.AppError) {
|
||||
return a.Srv().fileExists(path)
|
||||
}
|
||||
|
||||
func (a *App) ExportFileExists(path string) (bool, *model.AppError) {
|
||||
return a.Srv().exportFileExists(path)
|
||||
}
|
||||
|
||||
func (s *Server) fileExists(path string) (bool, *model.AppError) {
|
||||
result, nErr := s.FileBackend().FileExists(path)
|
||||
return fileExists(s.FileBackend(), path)
|
||||
}
|
||||
|
||||
func fileExists(backend filestore.FileBackend, path string) (bool, *model.AppError) {
|
||||
result, nErr := backend.FileExists(path)
|
||||
if nErr != nil {
|
||||
return false, model.NewAppError("FileExists", "api.file.file_exists.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Server) exportFileExists(path string) (bool, *model.AppError) {
|
||||
return fileExists(s.ExportFileBackend(), path)
|
||||
}
|
||||
|
||||
func (a *App) FileSize(path string) (int64, *model.AppError) {
|
||||
size, nErr := a.FileBackend().FileSize(path)
|
||||
if nErr != nil {
|
||||
@@ -144,8 +173,8 @@ func (a *App) FileSize(path string) (int64, *model.AppError) {
|
||||
return size, nil
|
||||
}
|
||||
|
||||
func (a *App) FileModTime(path string) (time.Time, *model.AppError) {
|
||||
modTime, nErr := a.FileBackend().FileModTime(path)
|
||||
func fileModTime(backend filestore.FileBackend, path string) (time.Time, *model.AppError) {
|
||||
modTime, nErr := backend.FileModTime(path)
|
||||
if nErr != nil {
|
||||
return time.Time{}, model.NewAppError("FileModTime", "api.file.file_mod_time.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
@@ -153,6 +182,14 @@ func (a *App) FileModTime(path string) (time.Time, *model.AppError) {
|
||||
return modTime, nil
|
||||
}
|
||||
|
||||
func (a *App) FileModTime(path string) (time.Time, *model.AppError) {
|
||||
return fileModTime(a.FileBackend(), path)
|
||||
}
|
||||
|
||||
func (a *App) ExportFileModTime(path string) (time.Time, *model.AppError) {
|
||||
return fileModTime(a.ExportFileBackend(), path)
|
||||
}
|
||||
|
||||
func (a *App) MoveFile(oldPath, newPath string) *model.AppError {
|
||||
nErr := a.FileBackend().MoveFile(oldPath, newPath)
|
||||
if nErr != nil {
|
||||
@@ -169,17 +206,33 @@ func (a *App) WriteFile(fr io.Reader, path string) (int64, *model.AppError) {
|
||||
return a.Srv().writeFile(fr, path)
|
||||
}
|
||||
|
||||
func (s *Server) writeFile(fr io.Reader, path string) (int64, *model.AppError) {
|
||||
result, nErr := s.FileBackend().WriteFile(fr, path)
|
||||
func writeFile(backend filestore.FileBackend, fr io.Reader, path string) (int64, *model.AppError) {
|
||||
result, nErr := backend.WriteFile(fr, path)
|
||||
if nErr != nil {
|
||||
return result, model.NewAppError("WriteFile", "api.file.write_file.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Server) writeFileContext(ctx context.Context, fr io.Reader, path string) (int64, *model.AppError) {
|
||||
func (s *Server) writeFile(fr io.Reader, path string) (int64, *model.AppError) {
|
||||
return writeFile(s.FileBackend(), fr, path)
|
||||
}
|
||||
|
||||
func (s *Server) writeExportFile(fr io.Reader, path string) (int64, *model.AppError) {
|
||||
return writeFile(s.ExportFileBackend(), fr, path)
|
||||
}
|
||||
|
||||
func (a *App) WriteExportFileContext(ctx context.Context, fr io.Reader, path string) (int64, *model.AppError) {
|
||||
return a.Srv().writeExportFileContext(ctx, fr, path)
|
||||
}
|
||||
|
||||
func (a *App) WriteExportFile(fr io.Reader, path string) (int64, *model.AppError) {
|
||||
return a.Srv().writeExportFile(fr, path)
|
||||
}
|
||||
|
||||
func writeFileContext(ctx context.Context, backend filestore.FileBackend, fr io.Reader, path string) (int64, *model.AppError) {
|
||||
// Check if we can provide a custom context, otherwise just use the default method.
|
||||
written, err := filestore.TryWriteFileContext(s.FileBackend(), ctx, fr, path)
|
||||
written, err := filestore.TryWriteFileContext(backend, ctx, fr, path)
|
||||
if err != nil {
|
||||
return written, model.NewAppError("WriteFile", "api.file.write_file.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -187,6 +240,14 @@ func (s *Server) writeFileContext(ctx context.Context, fr io.Reader, path string
|
||||
return written, nil
|
||||
}
|
||||
|
||||
func (s *Server) writeFileContext(ctx context.Context, fr io.Reader, path string) (int64, *model.AppError) {
|
||||
return writeFileContext(ctx, s.FileBackend(), fr, path)
|
||||
}
|
||||
|
||||
func (s *Server) writeExportFileContext(ctx context.Context, fr io.Reader, path string) (int64, *model.AppError) {
|
||||
return writeFileContext(ctx, s.ExportFileBackend(), fr, path)
|
||||
}
|
||||
|
||||
func (a *App) AppendFile(fr io.Reader, path string) (int64, *model.AppError) {
|
||||
result, nErr := a.FileBackend().AppendFile(fr, path)
|
||||
if nErr != nil {
|
||||
@@ -199,24 +260,43 @@ func (a *App) RemoveFile(path string) *model.AppError {
|
||||
return a.Srv().removeFile(path)
|
||||
}
|
||||
|
||||
func (s *Server) removeFile(path string) *model.AppError {
|
||||
nErr := s.FileBackend().RemoveFile(path)
|
||||
func (a *App) RemoveExportFile(path string) *model.AppError {
|
||||
return a.Srv().removeExportFile(path)
|
||||
}
|
||||
|
||||
func removeFile(backend filestore.FileBackend, path string) *model.AppError {
|
||||
nErr := backend.RemoveFile(path)
|
||||
if nErr != nil {
|
||||
return model.NewAppError("RemoveFile", "api.file.remove_file.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) removeFile(path string) *model.AppError {
|
||||
return removeFile(s.FileBackend(), path)
|
||||
}
|
||||
|
||||
func (s *Server) removeExportFile(path string) *model.AppError {
|
||||
return removeFile(s.ExportFileBackend(), path)
|
||||
}
|
||||
|
||||
func (a *App) ListDirectory(path string) ([]string, *model.AppError) {
|
||||
return a.Srv().listDirectory(path, false)
|
||||
}
|
||||
|
||||
func (a *App) ListExportDirectory(path string) ([]string, *model.AppError) {
|
||||
return a.Srv().listExportDirectory(path, false)
|
||||
}
|
||||
|
||||
func (a *App) ListDirectoryRecursively(path string) ([]string, *model.AppError) {
|
||||
return a.Srv().listDirectory(path, true)
|
||||
}
|
||||
|
||||
func (s *Server) listDirectory(path string, recursion bool) ([]string, *model.AppError) {
|
||||
backend := s.FileBackend()
|
||||
return listDirectory(s.FileBackend(), path, recursion)
|
||||
}
|
||||
|
||||
func listDirectory(backend filestore.FileBackend, path string, recursion bool) ([]string, *model.AppError) {
|
||||
var paths []string
|
||||
var nErr error
|
||||
|
||||
@@ -227,12 +307,16 @@ func (s *Server) listDirectory(path string, recursion bool) ([]string, *model.Ap
|
||||
}
|
||||
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("ListDirectory", "api.file.list_directory.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
return nil, model.NewAppError("ListExportDirectory", "api.file.list_directory.app_error", nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
return paths, nil
|
||||
}
|
||||
|
||||
func (s *Server) listExportDirectory(path string, recursion bool) ([]string, *model.AppError) {
|
||||
return listDirectory(s.ExportFileBackend(), path, recursion)
|
||||
}
|
||||
|
||||
func (a *App) RemoveDirectory(path string) *model.AppError {
|
||||
nErr := a.FileBackend().RemoveDirectory(path)
|
||||
if nErr != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user