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