JJ Colocate

This commit is contained in:
2025-06-30 14:23:20 -04:00
parent 360fa53439
commit 24abf5607f
77 changed files with 5700 additions and 5700 deletions

View File

@@ -1,43 +1,43 @@
using Aoba.RPC.Auth;
using AobaCore.Models;
using AobaCore.Services;
using AobaServer.Models;
using AobaServer.Utils;
using Grpc.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
namespace AobaServer.Services;
public class AobaAuthService(AccountsService accountsService, AuthInfo authInfo) : Aoba.RPC.Auth.AuthRpc.AuthRpcBase
{
[AllowAnonymous]
public override async Task<LoginResponse> Login(Credentials request, ServerCallContext context)
{
var user = await accountsService.VerifyLoginAsync(request.User, request.Password, context.CancellationToken);
if (user == null)
return new LoginResponse
{
Error = new LoginError
{
Message = "Invalid login credentials"
}
};
var token = user.GetToken(authInfo);
return new LoginResponse
{
Jwt = new Jwt
{
Token = token
}
};
}
using Aoba.RPC.Auth;
using AobaCore.Models;
using AobaCore.Services;
using AobaServer.Models;
using AobaServer.Utils;
using Grpc.Core;
using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
namespace AobaServer.Services;
public class AobaAuthService(AccountsService accountsService, AuthInfo authInfo) : Aoba.RPC.Auth.AuthRpc.AuthRpcBase
{
[AllowAnonymous]
public override async Task<LoginResponse> Login(Credentials request, ServerCallContext context)
{
var user = await accountsService.VerifyLoginAsync(request.User, request.Password, context.CancellationToken);
if (user == null)
return new LoginResponse
{
Error = new LoginError
{
Message = "Invalid login credentials"
}
};
var token = user.GetToken(authInfo);
return new LoginResponse
{
Jwt = new Jwt
{
Token = token
}
};
}
}

View File

@@ -1,59 +1,59 @@
using Aoba.RPC;
using AobaCore.Services;
using AobaServer.Models;
using AobaServer.Utils;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using MongoDB.Bson.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AobaServer.Services;
public class AobaRpcService(AobaService aobaService, AccountsService accountsService, AuthInfo authInfo) : AobaRpc.AobaRpcBase
{
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
{
var media = await aobaService.GetMediaAsync(request.ToObjectId());
return media.ToResponse();
}
public override async Task<ListResponse> ListMedia(PageFilter request, ServerCallContext context)
{
var user = context.GetUserId();
var result = await aobaService.FindMediaAsync(request.Query, user, request.HasPage ? request.Page : 1, request.HasPageSize ? request.PageSize : 100);
return result.ToResponse();
}
public override async Task<ShareXResponse> GetShareXDestination(Empty request, ServerCallContext context)
{
var userId = context.GetHttpContext().User.GetId();
var user = await accountsService.GetUserAsync(userId, context.CancellationToken);
if (user == null)
return new ShareXResponse { Error = "User does not exist" };
var token = user.GetToken(authInfo);
var dest = new ShareXDestination
{
DeletionURL = string.Empty,
ThumbnailURL = string.Empty,
Headers = new()
{
{ "Authorization", $"Bearer {token}" }
}
};
return new ShareXResponse
{
Destination = JsonSerializer.Serialize(dest, new JsonSerializerOptions
{
WriteIndented = true
})
};
}
using Aoba.RPC;
using AobaCore.Services;
using AobaServer.Models;
using AobaServer.Utils;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using MongoDB.Bson.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AobaServer.Services;
public class AobaRpcService(AobaService aobaService, AccountsService accountsService, AuthInfo authInfo) : AobaRpc.AobaRpcBase
{
public override async Task<MediaResponse> GetMedia(Id request, ServerCallContext context)
{
var media = await aobaService.GetMediaAsync(request.ToObjectId());
return media.ToResponse();
}
public override async Task<ListResponse> ListMedia(PageFilter request, ServerCallContext context)
{
var user = context.GetUserId();
var result = await aobaService.FindMediaAsync(request.Query, user, request.HasPage ? request.Page : 1, request.HasPageSize ? request.PageSize : 100);
return result.ToResponse();
}
public override async Task<ShareXResponse> GetShareXDestination(Empty request, ServerCallContext context)
{
var userId = context.GetHttpContext().User.GetId();
var user = await accountsService.GetUserAsync(userId, context.CancellationToken);
if (user == null)
return new ShareXResponse { Error = "User does not exist" };
var token = user.GetToken(authInfo);
var dest = new ShareXDestination
{
DeletionURL = string.Empty,
ThumbnailURL = string.Empty,
Headers = new()
{
{ "Authorization", $"Bearer {token}" }
}
};
return new ShareXResponse
{
Destination = JsonSerializer.Serialize(dest, new JsonSerializerOptions
{
WriteIndented = true
})
};
}
}