Remix file service

This commit is contained in:
2025-07-14 13:50:41 +08:00
parent 06f1cc3ca1
commit ef9175d27d
12 changed files with 110 additions and 184 deletions

View File

@@ -78,7 +78,7 @@ public abstract class Leveling
];
}
public class AccountProfile : ModelBase
public class AccountProfile : ModelBase, IIdentifiedResource
{
public Guid Id { get; set; }
[MaxLength(256)] public string? FirstName { get; set; }
@@ -104,10 +104,6 @@ public class AccountProfile : ModelBase
: (Experience - Leveling.ExperiencePerLevel[Level]) * 100.0 /
(Leveling.ExperiencePerLevel[Level + 1] - Leveling.ExperiencePerLevel[Level]);
// Outdated fields, for backward compability
[MaxLength(32)] public string? PictureId { get; set; }
[MaxLength(32)] public string? BackgroundId { get; set; }
[Column(TypeName = "jsonb")] public CloudFileReferenceObject? Picture { get; set; }
[Column(TypeName = "jsonb")] public CloudFileReferenceObject? Background { get; set; }
@@ -132,8 +128,6 @@ public class AccountProfile : ModelBase
Experience = Experience,
Level = Level,
LevelingProgress = LevelingProgress,
PictureId = PictureId ?? string.Empty,
BackgroundId = BackgroundId ?? string.Empty,
Picture = Picture?.ToProtoValue(),
Background = Background?.ToProtoValue(),
AccountId = AccountId.ToString(),
@@ -143,6 +137,8 @@ public class AccountProfile : ModelBase
return proto;
}
public string ResourceIdentifier => $"account:profile:{Id}";
}
public class AccountContact : ModelBase

View File

@@ -1,13 +1,8 @@
using System.ComponentModel.DataAnnotations;
using DysonNetwork.Pass.Auth;
using DysonNetwork.Pass;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using NodaTime;
using NodaTime.Extensions;
using System.Collections.Generic;
using DysonNetwork.Pass.Account;
namespace DysonNetwork.Pass.Account;

View File

@@ -1,10 +1,14 @@
using System.ComponentModel.DataAnnotations;
using DysonNetwork.Pass.Auth;
using DysonNetwork.Pass.Permission;
using DysonNetwork.Shared.Data;
using DysonNetwork.Shared.Proto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using NodaTime;
using AuthService = DysonNetwork.Pass.Auth.AuthService;
using AuthSession = DysonNetwork.Pass.Auth.AuthSession;
using ChallengePlatform = DysonNetwork.Pass.Auth.ChallengePlatform;
namespace DysonNetwork.Pass.Account;
@@ -15,7 +19,9 @@ public class AccountCurrentController(
AppDatabase db,
AccountService accounts,
AccountEventService events,
AuthService auth
AuthService auth,
FileService.FileServiceClient files,
FileReferenceService.FileReferenceServiceClient fileRefs
) : ControllerBase
{
[HttpGet]
@@ -94,12 +100,37 @@ public class AccountCurrentController(
if (request.PictureId is not null)
{
// TODO: Create reference, set profile picture
var file = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
if (profile.Picture is not null)
await fileRefs.DeleteResourceReferencesAsync(
new DeleteResourceReferencesRequest { ResourceId = profile.ResourceIdentifier }
);
await fileRefs.CreateReferenceAsync(
new CreateReferenceRequest
{
ResourceId = profile.ResourceIdentifier,
FileId = request.PictureId,
Usage = "profile.picture"
}
);
profile.Picture = CloudFileReferenceObject.FromProtoValue(file);
}
if (request.BackgroundId is not null)
{
// TODO: Create reference, set profile background
var file = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId });
if (profile.Background is not null)
await fileRefs.DeleteResourceReferencesAsync(
new DeleteResourceReferencesRequest { ResourceId = profile.ResourceIdentifier }
);
await fileRefs.CreateReferenceAsync(
new CreateReferenceRequest
{
ResourceId = profile.ResourceIdentifier,
FileId = request.BackgroundId,
Usage = "profile.background"
}
);
profile.Background = CloudFileReferenceObject.FromProtoValue(file);
}
db.Update(profile);

View File

@@ -100,7 +100,7 @@ public class AccountEventService(
}
}
if (cacheMissUserIds.Any())
if (cacheMissUserIds.Count != 0)
{
var now = SystemClock.Instance.GetCurrentInstant();
var statusesFromDb = await db.AccountStatuses