♻️ Extract the Storage service to DysonNetwork.Drive microservice
This commit is contained in:
39
DysonNetwork.Drive/Models/Account.cs
Normal file
39
DysonNetwork.Drive/Models/Account.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DysonNetwork.Drive.Models;
|
||||
|
||||
public class Account : ModelBase
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
[Required]
|
||||
[MaxLength(256)]
|
||||
public string Username { get; set; } = null!;
|
||||
|
||||
[Required]
|
||||
[MaxLength(256)]
|
||||
public string Email { get; set; } = null!;
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
public bool IsActive { get; set; } = true;
|
||||
public bool IsVerified { get; set; } = false;
|
||||
|
||||
// Navigation properties
|
||||
public virtual ICollection<CloudFile> Files { get; set; } = new List<CloudFile>();
|
||||
|
||||
// Timestamps
|
||||
public DateTimeOffset? LastLoginAt { get; set; }
|
||||
|
||||
// Methods
|
||||
public bool HasPermission(Permission permission)
|
||||
{
|
||||
// TODO: Implement actual permission checking logic
|
||||
return true;
|
||||
}
|
||||
}
|
67
DysonNetwork.Drive/Models/CloudFile.cs
Normal file
67
DysonNetwork.Drive/Models/CloudFile.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Drive.Models;
|
||||
|
||||
public class CloudFile : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
[MaxLength(256)]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string OriginalName { get; set; } = null!;
|
||||
|
||||
[MaxLength(256)]
|
||||
public string MimeType { get; set; } = null!;
|
||||
|
||||
public long Size { get; set; }
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string StoragePath { get; set; } = null!;
|
||||
|
||||
[MaxLength(64)]
|
||||
public string StorageProvider { get; set; } = "local";
|
||||
|
||||
[MaxLength(64)]
|
||||
public string? ContentHash { get; set; }
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string? ThumbnailPath { get; set; }
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string? PreviewPath { get; set; }
|
||||
|
||||
public int? Width { get; set; }
|
||||
public int? Height { get; set; }
|
||||
public float? Duration { get; set; }
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string? Metadata { get; set; }
|
||||
|
||||
[Column(TypeName = "jsonb")]
|
||||
public JsonDocument? ExtendedMetadata { get; set; }
|
||||
|
||||
public bool IsPublic { get; set; }
|
||||
public bool IsTemporary { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public Instant? ExpiresAt { get; set; }
|
||||
public new Instant? DeletedAt { get; set; }
|
||||
|
||||
public Guid? UploadedById { get; set; }
|
||||
public string? UploadedByType { get; set; }
|
||||
|
||||
public ICollection<CloudFileReference> References { get; set; } = new List<CloudFileReference>();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ExtendedMetadata?.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
61
DysonNetwork.Drive/Models/CloudFileReference.cs
Normal file
61
DysonNetwork.Drive/Models/CloudFileReference.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Drive.Models;
|
||||
|
||||
public class CloudFileReference : ModelBase
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
[MaxLength(2048)]
|
||||
public string ResourceId { get; set; } = null!;
|
||||
|
||||
[MaxLength(256)]
|
||||
public string ResourceType { get; set; } = null!;
|
||||
|
||||
[MaxLength(256)]
|
||||
public string ReferenceType { get; set; } = null!;
|
||||
|
||||
[MaxLength(256)]
|
||||
public string? ReferenceId { get; set; }
|
||||
|
||||
[MaxLength(256)]
|
||||
public string? ReferenceName { get; set; }
|
||||
|
||||
[MaxLength(256)]
|
||||
public string? ReferenceMimeType { get; set; }
|
||||
|
||||
public long? ReferenceSize { get; set; }
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string? ReferenceUrl { get; set; }
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string? ReferenceThumbnailUrl { get; set; }
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string? ReferencePreviewUrl { get; set; }
|
||||
|
||||
[MaxLength(1024)]
|
||||
public string? ReferenceMetadata { get; set; }
|
||||
|
||||
[Column(TypeName = "jsonb")]
|
||||
public JsonDocument? Metadata { get; set; }
|
||||
|
||||
public bool IsActive { get; set; } = true;
|
||||
|
||||
public Instant? ExpiresAt { get; set; }
|
||||
|
||||
public Guid FileId { get; set; }
|
||||
public virtual CloudFile File { get; set; } = null!;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Metadata?.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
10
DysonNetwork.Drive/Models/ModelBase.cs
Normal file
10
DysonNetwork.Drive/Models/ModelBase.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace DysonNetwork.Drive.Models;
|
||||
|
||||
public abstract class ModelBase
|
||||
{
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public DateTimeOffset? DeletedAt { get; set; }
|
||||
}
|
19
DysonNetwork.Drive/Models/Permission.cs
Normal file
19
DysonNetwork.Drive/Models/Permission.cs
Normal file
@ -0,0 +1,19 @@
|
||||
namespace DysonNetwork.Drive.Models;
|
||||
|
||||
public enum Permission
|
||||
{
|
||||
// File permissions
|
||||
File_Read,
|
||||
File_Write,
|
||||
File_Delete,
|
||||
File_Share,
|
||||
|
||||
// Admin permissions
|
||||
Admin_Access,
|
||||
Admin_ManageUsers,
|
||||
Admin_ManageFiles,
|
||||
|
||||
// Special permissions
|
||||
BypassRateLimit,
|
||||
BypassQuota
|
||||
}
|
50
DysonNetwork.Drive/Models/Post.cs
Normal file
50
DysonNetwork.Drive/Models/Post.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace DysonNetwork.Drive.Models;
|
||||
|
||||
public class Post : ModelBase
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
[Required]
|
||||
[MaxLength(1024)]
|
||||
public string Title { get; set; } = null!;
|
||||
|
||||
public string Content { get; set; } = string.Empty;
|
||||
|
||||
public Guid AuthorId { get; set; }
|
||||
public virtual Account? Author { get; set; }
|
||||
|
||||
public bool IsPublished { get; set; } = false;
|
||||
public bool IsDeleted { get; set; } = false;
|
||||
|
||||
// Navigation properties
|
||||
public virtual ICollection<PostViewInfo> Views { get; set; } = new List<PostViewInfo>();
|
||||
public virtual ICollection<CloudFileReference> Attachments { get; set; } = new List<CloudFileReference>();
|
||||
}
|
||||
|
||||
public class PostViewInfo
|
||||
{
|
||||
[Key]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public Guid PostId { get; set; }
|
||||
public virtual Post? Post { get; set; }
|
||||
|
||||
public string? UserAgent { get; set; }
|
||||
public string? IpAddress { get; set; }
|
||||
public string? Referrer { get; set; }
|
||||
|
||||
public string? ViewerId { get; set; }
|
||||
|
||||
public DateTimeOffset ViewedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
|
||||
// Additional metadata
|
||||
public string? CountryCode { get; set; }
|
||||
public string? DeviceType { get; set; }
|
||||
public string? Platform { get; set; }
|
||||
public string? Browser { get; set; }
|
||||
}
|
Reference in New Issue
Block a user