video thumbnails extractor añadido

This commit is contained in:
Abraham
2026-01-13 15:08:10 -08:00
parent 8612688aa3
commit 9533b60906
6 changed files with 225 additions and 20 deletions

View File

@@ -37,6 +37,36 @@ class VideosProvider extends ChangeNotifier {
String? posterStoragePath;
String posterFileExtension = '';
Uint8List? webPosterBytes;
// ========== HELPERS ==========
/// Sanitize file name to avoid issues with special characters in URLs
/// Removes/replaces: brackets [], parentheses (), spaces, special chars
String _sanitizeFileName(String fileName) {
// Get extension
final ext = p.extension(fileName);
final nameWithoutExt = p.basenameWithoutExtension(fileName);
// Replace special characters and spaces
String sanitized = nameWithoutExt
.replaceAll(RegExp(r'[\[\]\(\){}]'), '') // Remove brackets/parentheses
.replaceAll(RegExp(r'[^a-zA-Z0-9_-]'),
'_') // Replace other special chars with underscore
.replaceAll(
RegExp(r'_+'), '_') // Replace multiple underscores with single
.replaceAll(
RegExp(r'^_|_$'), ''); // Remove leading/trailing underscores
// If name is empty after sanitization, use generic name
if (sanitized.isEmpty) {
sanitized = 'video_${DateTime.now().millisecondsSinceEpoch}';
}
// Limit length to avoid excessively long names (max 100 chars + extension)
if (sanitized.length > 100) {
sanitized = sanitized.substring(0, 100);
}
return '$sanitized$ext';
}
// ========== LOADING STATE ==========
bool isLoading = false;
@@ -246,7 +276,8 @@ class VideosProvider extends ChangeNotifier {
// 1. Upload video to storage
final timestamp = DateTime.now().millisecondsSinceEpoch;
final fileName = '${timestamp}_$videoName';
final sanitizedName = _sanitizeFileName(videoName!);
final fileName = '${timestamp}_$sanitizedName';
videoStoragePath = 'videos/$fileName';
await supabaseML.storage.from('energymedia').uploadBinary(
@@ -323,7 +354,8 @@ class VideosProvider extends ChangeNotifier {
try {
final timestamp = DateTime.now().millisecondsSinceEpoch;
final fileName = '${timestamp}_$posterName';
final sanitizedName = _sanitizeFileName(posterName!);
final fileName = '${timestamp}_$sanitizedName';
posterStoragePath = 'imagenes/$fileName';
// Solo subir al storage, NO crear registro en media_files
@@ -484,7 +516,8 @@ class VideosProvider extends ChangeNotifier {
// Upload new poster to storage
final timestamp = DateTime.now().millisecondsSinceEpoch;
final fileName = '${timestamp}_$posterName';
final sanitizedName = _sanitizeFileName(posterName);
final fileName = '${timestamp}_$sanitizedName';
final posterPath = 'imagenes/$fileName';
await supabaseML.storage.from('energymedia').uploadBinary(