Search Bar
Search requests
This commit is contained in:
2025-05-03 22:21:11 -04:00
parent 3eac4e619e
commit e223612a08
17 changed files with 191 additions and 69 deletions

View File

@@ -32,7 +32,8 @@
</ItemGroup>
<ItemGroup>
<Protobuf Include="Proto\Aoba.proto"></Protobuf>
<Protobuf Include="Proto\Aoba.proto"></Protobuf>
<Protobuf Include="Proto\Auth.proto"></Protobuf>
</ItemGroup>
</Project>

View File

@@ -16,16 +16,12 @@ public class MediaController(AobaService aobaService, ILogger<MediaController> l
[ResponseCache(Duration = int.MaxValue)]
public async Task<IActionResult> MediaAsync(ObjectId id, [FromServices] MongoClient client, CancellationToken cancellationToken)
{
using var session = await client.StartSessionAsync(cancellationToken: cancellationToken);
session.StartTransaction();
var file = await aobaService.GetFileStreamAsync(id, cancellationToken: cancellationToken);
if (file.HasError)
{
await session.AbortTransactionAsync(cancellationToken: cancellationToken);
logger.LogError(file.Error.Exception, "Failed to load media stream");
return NotFound();
}
await session.CommitTransactionAsync(cancellationToken: cancellationToken);
var mime = MimeTypesMap.GetMimeType(file.Value.FileInfo.Filename);
_ = aobaService.IncrementFileViewCountAsync(id, cancellationToken);
return File(file, mime, true);

View File

@@ -42,7 +42,16 @@ builder.Services.AddCors(o =>
p.AllowAnyOrigin();
p.AllowAnyMethod();
p.AllowAnyHeader();
//p.WithOrigins("http://127.0.0.1:8080", "https://aoba.app");
});
o.AddPolicy("RPC", p =>
{
p.AllowAnyMethod();
p.AllowAnyHeader();
#if DEBUG
p.AllowAnyOrigin();
#else
p.WithOrigins("http://127.0.0.1:8080", "https://aoba.app");
#endif
});
});
@@ -107,7 +116,10 @@ app.UseAuthorization();
app.MapControllers();
app.MapObserability();
app.MapGrpcService<AobaRpcService>()
.RequireCors("AllowAll");
.RequireCors("RPC");
app.MapGrpcService<AobaAuthService>()
.AllowAnonymous()
.RequireCors("RPC");

View File

@@ -0,0 +1,33 @@
syntax = "proto3";
option csharp_namespace = "Aoba.RPC.Auth";
package aoba.Auth;
service AuthRpc {
rpc Login(Credentials) returns (LoginResponse);
rpc LoginPasskey(PassKeyPayload) returns (LoginResponse);
}
message Credentials{
string user = 1;
string password = 2;
}
message PassKeyPayload {
}
message Jwt{
string token = 1;
}
message LoginResponse{
oneof result {
Jwt jwt = 1;
LoginError error = 2;
}
}
message LoginError{
string message = 1;
}

View File

@@ -0,0 +1,6 @@
namespace AobaServer.Services;
public class AobaAuthService() : Aoba.RPC.Auth.AuthRpc.AuthRpcBase
{
}

View File

@@ -1,4 +1,5 @@
using MongoDB.Bson;
using MongoDB.Driver;
namespace AobaServer.Utils;
@@ -12,4 +13,6 @@ public static class Extensions
return result;
return ObjectId.Empty;
}
}