Compare commits

..

3 Commits

Author SHA1 Message Date
Amatsugu 1266518532 revert grpc updates
Build and Push Image / build-and-push (push) Successful in 6m58s
2026-05-07 14:14:38 -04:00
Amatsugu 719df155fb fix compile error
Build and Push Image / build-and-push (push) Successful in 4m41s
2026-05-02 14:12:02 -04:00
Amatsugu e81d432b1f added missing thumbnail deletion on media delete
Build and Push Image / build-and-push (push) Failing after 4m14s
2026-05-02 13:42:52 -04:00
6 changed files with 213 additions and 170 deletions
+3
View File
@@ -47,6 +47,9 @@ pub fn MediaItem(props: MediaItemProps) -> Element
ContextMenu{ ContextMenu{
ContextMenuTrigger{ ContextMenuTrigger{
a { a {
onmousemove: move |e: MouseEvent|{
},
class: "mediaItem {class_string}", class: "mediaItem {class_string}",
href: "{HOST}{url}", href: "{HOST}{url}",
target: "_blank", target: "_blank",
+5
View File
@@ -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>>()
+17
View File
@@ -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>
+168 -168
View File
@@ -1,126 +1,126 @@
using AobaCore; using AobaCore;
using AobaServer.Auth; using AobaServer.Auth;
using AobaServer.Middleware; using AobaServer.Middleware;
using AobaServer.Models; using AobaServer.Models;
using AobaServer.Services; using AobaServer.Services;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Core.Extensions.DiagnosticSources; using MongoDB.Driver.Core.Extensions.DiagnosticSources;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(o => builder.WebHost.ConfigureKestrel(o =>
{ {
o.Limits.MaxRequestBodySize = null; o.Limits.MaxRequestBodySize = null;
#if !DEBUG #if !DEBUG
o.ListenAnyIP(8081, lo => 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 => o.ListenAnyIP(8080, lo =>
{ {
lo.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1AndHttp2; lo.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http1AndHttp2;
}); });
#endif #endif
}); });
var config = builder.Configuration; var config = builder.Configuration;
// Add services to the container. // Add services to the container.
builder.Services.AddControllers(opt => opt.ModelBinderProviders.Add(new BsonIdModelBinderProvider())); builder.Services.AddControllers(opt => opt.ModelBinderProviders.Add(new BsonIdModelBinderProvider()));
builder.Services.AddObersability(builder.Configuration); builder.Services.AddObersability(builder.Configuration);
builder.Services.AddGrpc(); builder.Services.AddGrpc();
//DB //DB
var dbString = config["DB_STRING"]; var dbString = config["DB_STRING"];
var settings = MongoClientSettings.FromConnectionString(dbString); var settings = MongoClientSettings.FromConnectionString(dbString);
settings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber()); settings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber());
var dbClient = new MongoClient(settings); var dbClient = new MongoClient(settings);
var db = dbClient.GetDatabase("Aoba"); var db = dbClient.GetDatabase("Aoba");
builder.Services.AddSingleton(dbClient); builder.Services.AddSingleton(dbClient);
builder.Services.AddSingleton<IMongoDatabase>(db); builder.Services.AddSingleton<IMongoDatabase>(db);
var authCfg = new AuthConfigService(db); var authCfg = new AuthConfigService(db);
builder.Services.AddSingleton(authCfg); builder.Services.AddSingleton(authCfg);
var authInfo = authCfg.GetDefaultAuthInfoAsync().GetAwaiter().GetResult(); var authInfo = authCfg.GetDefaultAuthInfoAsync().GetAwaiter().GetResult();
var signingKey = new SymmetricSecurityKey(authInfo.SecureKey); var signingKey = new SymmetricSecurityKey(authInfo.SecureKey);
var validationParams = new TokenValidationParameters var validationParams = new TokenValidationParameters
{ {
ValidateIssuerSigningKey = true, ValidateIssuerSigningKey = true,
IssuerSigningKey = signingKey, IssuerSigningKey = signingKey,
ValidateIssuer = true, ValidateIssuer = true,
ValidIssuer = authInfo.Issuer, ValidIssuer = authInfo.Issuer,
ValidateAudience = true, ValidateAudience = true,
ValidAudience = authInfo.Audience, ValidAudience = authInfo.Audience,
ValidateLifetime = false, ValidateLifetime = false,
ClockSkew = TimeSpan.FromMinutes(1), ClockSkew = TimeSpan.FromMinutes(1),
}; };
builder.Services.AddCors(o => builder.Services.AddCors(o =>
{ {
o.AddPolicy("AllowAll", p => o.AddPolicy("AllowAll", p =>
{ {
p.AllowAnyOrigin(); p.AllowAnyOrigin();
p.AllowAnyMethod(); p.AllowAnyMethod();
p.AllowAnyHeader(); p.AllowAnyHeader();
}); });
o.AddPolicy("RPC", p => o.AddPolicy("RPC", p =>
{ {
p.AllowAnyMethod(); p.AllowAnyMethod();
p.AllowAnyHeader(); p.AllowAnyHeader();
p.WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding"); p.WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding");
p.AllowAnyOrigin(); p.AllowAnyOrigin();
}); });
}); });
var metricsAuthInfo = authCfg.GetAuthInfoAsync("aoba", "metrics").GetAwaiter().GetResult(); var metricsAuthInfo = authCfg.GetAuthInfoAsync("aoba", "metrics").GetAwaiter().GetResult();
builder.Services.AddAuthentication(options => builder.Services.AddAuthentication(options =>
{ {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "Aoba"; options.DefaultChallengeScheme = "Aoba";
}).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => //Bearer auth }).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => //Bearer auth
{ {
options.TokenValidationParameters = validationParams; options.TokenValidationParameters = validationParams;
options.TokenHandlers.Add(new MetricsTokenValidator(metricsAuthInfo)); options.TokenHandlers.Add(new MetricsTokenValidator(metricsAuthInfo));
options.Events = new JwtBearerEvents options.Events = new JwtBearerEvents
{ {
OnMessageReceived = ctx => //Retreive token from cookie if not found in headers OnMessageReceived = ctx => //Retreive token from cookie if not found in headers
{ {
if (string.IsNullOrWhiteSpace(ctx.Token)) if (string.IsNullOrWhiteSpace(ctx.Token))
ctx.Token = ctx.Request.Headers.Authorization.FirstOrDefault()?.Replace("Bearer ", ""); ctx.Token = ctx.Request.Headers.Authorization.FirstOrDefault()?.Replace("Bearer ", "");
#if DEBUG //allow cookie based auth when in debug mode #if DEBUG //allow cookie based auth when in debug mode
if (string.IsNullOrWhiteSpace(ctx.Token)) if (string.IsNullOrWhiteSpace(ctx.Token))
ctx.Token = ctx.Request.Cookies.FirstOrDefault(c => c.Key == "token").Value; ctx.Token = ctx.Request.Cookies.FirstOrDefault(c => c.Key == "token").Value;
#endif #endif
return Task.CompletedTask; return Task.CompletedTask;
}, },
OnAuthenticationFailed = ctx => OnAuthenticationFailed = ctx =>
{ {
ctx.Response.Cookies.Append("token", "", new CookieOptions ctx.Response.Cookies.Append("token", "", new CookieOptions
{ {
MaxAge = TimeSpan.Zero, MaxAge = TimeSpan.Zero,
Expires = DateTime.Now Expires = DateTime.Now
}); });
ctx.Options.ForwardChallenge = "Aoba"; ctx.Options.ForwardChallenge = "Aoba";
return Task.CompletedTask; return Task.CompletedTask;
} }
}; };
}).AddScheme<AuthenticationSchemeOptions, AobaAuthenticationHandler>("Aoba", null); }).AddScheme<AuthenticationSchemeOptions, AobaAuthenticationHandler>("Aoba", null);
builder.Services.AddAoba(); builder.Services.AddAoba();
builder.Services.AddFido2(opts => builder.Services.AddFido2(opts =>
{ {
opts.ServerName = "Aoba"; opts.ServerName = "Aoba";
@@ -130,48 +130,48 @@ builder.Services.AddFido2(opts =>
#else #else
opts.Origins = new HashSet<string> { "https://aoba.app" }; opts.Origins = new HashSet<string> { "https://aoba.app" };
#endif #endif
}); });
#if DEBUG #if DEBUG
builder.Services.AddHostedService<DebugService>(); builder.Services.AddHostedService<DebugService>();
#endif #endif
builder.Services.Configure<FormOptions>(opt => builder.Services.Configure<FormOptions>(opt =>
{ {
opt.ValueLengthLimit = int.MaxValue; opt.ValueLengthLimit = int.MaxValue;
opt.MultipartBodyLengthLimit = long.MaxValue; opt.MultipartBodyLengthLimit = long.MaxValue;
}); });
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
{ {
app.UseExceptionHandler("/Home/Error"); app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true }); app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseCors(); app.UseCors();
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();
app.MapObserability(); app.MapObserability();
app.MapGrpcService<AobaRpcService>() app.MapGrpcService<AobaRpcService>()
.RequireAuthorization() .RequireAuthorization()
.RequireCors("RPC"); .RequireCors("RPC");
app.MapGrpcService<MetricsRpcService>() app.MapGrpcService<MetricsRpcService>()
.RequireAuthorization() .RequireAuthorization()
.RequireCors("RPC"); .RequireCors("RPC");
app.MapGrpcService<AobaAuthService>() app.MapGrpcService<AobaAuthService>()
.AllowAnonymous() .AllowAnonymous()
.RequireCors("RPC"); .RequireCors("RPC");
app.MapFallbackToFile("index.html"); app.MapFallbackToFile("index.html");
app.Run(); app.Run();
+19 -2
View File
@@ -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();
} }
} }
+1
View File
@@ -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
} }
} }