- 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 SetImagesToDB(pool *[]typesdefs.UploadedMedia) error {
|
|
batch := &pgx.Batch{}
|
|
|
|
for _, data := range *pool {
|
|
batch.Queue(`
|
|
INSERT INTO public.images_refs (codice, ordine, img, thumb, og_url)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
ON CONFLICT (codice, ordine) DO UPDATE SET img = $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 images batch: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func GetImagesFromDB() ([]typesdefs.ImagesRefs, error) {
|
|
var images []typesdefs.ImagesRefs
|
|
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &images, "SELECT * FROM public.images_refs ORDER BY ordine ASC")
|
|
if err != nil && err != pgx.ErrNoRows {
|
|
return nil, fmt.Errorf("failed to get images: %w", err)
|
|
}
|
|
return images, nil
|
|
}
|
|
|
|
func GetCodiceImagesFromDB(codice string) ([]typesdefs.ImagesRefs, error) {
|
|
var images []typesdefs.ImagesRefs
|
|
err := pgxscan.Select(Db.Ctx, Db.Dbpool, &images, "SELECT * FROM public.images_refs WHERE codice = $1 ORDER BY ordine ASC", codice)
|
|
if err != nil && err != pgx.ErrNoRows {
|
|
return nil, fmt.Errorf("failed to get images: %w", err)
|
|
}
|
|
return images, nil
|
|
}
|
|
|
|
func ClearImagesRefsByCodice(codice string) error {
|
|
_, err := Db.Dbpool.Exec(Db.Ctx, "DELETE FROM public.images_refs WHERE codice = $1", codice)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to clear images refs by codice: %w", err)
|
|
}
|
|
return nil
|
|
}
|