Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 719df155fb | |||
| e81d432b1f |
@@ -25,6 +25,11 @@ public class AobaService(IMongoDatabase db)
|
|||||||
return await _media.Find(m => m.MediaId == id).FirstOrDefaultAsync(cancellationToken);
|
return await _media.Find(m => m.MediaId == id).FirstOrDefaultAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<Media>> GetMediaAsync(IEnumerable<ObjectId> ids, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _media.Find(m => ids.Contains(m.MediaId)).ToListAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<PagedResult<Media>> FindMediaAsync(string? query, ObjectId userId, int page = 1, int pageSize = 100, CancellationToken cancellationToken = default)
|
public async Task<PagedResult<Media>> FindMediaAsync(string? query, ObjectId userId, int page = 1, int pageSize = 100, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var filters = new List<FilterDefinition<Media>>()
|
var filters = new List<FilterDefinition<Media>>()
|
||||||
|
|||||||
@@ -53,6 +53,23 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Error?> DeleteThumbnailDirectAsync(ObjectId thumbnailId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _gridfs.DeleteAsync(thumbnailId);
|
||||||
|
}
|
||||||
|
catch (GridFSFileNotFoundException)
|
||||||
|
{
|
||||||
|
//Ignore if the file was not found (somehow already deleted)
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return new ExceptionError(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Text.Json;
|
|||||||
|
|
||||||
namespace AobaServer.Services;
|
namespace AobaServer.Services;
|
||||||
|
|
||||||
public class AobaRpcService(AobaService aobaService, AccountsService accountsService, AuthConfigService authConfig) : AobaRpc.AobaRpcBase
|
public class AobaRpcService(AobaService aobaService, ThumbnailService thumbnailService, AccountsService accountsService, AuthConfigService authConfig) : AobaRpc.AobaRpcBase
|
||||||
{
|
{
|
||||||
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
|
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
@@ -59,13 +59,30 @@ public class AobaRpcService(AobaService aobaService, AccountsService accountsSer
|
|||||||
|
|
||||||
public override async Task<Empty> DeleteMedia(Id request, ServerCallContext context)
|
public override async Task<Empty> DeleteMedia(Id request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
await aobaService.DeleteFileAsync(request.ToObjectId(), context.CancellationToken);
|
var media = await aobaService.GetMediaAsync(request.ToObjectId());
|
||||||
|
if (media == null)
|
||||||
|
return new Empty();
|
||||||
|
await aobaService.DeleteFileAsync(media.MediaId, context.CancellationToken);
|
||||||
|
foreach (var (_, id) in media.Thumbnails)
|
||||||
|
{
|
||||||
|
await thumbnailService.DeleteThumbnailDirectAsync(id);
|
||||||
|
}
|
||||||
return new Empty();
|
return new Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<Empty> DeleteMediaBulk(IdList request, ServerCallContext context)
|
public override async Task<Empty> DeleteMediaBulk(IdList request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
|
var media = await aobaService.GetMediaAsync(request.ToObjectId(), context.CancellationToken);
|
||||||
|
if(media.Count == 0)
|
||||||
|
return new Empty();
|
||||||
await aobaService.DeleteFilesAsync(request.ToObjectId(), context.CancellationToken);
|
await aobaService.DeleteFilesAsync(request.ToObjectId(), context.CancellationToken);
|
||||||
|
foreach (var item in media)
|
||||||
|
{
|
||||||
|
foreach (var (_, id) in item.Thumbnails)
|
||||||
|
{
|
||||||
|
await thumbnailService.DeleteThumbnailDirectAsync(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
return new Empty();
|
return new Empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,5 +8,6 @@ public class DebugService(AobaService aobaService, ThumbnailService thumbnailSer
|
|||||||
{
|
{
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
|
//todo: clean up orphaned thumbnails
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user