- Updated the announcement detail component to directly use images and videos from the data structure. - Changed the form edit component to accommodate the new media structure, replacing AnnunciWithImages with AnnunciWithMedia. - Modified the announcements list to initialize videos as an empty array. - Enhanced the announcement view to handle external videos and updated the footer to display them correctly. - Introduced a new utility function to generate YouTube embed URLs. - Updated the database schema to replace url_video with external_videos and added a new videos_refs table for video management. - Implemented video processing logic, including downloading, transcoding, and thumbnail generation. - Added migration scripts for the new videos_refs table and updated existing references in the database.
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package queries
|
|
|
|
import (
|
|
"backend/typesdefs"
|
|
"fmt"
|
|
|
|
"github.com/georgysavva/scany/v2/pgxscan"
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
func SetVideosToDB(pool *[]typesdefs.UploadedMedia) error {
|
|
batch := &pgx.Batch{}
|
|
|
|
for _, data := range *pool {
|
|
batch.Queue(`
|
|
INSERT INTO public.videos_refs (codice, ordine, video, thumb, og_url)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
ON CONFLICT (codice, ordine) DO UPDATE SET video = $3, thumb = $4
|
|
`, data.Codice, data.Order, data.MediaId, data.ThumbId, data.OGUrl)
|
|
}
|
|
|
|
if err := Db.Dbpool.SendBatch(Db.Ctx, batch).Close(); err != nil {
|
|
return fmt.Errorf("failed to insert/update video batch: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func GetVideosFromDB() ([]typesdefs.VideosRefs, error) {
|
|
var videos []typesdefs.VideosRefs
|
|
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &videos, "SELECT * FROM public.videos_refs ORDER BY ordine ASC")
|
|
if err != nil && err != pgx.ErrNoRows {
|
|
return nil, fmt.Errorf("failed to get videos: %w", err)
|
|
}
|
|
return videos, nil
|
|
}
|
|
|
|
func GetCodiceVideosFromDB(codice string) ([]typesdefs.VideosRefs, error) {
|
|
var videos []typesdefs.VideosRefs
|
|
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &videos, "SELECT * FROM public.videos_refs WHERE codice = $1 ORDER BY ordine ASC", codice)
|
|
if err != nil && err != pgx.ErrNoRows {
|
|
return nil, fmt.Errorf("failed to get videos: %w", err)
|
|
}
|
|
return videos, nil
|
|
}
|
|
|
|
func ClearVideosRefsByCodice(codice string) error {
|
|
_, err := Db.Dbpool.Exec(Db.Ctx, "DELETE FROM public.videos_refs WHERE codice = $1", codice)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to clear videos refs by codice: %w", err)
|
|
}
|
|
return nil
|
|
}
|