2022-06-13 10:05:42 +02:00
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
sq "github.com/Masterminds/squirrel"
|
2022-09-13 12:18:40 +02:00
|
|
|
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
|
|
|
|
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
2022-06-13 10:05:42 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
|
|
|
)
|
|
|
|
|
2022-09-13 12:18:40 +02:00
|
|
|
func (s *SQLStore) saveFileInfo(db sq.BaseRunner, fileInfo *mmModel.FileInfo) error {
|
2022-06-13 10:05:42 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-09-13 12:18:40 +02:00
|
|
|
func (s *SQLStore) getFileInfo(db sq.BaseRunner, id string) (*mmModel.FileInfo, error) {
|
2022-06-13 10:05:42 +02:00
|
|
|
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()
|
|
|
|
|
2022-09-13 12:18:40 +02:00
|
|
|
fileInfo := mmModel.FileInfo{}
|
2022-06-13 10:05:42 +02:00
|
|
|
|
|
|
|
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) {
|
2022-09-13 12:18:40 +02:00
|
|
|
return nil, model.NewErrNotFound("file info ID=" + id)
|
2022-06-13 10:05:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s.logger.Error("error scanning fileinfo row", mlog.String("id", id), mlog.Err(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &fileInfo, nil
|
|
|
|
}
|