add fix for widgt files
This commit is contained in:
parent
904eeb49d1
commit
5f7a18c210
@ -45,6 +45,7 @@ func AddNewFile(fileService model.FileService) echo.HandlerFunc {
|
||||
ctx,
|
||||
*newFile,
|
||||
authData.AccountID,
|
||||
"widget",
|
||||
)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
|
@ -162,7 +162,7 @@ type FileRepo interface {
|
||||
ctx context.Context,
|
||||
streamerID int,
|
||||
file multipart.FileHeader,
|
||||
extension, fileType string,
|
||||
extension, fileType, entity string,
|
||||
) (string, error)
|
||||
GetByID(ctx context.Context, fileID string) ([]byte, string, error)
|
||||
WidgetsFiles(ctx context.Context, fileType string, streamerID int) ([]*DataFile, error)
|
||||
@ -175,6 +175,7 @@ type FileService interface {
|
||||
ctx context.Context,
|
||||
file multipart.FileHeader,
|
||||
streamerID int,
|
||||
entity string,
|
||||
) (string, error)
|
||||
GetByID(ctx context.Context, fileID string) ([]byte, string, error)
|
||||
WidgetsFiles(ctx context.Context, fileType string, streamerID int) ([]*DataFile, error)
|
||||
|
@ -14,6 +14,7 @@ type DataFile struct {
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Size float32 `db:"size" json:"size"`
|
||||
FileLink string `json:"file_link"`
|
||||
Entity string `db:"entity"`
|
||||
}
|
||||
|
||||
type GetWidgetDb struct {
|
||||
|
@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS files (
|
||||
file_name VARCHAR(50) NOT NULL,
|
||||
extension VARCHAR(10) NOT NULL,
|
||||
streamer_id INTEGER NOT NULL,
|
||||
entity VARCHAR(50) NOT NULL DEFAULT 'widget',
|
||||
created_at TIMESTAMP DEFAULT now()
|
||||
)
|
||||
|
||||
|
@ -127,19 +127,20 @@ var GetWidgetByName = `SELECT id FROM widgets WHERE (
|
||||
var FileById = `SELECT file_name, streamer_id, file_type FROM files WHERE id = (@id);`
|
||||
|
||||
var AudioFilesWidgets = `
|
||||
SELECT f.*
|
||||
FROM files AS f
|
||||
JOIN widgets AS w ON w.audio = f.id
|
||||
WHERE f.streamer_id = (@streamer_id);
|
||||
SELECT *
|
||||
FROM files
|
||||
WHERE streamer_id = @streamer_id
|
||||
AND entity = @entity
|
||||
AND file_type LIKE 'audio%';
|
||||
`
|
||||
|
||||
var ImageFilesWidgets = `
|
||||
SELECT f.*
|
||||
FROM files AS f
|
||||
JOIN widgets AS w ON w.image = f.id
|
||||
WHERE f.streamer_id = (@streamer_id);
|
||||
SELECT *
|
||||
FROM files
|
||||
WHERE streamer_id = @streamer_id
|
||||
AND entity = @entity
|
||||
AND file_type LIKE 'image%';
|
||||
`
|
||||
|
||||
var UpdateWidget = `
|
||||
UPDATE widgets
|
||||
SET
|
||||
|
@ -32,6 +32,7 @@ func (fileRepo *RepoFile) AddNew(
|
||||
streamerID int,
|
||||
file multipart.FileHeader,
|
||||
extension, fileType string,
|
||||
entity string,
|
||||
) (string, error) {
|
||||
fileName, err := fileRepo.storage.Upload(&file, streamerID)
|
||||
if err != nil {
|
||||
@ -45,6 +46,7 @@ func (fileRepo *RepoFile) AddNew(
|
||||
"file_type": fileType,
|
||||
"extension": extension,
|
||||
"size": sizeInKB,
|
||||
"entity": entity,
|
||||
}
|
||||
|
||||
fileIDRaw, err := fileRepo.db.Insert(ctx, sql.AddNewFile, args)
|
||||
@ -98,6 +100,7 @@ func (fileRepo *RepoFile) WidgetsFiles(
|
||||
) ([]*model.DataFile, error) {
|
||||
args := pgx.NamedArgs{
|
||||
"streamer_id": streamerID,
|
||||
"entity": "widget",
|
||||
}
|
||||
|
||||
var stmt string
|
||||
|
@ -37,6 +37,7 @@ func (fileService *ServiceFile) AddNewFile(
|
||||
ctx context.Context,
|
||||
file multipart.FileHeader,
|
||||
streamerID int,
|
||||
entity string,
|
||||
) (string, error) {
|
||||
fileExt := path.Ext(file.Filename)
|
||||
mimeType := mime.TypeByExtension(fileExt)
|
||||
@ -50,6 +51,7 @@ func (fileService *ServiceFile) AddNewFile(
|
||||
file,
|
||||
fileExt,
|
||||
mimeType,
|
||||
entity,
|
||||
)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS files (
|
||||
file_name VARCHAR(50) NOT NULL,
|
||||
extension VARCHAR(10) NOT NULL,
|
||||
streamer_id INTEGER NOT NULL,
|
||||
entity VARCHAR(50) NOT NULL DEFAULT 'widget',
|
||||
created_at TIMESTAMP DEFAULT now()
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS widgets (
|
||||
|
Loading…
x
Reference in New Issue
Block a user