Backend Go: - Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN. - Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError). - Sécurisation de config.go, CORS, statuts de santé et monitoring. - Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles). - Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés. - Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*. Chat server (Rust): - Refonte du pipeline JWT + sécurité, audit et rate limiting avancé. - Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing). - Nettoyage des panics, gestion d’erreurs robuste, logs structurés. - Migrations chat alignées sur le schéma UUID et nouvelles features. Stream server (Rust): - Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core. - Transactions P0 pour les jobs et segments, garanties d’atomicité. - Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION). Documentation & audits: - TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services. - Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3). - Scripts de reset et de cleanup pour la lab DB et la V1. Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
package workers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/disintegration/imaging"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// ThumbnailJob représente un job de génération de thumbnail
|
|
type ThumbnailJob struct {
|
|
InputPath string // Chemin du fichier source
|
|
OutputPath string // Chemin du fichier thumbnail à générer
|
|
Width int // Largeur du thumbnail (0 = auto, conserve ratio)
|
|
Height int // Hauteur du thumbnail (0 = auto, conserve ratio)
|
|
}
|
|
|
|
// NewThumbnailJob crée un nouveau job de thumbnail
|
|
func NewThumbnailJob(inputPath, outputPath string, width, height int) *ThumbnailJob {
|
|
// Valeurs par défaut si non spécifiées
|
|
if width == 0 {
|
|
width = 300 // Largeur par défaut
|
|
}
|
|
if height == 0 {
|
|
height = 300 // Hauteur par défaut
|
|
}
|
|
|
|
return &ThumbnailJob{
|
|
InputPath: inputPath,
|
|
OutputPath: outputPath,
|
|
Width: width,
|
|
Height: height,
|
|
}
|
|
}
|
|
|
|
// Execute exécute le job de génération de thumbnail
|
|
func (j *ThumbnailJob) Execute(ctx context.Context, logger *zap.Logger) error {
|
|
// Vérifier que le fichier source existe
|
|
if _, err := os.Stat(j.InputPath); os.IsNotExist(err) {
|
|
return fmt.Errorf("input file does not exist: %s", j.InputPath)
|
|
}
|
|
|
|
// Créer le répertoire de destination s'il n'existe pas
|
|
outputDir := filepath.Dir(j.OutputPath)
|
|
if err := os.MkdirAll(outputDir, 0755); err != nil {
|
|
return fmt.Errorf("failed to create output directory: %w", err)
|
|
}
|
|
|
|
// Ouvrir l'image source
|
|
src, err := imaging.Open(j.InputPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to open image: %w", err)
|
|
}
|
|
|
|
// Générer le thumbnail avec l'algorithme Lanczos (qualité élevée)
|
|
thumbnail := imaging.Resize(src, j.Width, j.Height, imaging.Lanczos)
|
|
|
|
// Déterminer le format de sortie depuis l'extension
|
|
ext := filepath.Ext(j.OutputPath)
|
|
// Ajuster l'extension si nécessaire
|
|
if ext == "" {
|
|
j.OutputPath = j.OutputPath + ".jpg"
|
|
ext = ".jpg"
|
|
}
|
|
|
|
// Sauvegarder le thumbnail (imaging.Save détecte automatiquement le format depuis l'extension)
|
|
if err := imaging.Save(thumbnail, j.OutputPath); err != nil {
|
|
return fmt.Errorf("failed to save thumbnail: %w", err)
|
|
}
|
|
|
|
logger.Info("Thumbnail generated successfully",
|
|
zap.String("input", j.InputPath),
|
|
zap.String("output", j.OutputPath),
|
|
zap.Int("width", j.Width),
|
|
zap.Int("height", j.Height),
|
|
)
|
|
|
|
return nil
|
|
}
|
|
|