Compare commits

...

5 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
Amatsugu 61d70aee28 update packages
Build and Push Image / build-and-push (push) Successful in 4m55s
2026-05-01 15:10:46 -04:00
Amatsugu 73236e1fde remove debug service
Build and Push Image / build-and-push (push) Successful in 4m52s
2026-05-01 14:58:09 -04:00
8 changed files with 245 additions and 190 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",
+4 -4
View File
@@ -10,13 +10,13 @@
<PackageReference Include="FFMpegCore" Version="5.4.0" /> <PackageReference Include="FFMpegCore" Version="5.4.0" />
<PackageReference Include="Fido2.Models" Version="4.0.1" /> <PackageReference Include="Fido2.Models" Version="4.0.1" />
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" /> <PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.5" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.7" />
<PackageReference Include="MaybeError" Version="1.2.0" /> <PackageReference Include="MaybeError" Version="1.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.5" /> <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.7" />
<PackageReference Include="MongoDB.Driver" Version="3.7.1" /> <PackageReference Include="MongoDB.Driver" Version="3.8.0" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="3.0.0" /> <PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="3.0.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" /> <PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.17.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.18.0" />
<PackageReference Include="ZLinq" Version="1.5.6" /> <PackageReference Include="ZLinq" Version="1.5.6" />
</ItemGroup> </ItemGroup>
+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>>()
+37 -2
View File
@@ -10,8 +10,11 @@ using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.GridFS; using MongoDB.Driver.GridFS;
using SixLabors.Fonts;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using System; using System;
@@ -50,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>
@@ -120,7 +140,7 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
MediaType.Image => await GenerateImageThumbnailAsync(stream, size, ext, cancellationToken), MediaType.Image => await GenerateImageThumbnailAsync(stream, size, ext, cancellationToken),
MediaType.Video => GenerateVideoThumbnail(stream, size, cancellationToken), MediaType.Video => GenerateVideoThumbnail(stream, size, cancellationToken),
MediaType.Audio => GenerateAudioThumbnail(stream, size, ext, cancellationToken), MediaType.Audio => GenerateAudioThumbnail(stream, size, ext, cancellationToken),
MediaType.Text or MediaType.Code => await GenerateDocumentThumbnailAsync(stream, size, cancellationToken), MediaType.Text or MediaType.Code => await GenerateTextThumbnailAsync(stream, size, cancellationToken),
_ => new Error($"No Thumbnail for {type}"), _ => new Error($"No Thumbnail for {type}"),
}; };
} }
@@ -266,8 +286,23 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
} }
} }
public async Task<Maybe<Stream>> GenerateDocumentThumbnailAsync(Stream data, ThumbnailSize size, CancellationToken cancellationToken = default) public async Task<Maybe<Stream>> GenerateTextThumbnailAsync(Stream data, ThumbnailSize size, CancellationToken cancellationToken = default)
{ {
//var w = (int)size;
//using var image = new Image<Rgba32>(w, w);
//var reader = new StreamReader(data);
//var text = new char[500];
//reader.ReadBlock(text, 0, text.Length);
//image.Mutate(op =>
//{
// op.BackgroundColor(Color.Black);
// var font = new Font(), 11);
// var textOpts = new RichTextOptions(font);
// op.DrawText(, new string(text), new Brush
// {
// });
//});
return new NotImplementedException(); return new NotImplementedException();
} }
} }
+8 -8
View File
@@ -10,22 +10,22 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Fido2.AspNet" Version="4.0.1" /> <PackageReference Include="Fido2.AspNet" Version="4.0.1" />
<PackageReference Include="Grpc.AspNetCore" Version="2.76.0" /> <PackageReference Include="Grpc.AspNetCore" Version="2.80.0" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.76.0" /> <PackageReference Include="Grpc.AspNetCore.Web" Version="2.80.0" />
<PackageReference Include="Grpc.Tools" Version="2.80.0"> <PackageReference Include="Grpc.Tools" Version="2.80.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" /> <PackageReference Include="Isopoh.Cryptography.Argon2" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.7" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.17.0" /> <PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.18.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageReference Include="MimeTypesMap" Version="1.0.9" /> <PackageReference Include="MimeTypesMap" Version="1.0.9" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.2" /> <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.3" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.9.0-beta.2" /> <PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.9.0-beta.2" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.2" /> <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.1" /> <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.2" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.0" /> <PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+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 -6
View File
@@ -8,11 +8,6 @@ public class DebugService(AobaService aobaService, ThumbnailService thumbnailSer
{ {
protected override async Task ExecuteAsync(CancellationToken stoppingToken) protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{ {
var mediaItems = await aobaService.FindMediaWithExtAsync(".ogg", stoppingToken); //todo: clean up orphaned thumbnails
foreach (var item in mediaItems)
{
if(item.MediaType != MediaType.Audio)
await aobaService.SetMediaTypeAsync(item.MediaId, MediaType.Audio);
}
} }
} }