mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-24 13:43:12 +02:00
08c0b7a2fd
* Refactor error usage from the store level up and add API helpers * Complete API tests * Fix merge errorResponse calls * Remove ensure helpers to allow for custom messages on permission errors * Fix bad import and call * Remove bad user check on auth that was added as part of the main merge * Fix empty list test * Replace deprecated proxy calls to ioutil.ReadAll with io.ReadAll * Add information to the NotFound errors * Add context to all remaining errors and address review comments * Fix linter * Adapt the new card API endpoints to the error refactor * Remove almost all customErrorResponse calls * Add request entity too large to errorResponse and remove customErrorResponse * Fix linter
89 lines
1.6 KiB
Go
89 lines
1.6 KiB
Go
package sqlstore
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
|
)
|
|
|
|
func (s *SQLStore) saveFileInfo(db sq.BaseRunner, fileInfo *mmModel.FileInfo) error {
|
|
query := s.getQueryBuilder(db).
|
|
Insert(s.tablePrefix+"file_info").
|
|
Columns(
|
|
"id",
|
|
"create_at",
|
|
"name",
|
|
"extension",
|
|
"size",
|
|
"delete_at",
|
|
"archived",
|
|
).
|
|
Values(
|
|
fileInfo.Id,
|
|
fileInfo.CreateAt,
|
|
fileInfo.Name,
|
|
fileInfo.Extension,
|
|
fileInfo.Size,
|
|
fileInfo.DeleteAt,
|
|
false,
|
|
)
|
|
|
|
if _, err := query.Exec(); err != nil {
|
|
s.logger.Error(
|
|
"failed to save fileinfo",
|
|
mlog.String("file_name", fileInfo.Name),
|
|
mlog.Int64("size", fileInfo.Size),
|
|
mlog.Err(err),
|
|
)
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *SQLStore) getFileInfo(db sq.BaseRunner, id string) (*mmModel.FileInfo, error) {
|
|
query := s.getQueryBuilder(db).
|
|
Select(
|
|
"id",
|
|
"create_at",
|
|
"delete_at",
|
|
"name",
|
|
"extension",
|
|
"size",
|
|
"archived",
|
|
).
|
|
From(s.tablePrefix + "file_info").
|
|
Where(sq.Eq{"Id": id})
|
|
|
|
row := query.QueryRow()
|
|
|
|
fileInfo := mmModel.FileInfo{}
|
|
|
|
err := row.Scan(
|
|
&fileInfo.Id,
|
|
&fileInfo.CreateAt,
|
|
&fileInfo.DeleteAt,
|
|
&fileInfo.Name,
|
|
&fileInfo.Extension,
|
|
&fileInfo.Size,
|
|
&fileInfo.Archived,
|
|
)
|
|
|
|
if err != nil {
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return nil, model.NewErrNotFound("file info ID=" + id)
|
|
}
|
|
|
|
s.logger.Error("error scanning fileinfo row", mlog.String("id", id), mlog.Err(err))
|
|
return nil, err
|
|
}
|
|
|
|
return &fileInfo, nil
|
|
}
|