front y back minimos
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
|
||||
@@ -10,29 +11,33 @@ public class PhotoBuilder
|
||||
public static Photo Build(string? title, string? description, List<string>? tags, List<string>? personsIn, IFormFile image)
|
||||
{
|
||||
// Genera un nombre de archivo único
|
||||
var fileName = $"{Guid.NewGuid()}{Path.GetExtension(image.FileName)}";
|
||||
var photo = new Photo(title, description, tags, personsIn, fileName);
|
||||
var id = Guid.NewGuid();
|
||||
var fileName = $"{id}{Path.GetExtension(image.FileName)}";
|
||||
var photo = new Photo(title, description, tags, personsIn, fileName)
|
||||
{
|
||||
Id = id
|
||||
};
|
||||
|
||||
// Asegura que los directorios existen
|
||||
Directory.CreateDirectory(Photo.LowResFolder);
|
||||
Directory.CreateDirectory(Photo.MidResFolder);
|
||||
Directory.CreateDirectory(Photo.HighResFolder);
|
||||
Directory.CreateDirectory(Path.Join(Constants.Data, Photo.LowResFolder));
|
||||
Directory.CreateDirectory(Path.Join(Constants.Data, Photo.MidResFolder));
|
||||
Directory.CreateDirectory(Path.Join(Constants.Data, Photo.HighResFolder));
|
||||
|
||||
// Procesa y guarda las imágenes
|
||||
using var stream = image.OpenReadStream();
|
||||
using var img = Image.Load(stream);
|
||||
// Baja resolución (480px)
|
||||
img.Mutate(x => x.Resize(new ResizeOptions { Size = new Size(480, 0), Mode = ResizeMode.Max }));
|
||||
img.Save(photo.LowResUrl);
|
||||
img.Save(Path.Join(Constants.Data, photo.LowResUrl));
|
||||
|
||||
// Media resolución (720px)
|
||||
img.Mutate(x => x.Resize(new ResizeOptions { Size = new Size(720, 0), Mode = ResizeMode.Max }));
|
||||
img.Save(photo.MidResUrl);
|
||||
img.Save(Path.Join(Constants.Data, photo.MidResUrl));
|
||||
|
||||
// Original
|
||||
stream.Position = 0;
|
||||
using var original = Image.Load(stream);
|
||||
original.Save(photo.HighResUrl);
|
||||
original.Save(Path.Join(Constants.Data, photo.HighResUrl));
|
||||
|
||||
return photo;
|
||||
}
|
||||
@@ -45,7 +50,7 @@ public class Photo
|
||||
public const string MidResFolder = "imgs/mid";
|
||||
public const string HighResFolder = "imgs/high";
|
||||
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
|
Reference in New Issue
Block a user