Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1266518532 | |||
| 719df155fb | |||
| e81d432b1f |
@@ -47,6 +47,9 @@ pub fn MediaItem(props: MediaItemProps) -> Element
|
||||
ContextMenu{
|
||||
ContextMenuTrigger{
|
||||
a {
|
||||
onmousemove: move |e: MouseEvent|{
|
||||
|
||||
},
|
||||
class: "mediaItem {class_string}",
|
||||
href: "{HOST}{url}",
|
||||
target: "_blank",
|
||||
|
||||
@@ -25,6 +25,11 @@ public class AobaService(IMongoDatabase db)
|
||||
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)
|
||||
{
|
||||
var filters = new List<FilterDefinition<Media>>()
|
||||
|
||||
@@ -53,6 +53,23 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
||||
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>
|
||||
|
||||
@@ -20,13 +20,13 @@ builder.WebHost.ConfigureKestrel(o =>
|
||||
o.Limits.MaxRequestBodySize = null;
|
||||
#if !DEBUG
|
||||
o.ListenAnyIP(8081, lo =>
|
||||
{
|
||||
lo.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http2;
|
||||
});
|
||||
{
|
||||
lo.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http2;
|
||||
});
|
||||
o.ListenAnyIP(8080, lo =>
|
||||
{
|
||||
lo.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1AndHttp2;
|
||||
});
|
||||
{
|
||||
lo.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1AndHttp2;
|
||||
});
|
||||
#endif
|
||||
});
|
||||
var config = builder.Configuration;
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Text.Json;
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -59,13 +59,30 @@ public class AobaRpcService(AobaService aobaService, AccountsService accountsSer
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
foreach (var item in media)
|
||||
{
|
||||
foreach (var (_, id) in item.Thumbnails)
|
||||
{
|
||||
await thumbnailService.DeleteThumbnailDirectAsync(id);
|
||||
}
|
||||
}
|
||||
return new Empty();
|
||||
}
|
||||
}
|
||||
@@ -8,5 +8,6 @@ public class DebugService(AobaService aobaService, ThumbnailService thumbnailSer
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
//todo: clean up orphaned thumbnails
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user