Initial commit

This commit is contained in:
shiyu
2025-05-18 20:48:20 +08:00
commit cde2c7b997
79 changed files with 5713 additions and 0 deletions

18
Models/DataBase/Album.cs Normal file
View File

@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.DataBase;
public class Album : BaseModel
{
[Required]
[StringLength(100)]
public string Name { get; set; } = string.Empty;
[StringLength(500)]
public string Description { get; set; } = string.Empty;
public int UserId { get; set; }
[Required]
public User User { get; set; }
public ICollection<Picture>? Pictures { get; set; }
}

View File

@@ -0,0 +1,12 @@
namespace Foxel.Models.DataBase;
public class AlbumPicture
{
public int Id { get; set; }
public int AlbumId { get; set; }
public int PictureId { get; set; }
// 导航属性
public Album? Album { get; set; }
public Picture? Picture { get; set; }
}

View File

@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.DataBase;
public abstract class BaseModel
{
[Key] public int Id { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
}

17
Models/DataBase/Config.cs Normal file
View File

@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.DataBase;
public class Config : BaseModel
{
[Required]
[StringLength(50)]
public string Key { get; set; } = string.Empty;
[Required]
[StringLength(255)]
public string Value { get; set; } = string.Empty;
[StringLength(255)]
public string Description { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Foxel.Models.DataBase;
public class Favorite
{
[Key]
public int Id { get; set; }
public User User { get; set; }
public int PictureId { get; set; }
[ForeignKey("PictureId")]
public Picture Picture { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}

View File

@@ -0,0 +1,69 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using Vector = Pgvector.Vector;
namespace Foxel.Models.DataBase;
public enum StorageType
{
Local = 0,
Telegram = 1,
}
public class Picture : BaseModel
{
[StringLength(255)] public string Name { get; set; } = string.Empty;
[StringLength(1024)] public string Path { get; set; } = string.Empty;
[StringLength(1024)] public string? ThumbnailPath { get; set; } = string.Empty;
[StringLength(2000)] public string Description { get; set; } = string.Empty;
[Column(TypeName = "vector(1024)")] public Vector? Embedding { get; set; }
public DateTime? TakenAt { get; set; }
[Column(TypeName = "jsonb")] public string? ExifInfoJson { get; set; }
[NotMapped]
public ExifInfo? ExifInfo
{
get => ExifInfoJson != null ? JsonSerializer.Deserialize<ExifInfo>(ExifInfoJson) : null;
set => ExifInfoJson = value != null ? JsonSerializer.Serialize(value) : null;
}
public StorageType StorageType { get; set; } = StorageType.Local;
public ICollection<Tag>? Tags { get; set; }
public int? UserId { get; set; }
public User? User { get; set; }
public int? AlbumId { get; set; }
public Album? Album { get; set; }
public ICollection<Favorite>? Favorites { get; set; }
public bool ContentWarning { get; set; } = false;
public PermissionType Permission { get; set; } = PermissionType.Public;
public ProcessingStatus ProcessingStatus { get; set; } = ProcessingStatus.Pending;
public string? ProcessingError { get; set; }
public int ProcessingProgress { get; set; } = 0;
}
public enum PermissionType
{
Public = 0,
Friends = 1,
Private = 2
}
public enum ProcessingStatus
{
Pending, // 等待处理
Processing, // 处理中
Completed, // 处理完成
Failed // 处理失败
}

15
Models/DataBase/Role.cs Normal file
View File

@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.DataBase;
public class Role : BaseModel
{
[Required]
[StringLength(50)]
public string Name { get; set; } = string.Empty;
[StringLength(200)]
public string Description { get; set; } = string.Empty;
public ICollection<User>? Users { get; set; }
}

14
Models/DataBase/Tag.cs Normal file
View File

@@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.DataBase;
public class Tag : BaseModel
{
[Required] [StringLength(50)] public string Name { get; set; } = string.Empty;
[StringLength(200)] public string Description { get; set; } = string.Empty;
public ICollection<Picture>? Pictures { get; set; }
public ICollection<User>? Users { get; set; }
}

26
Models/DataBase/User.cs Normal file
View File

@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.DataBase;
public class User : BaseModel
{
[Required] [StringLength(50)] public required string UserName { get; set; }
[Required]
[EmailAddress]
[StringLength(100)]
public required string Email { get; set; }
[Required] [StringLength(255)] public required string PasswordHash { get; set; }
[StringLength(255)] public string? GithubId { get; set; }
public int? RoleId { get; set; }
public Role? Role { get; set; }
public ICollection<Favorite>? Favorites { get; set; }
public ICollection<Tag>? Tags { get; set; }
public ICollection<Album>? Albums { get; set; }
}