Implement gRPC on client and server

Pending Testing
This commit is contained in:
2025-05-03 01:09:59 -04:00
parent 84f4dc9b8e
commit 0239186a13
12 changed files with 475 additions and 15 deletions

View File

@@ -0,0 +1,15 @@
using MongoDB.Bson;
namespace AobaServer.Utils;
public static class Extensions
{
public static ObjectId ToObjectId(this string? value)
{
if(value == null)
return ObjectId.Empty;
if(ObjectId.TryParse(value, out ObjectId result))
return result;
return ObjectId.Empty;
}
}

View File

@@ -0,0 +1,65 @@
using AobaCore.Models;
using Aoba.RPC;
using MongoDB.Bson;
namespace AobaServer.Utils;
public static class ProtoExtensions
{
public static ListResponse ToResponse(this PagedResult<Media> result)
{
var res = new ListResponse()
{
Pagination = result.ToPagination(),
};
res.Items.AddRange(result.Items.Select(i => i.ToMediaModel()));
return res;
}
public static Pagination ToPagination<T>(this PagedResult<T> result)
{
return new Pagination()
{
Page = result.Page,
PageSize = result.PageSize,
TotalItems = result.TotalItems,
TotalPages = result.TotalPages,
Query = result.Query,
};
}
public static MediaResponse ToResponse(this Media? media)
{
if(media == null)
return new MediaResponse() { Empty = new Empty() };
return new MediaResponse()
{
Value = media.ToMediaModel()
};
}
public static MediaModel ToMediaModel(this Media media)
{
return new MediaModel()
{
Ext = media.Ext,
FileName = media.Filename,
Id = media.Id.ToId(),
MediaId = media.MediaId.ToId(),
MediaType = (Aoba.RPC.MediaType)media.MediaType,
Owner = media.Owner.ToId(),
ViewCount = media.ViewCount,
};
}
public static Id ToId(this ObjectId id)
{
return new Id() { Value = id.ToString() };
}
public static ObjectId ToObjectId(this Id id)
{
return id.Value.ToObjectId();
}
}