video thumbnails extractor añadido
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user