♻️ Extract the Storage service to DysonNetwork.Drive microservice

This commit is contained in:
2025-07-06 17:29:26 +08:00
parent 6a3d04af3d
commit 14b79f16f4
71 changed files with 2629 additions and 346 deletions

View File

@ -1,10 +1,13 @@
using DysonNetwork.Common.Interfaces;
using DysonNetwork.Common.Models;
using DysonNetwork.Common.Services;
using DysonNetwork.Sphere.Storage;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Sphere.Sticker;
public class StickerService(AppDatabase db, FileService fs, FileReferenceService fileRefService, ICacheService cache)
public class StickerService(AppDatabase db, IFileReferenceServiceClient fileRefService, ICacheService cache)
{
public const string StickerFileUsageIdentifier = "sticker";
@ -19,9 +22,9 @@ public class StickerService(AppDatabase db, FileService fs, FileReferenceService
var stickerResourceId = $"sticker:{sticker.Id}";
await fileRefService.CreateReferenceAsync(
sticker.Image.Id,
StickerFileUsageIdentifier,
stickerResourceId
fileId: sticker.Image.Id.ToString(),
usage: StickerFileUsageIdentifier,
resourceId: stickerResourceId
);
return sticker;
@ -34,20 +37,23 @@ public class StickerService(AppDatabase db, FileService fs, FileReferenceService
var stickerResourceId = $"sticker:{sticker.Id}";
// Delete old references
var oldRefs =
await fileRefService.GetResourceReferencesAsync(stickerResourceId, StickerFileUsageIdentifier);
var oldRefs = await fileRefService.GetResourceReferencesAsync(
resourceId: stickerResourceId,
usage: StickerFileUsageIdentifier
);
foreach (var oldRef in oldRefs)
{
await fileRefService.DeleteReferenceAsync(oldRef.Id);
await fileRefService.DeleteReferenceAsync(oldRef.Id.ToString());
}
sticker.Image = newImage.ToReferenceObject();
// Create new reference
await fileRefService.CreateReferenceAsync(
newImage.Id,
StickerFileUsageIdentifier,
stickerResourceId
fileId: newImage.Id.ToString(),
usage: StickerFileUsageIdentifier,
resourceId: stickerResourceId
);
}