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

17
Models/BaseResult.cs Normal file
View File

@@ -0,0 +1,17 @@
namespace Foxel.Models;
public class BaseResult<T>
{
public string Message { get; set; } = string.Empty;
public bool Success { get; set; } = true;
public T? Data { get; set; }
public int StatusCode { get; set; } = 200;
}
public class BaseResult
{
public string Message { get; set; } = string.Empty;
public bool Success { get; set; } = true;
public int Data { get; set; }
public int StatusCode { get; set; } = 200;
}

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; }
}

35
Models/ExifInfo.cs Normal file
View File

@@ -0,0 +1,35 @@
using System.Text.Json.Serialization;
namespace Foxel.Models;
public class ExifInfo
{
// 基本图像信息
public int Width { get; set; }
public int Height { get; set; }
// 相机信息
public string? CameraMaker { get; set; }
public string? CameraModel { get; set; }
public string? Software { get; set; }
// 拍摄参数
public string? ExposureTime { get; set; }
public string? Aperture { get; set; }
public string? IsoSpeed { get; set; }
public string? FocalLength { get; set; }
public string? Flash { get; set; }
public string? MeteringMode { get; set; }
public string? WhiteBalance { get; set; }
// 时间信息
public string? DateTimeOriginal { get; set; }
// 位置信息
public string? GpsLatitude { get; set; }
public string? GpsLongitude { get; set; }
// 错误信息
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? ErrorMessage { get; set; }
}

13
Models/PaginatedResult.cs Normal file
View File

@@ -0,0 +1,13 @@
namespace Foxel.Models;
public class PaginatedResult<T> : BaseResult<List<T>>
{
public int Page { get; set; } = 1;
public int PageSize { get; set; } = 10;
public int TotalCount { get; set; }
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
public bool HasPreviousPage => Page > 1;
public bool HasNextPage => Page < TotalPages;
}

View File

