using System.Net; using System.Text; using System.Text.Json; using System.Text.Json.Nodes; using XFEExtension.NetCore.ServerInteractive.Attributes; using XFEExtension.NetCore.ServerInteractive.Implements.CoreService; using XFEExtension.NetCore.ServerInteractive.Utilities.Server.Services.CoreService; using XFEWorkflow.Abstractions; using XFEWorkflow.Space.Contracts; namespace XFEWorkflow.Space.Server; public static class SpaceHost { public static SpaceStore Store { get; set; } = null!; } public partial class SpacePublicService : ServerCoreStandardServiceBase { [EntryPoint("health")] [EntryPoint("register")] [EntryPoint("plugins/search")] [EntryPoint("plugins/detail")] [EntryPoint("workflows/search")] [EntryPoint("workflows/detail")] [EntryPoint("workflows/preview")] [EntryPoint("packages/chunk")] [NoLog] public async Task Execute() { try { var body = Args.Context?.Body ?? ReadOnlyMemory.Empty; var input = body.Length == 0 ? new JsonObject() : JsonNode.Parse(body.Span) as JsonObject ?? throw new InvalidDataException("请求必须是 JSON 对象"); await Close((await SpaceHost.Store.PublicAsync(Route, input)).ToJsonString(WorkflowJson.Options)); } catch (Exception ex) when (ex is ArgumentException or InvalidOperationException or InvalidDataException or IOException or FormatException or JsonException) { await CloseWithError(ex.Message, HttpStatusCode.BadRequest); } } } public partial class SpaceAuthorService : ServerCoreUserServiceBase { [EntryPoint("plugins/mine")] [EntryPoint("workflows/mine")] [EntryPoint("workflows/preview/private")] [EntryPoint("workflows/withdraw")] [EntryPoint("uploads/cancel")] [EntryPoint("uploads/begin")] [EntryPoint("uploads/chunk")] [EntryPoint("uploads/complete")] [EntryPoint("reviews/list")] [EntryPoint("reviews/decide")] [EntryPoint("plugins/withdraw")] [EntryPoint("account/profile")] [EntryPoint("account/update")] [NoLog] public async Task Execute() { try { var current = SpaceHost.Store.PublicUser(User); var input = JsonNode.Parse((Args.Context?.Body ?? ReadOnlyMemory.Empty).Span) as JsonObject ?? throw new InvalidDataException("请求必须是 JSON 对象"); await Close((await SpaceHost.Store.AuthorAsync(Route, input, current)).ToJsonString(WorkflowJson.Options)); } catch (UnauthorizedAccessException ex) { await CloseWithError(ex.Message, HttpStatusCode.Forbidden); } catch (Exception ex) when (ex is ArgumentException or InvalidOperationException or InvalidDataException or IOException or FormatException or JsonException) { await CloseWithError(ex.Message, HttpStatusCode.BadRequest); } } } public partial class SpaceLoginService : UserLoginService { [EntryPoint("login")] [NoLog] public Task SpaceLogin() => Login(); } public partial class SpaceReloginService : UserReloginService { [EntryPoint("relogin")] [NoLog] public Task SpaceRelogin() => Relogin(); }