refactor proto files + added metrics token
All checks were successful
Build and Push Image / build-and-push (push) Successful in 5m24s

This commit is contained in:
2025-07-06 01:28:52 -04:00
parent cc64675c9c
commit 7427bbb576
14 changed files with 170 additions and 112 deletions

View File

@@ -35,6 +35,7 @@
<Protobuf Include="Proto\Aoba.proto"></Protobuf>
<Protobuf Include="Proto\Auth.proto"></Protobuf>
<Protobuf Include="Proto\Metrics.proto"></Protobuf>
<Protobuf Include="Proto\Types.proto"></Protobuf>
</ItemGroup>
</Project>

View File

@@ -153,6 +153,9 @@ app.MapObserability();
app.MapGrpcService<AobaRpcService>()
.RequireAuthorization()
.RequireCors("RPC");
app.MapGrpcService<MetricsRpcService>()
.RequireAuthorization()
.RequireCors("RPC");
app.MapGrpcService<AobaAuthService>()
.AllowAnonymous()
.RequireCors("RPC");

View File

@@ -3,6 +3,7 @@ import "google/protobuf/empty.proto";
option csharp_namespace = "Aoba.RPC";
package aoba;
import "Proto/Types.proto";
service AobaRpc {
rpc GetMedia (Id) returns (MediaResponse);
@@ -13,73 +14,3 @@ service AobaRpc {
rpc GetShareXDestination(google.protobuf.Empty) returns (ShareXResponse);
}
message PageFilter {
optional int32 page = 1;
optional int32 pageSize = 2;
optional string query = 3;
}
message Id {
string value = 1;
}
message MediaResponse {
oneof result {
MediaModel value = 1;
google.protobuf.Empty empty = 2;
}
}
message ListResponse {
repeated MediaModel items = 1;
Pagination pagination = 2;
}
message Pagination {
int32 page = 1;
int32 pageSize = 2;
int64 totalPages = 3;
int64 totalItems = 4;
optional string query = 5;
}
message UserResponse {
oneof userResult {
UserModel user = 1;
google.protobuf.Empty empty = 2;
}
}
message UserModel {
Id id = 1;
string username = 2;
string email = 3;
bool isAdmin = 4;
}
message MediaModel {
Id id = 1;
string fileName = 2;
MediaType mediaType = 3;
string ext = 4;
int32 viewCount = 5;
Id owner = 6;
string thumbUrl = 7;
}
enum MediaType {
Image = 0;
Audio = 1;
Video = 2;
Text = 3;
Code = 4;
Raw = 5;
}
message ShareXResponse {
oneof dstResult {
string destination = 1;
string error = 2;
}
}

View File

@@ -1,33 +1,12 @@
syntax = "proto3";
option csharp_namespace = "Aoba.RPC.Auth";
package aoba.Auth;
package aoba;
import "Proto/Types.proto";
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

@@ -1,12 +1,12 @@
syntax = "proto3";
option csharp_namespace = "Aoba.RPC.Metrics";
package aoba.Metrics;
package aoba;
import "Proto/Auth.proto";
import "google/protobuf/empty.proto";
import "Proto/Types.proto";
service Metrics {
rpc GetToken(google.protobuf.Empty) returns (Auth.Jwt);
service MetricsRpc {
rpc GetToken(google.protobuf.Empty) returns (Jwt);
}

View File

@@ -0,0 +1,101 @@
syntax = "proto3";
option csharp_namespace = "Aoba.RPC";
package aoba;
import "google/protobuf/empty.proto";
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;
}
message PageFilter {
optional int32 page = 1;
optional int32 pageSize = 2;
optional string query = 3;
}
message Id {
string value = 1;
}
message MediaResponse {
oneof result {
MediaModel value = 1;
google.protobuf.Empty empty = 2;
}
}
message ListResponse {
repeated MediaModel items = 1;
Pagination pagination = 2;
}
message Pagination {
int32 page = 1;
int32 pageSize = 2;
int64 totalPages = 3;
int64 totalItems = 4;
optional string query = 5;
}
message UserResponse {
oneof userResult {
UserModel user = 1;
google.protobuf.Empty empty = 2;
}
}
message UserModel {
Id id = 1;
string username = 2;
string email = 3;
bool isAdmin = 4;
}
message MediaModel {
Id id = 1;
string fileName = 2;
MediaType mediaType = 3;
string ext = 4;
int32 viewCount = 5;
Id owner = 6;
string thumbUrl = 7;
}
enum MediaType {
Image = 0;
Audio = 1;
Video = 2;
Text = 3;
Code = 4;
Raw = 5;
}
message ShareXResponse {
oneof dstResult {
string destination = 1;
string error = 2;
}
}

View File

@@ -9,15 +9,13 @@ using AobaServer.Utils;
using Grpc.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.Tokens;
using Aoba.RPC;
using System.IdentityModel.Tokens.Jwt;
namespace AobaServer.Services;
public class AobaAuthService(AccountsService accountsService, AuthInfo authInfo) : Aoba.RPC.Auth.AuthRpc.AuthRpcBase
public class AobaAuthService(AccountsService accountsService, AuthInfo authInfo) : AuthRpc.AuthRpcBase
{
[AllowAnonymous]
public override async Task<LoginResponse> Login(Credentials request, ServerCallContext context)
{
var user = await accountsService.VerifyLoginAsync(request.User, request.Password, context.CancellationToken);
@@ -32,7 +30,7 @@ public class AobaAuthService(AccountsService accountsService, AuthInfo authInfo)
var token = user.GetToken(authInfo);
return new LoginResponse
{
Jwt = new Jwt
Jwt = new ()
{
Token = token
}

View File

@@ -12,7 +12,7 @@ using System.IdentityModel.Tokens.Jwt;
namespace AobaServer.Services;
public class MetricsRpcService(AuthConfigService authConfig): Aoba.RPC.Metrics.Metrics.MetricsBase
public class MetricsRpcService(AuthConfigService authConfig): Aoba.RPC.Metrics.MetricsRpc.MetricsRpcBase
{
[AllowAnonymous]
public override async Task<Jwt> GetToken(Empty request, ServerCallContext context)