@@ -0,0 +1,7 @@
namespace Foxel.Models.Request.Album;
public class AlbumPictureRequest
{
public int AlbumId { get; set; }
public int PictureId { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace Foxel.Models.Request.Album;
public class AlbumPicturesRequest
{
public int AlbumId { get; set; }
public List<int> PictureIds { get; set; } = new();
}

View File

@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.Request.Album;
public class CreateAlbumRequest
{
[Required]
[StringLength(100)]
public string Name { get; set; } = string.Empty;
[StringLength(500)]
public string? Description { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace Foxel.Models.Request.Album;
public class UpdateAlbumRequest : CreateAlbumRequest
{
public int Id { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace Foxel.Models.Request.Auth;
public class LoginRequest
{
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,8 @@
namespace Foxel.Models.Request.Auth;
public class RegisterRequest
{
public string UserName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.Request.Config;
public class SetConfigRequest
{
[Required(ErrorMessage = "配置键不能为空")]
[StringLength(50, ErrorMessage = "配置键长度不能超过50个字符")]
public string Key { get; set; } = string.Empty;
public string? Value { get; set; }
[StringLength(255, ErrorMessage = "描述长度不能超过255个字符")]
public string? Description { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace Foxel.Models.Request.Picture;
public class DeleteMultiplePicturesRequest
{
public List<int> PictureIds { get; set; } = new();
}

View File

@@ -0,0 +1,6 @@
namespace Foxel.Models.Request.Picture;
public class DeletePictureRequest
{
public int Id { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace Foxel.Models.Request.Picture;
public class FavoriteRequest
{
public int PictureId { get; set; }
}

View File

@@ -0,0 +1,39 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.Request.Picture
{
public class FilteredPicturesRequest
{
[Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]
public int Page { get; set; } = 1;
[Range(1, 100, ErrorMessage = "每页数量必须在1-100之间")]
public int PageSize { get; set; } = 8;
public string? SearchQuery { get; set; }
public string? Tags { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public string? SortBy { get; set; } = "newest";
public bool OnlyWithGps { get; set; } = false;
public bool UseVectorSearch { get; set; } = false;
public double SimilarityThreshold { get; set; } = 0.36;
public int? ExcludeAlbumId { get; set; }
public int? AlbumId { get; set; }
public bool OnlyFavorites { get; set; } = false;
public int? OwnerId { get; set; }
public bool IncludeAllPublic { get; set; } = false;
}
}

View File

@@ -0,0 +1,9 @@
namespace Foxel.Models.Request.Picture;
public class SearchPicturesByTextRequest
{
public string Query { get; set; } = string.Empty;
public int Page { get; set; } = 1;
public int PageSize { get; set; } = 8;
public double SimilarityThreshold { get; set; } = 0.36;
}

View File

@@ -0,0 +1,8 @@
namespace Foxel.Models.Request.Picture;
public class UpdatePictureRequest
{
public string? Name { get; set; }
public string? Description { get; set; }
public List<string>? Tags { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace Foxel.Models.Request.Picture;
public class UpdatePictureRequestWithId : UpdatePictureRequest
{
public int Id { get; set; }
}

View File

@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
using Foxel.Models.DataBase;
namespace Foxel.Models.Request.Picture;
public class UploadPictureRequest
{
[Required] public IFormFile File { get; set; } = null!;
public int? Permission { get; set; } = 1;
public int? AlbumId { get; set; } = null;
}

View File

@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.Request.Tag;
public class CreateTagRequest
{
[Required]
[StringLength(50)]
public string Name { get; set; } = string.Empty;
[StringLength(200)]
public string? Description { get; set; }
}

View File

@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace Foxel.Models.Request.Tag
{
public class FilteredTagsRequest
{
[Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]
public int Page { get; set; } = 1;
[Range(1, 100, ErrorMessage = "每页数量必须在1-100之间")]
public int PageSize { get; set; } = 20;
public string? SearchQuery { get; set; }
// 排序方式name, pictureCount, createdAt
public string? SortBy { get; set; } = "pictureCount";
// 排序方向asc, desc
public string? SortDirection { get; set; } = "desc";
}
}

View File

@@ -0,0 +1,6 @@
namespace Foxel.Models.Request.Tag;
public class UpdateTagRequest : CreateTagRequest
{
public int Id { get; set; }
}

View File

@@ -0,0 +1,15 @@
using Foxel.Models.Response.Picture;
namespace Foxel.Models.Response.Album;
public class AlbumResponse
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public int PictureCount { get; set; } = 0;
public int UserId { get; set; }
public string? Username { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}

View File

@@ -0,0 +1,15 @@
namespace Foxel.Models.Response.Auth;
public class UserProfile
{
public int Id { get; set; }
public string UserName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string? RoleName { get; set; }
}
public class AuthResponse
{
public string Token { get; set; } = string.Empty;
public UserProfile User { get; set; } = new();
}

View File

@@ -0,0 +1,26 @@
using Foxel.Models.DataBase;
namespace Foxel.Models.Response.Picture;
public class PictureResponse
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? Path { get; set; }
public string? ThumbnailPath { get; set; }
public string Description { get; set; } = string.Empty;
public DateTime CreatedAt { get; set; }
public List<string>? Tags { get; set; }
public DateTime? TakenAt { get; set; }
public ExifInfo? ExifInfo { get; set; }
public int? UserId { get; set; }
public string? Username { get; set; }
public bool IsFavorited { get; set; }
public int FavoriteCount { get; set; }
public int? AlbumId { get; set; }
public string? AlbumName { get; set; }
public PermissionType Permission { get; set; } = PermissionType.Public;
public ProcessingStatus ProcessingStatus { get; set; }
public string? ProcessingError { get; set; }
public int ProcessingProgress { get; set; }
}

View File

@@ -0,0 +1,19 @@
namespace Foxel.Models.Response.Tag;
public class TagResponse
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public int PictureCount { get; set; } = 0;
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}
public class TagWithCount
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public int Count { get; set; } = 0;
}