1
0
mirror of https://github.com/mattermost/focalboard.git synced 2025-01-26 18:48:15 +02:00
Harshil Sharma fa72286427
Board teamless file path (#4577)
* Updated upload and donwload code

* Removed archived file handling as we no longer have cloud limits

* Fixed server lint

* Restored unused

* CI

* Added new tests

* Fixed integration tests

* Added Path column for personal server's FileInfo table

* Removed sophesticated, elegant debug logs

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2023-03-07 10:21:53 +05:30

93 lines
1.7 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",
"path",
"archived",
).
Values(
fileInfo.Id,
fileInfo.CreateAt,
fileInfo.Name,
fileInfo.Extension,
fileInfo.Size,
fileInfo.DeleteAt,
fileInfo.Path,
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",
"path",
).
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,
&fileInfo.Path,
)
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
}