From 4f459927702dfe256a6c7b4fe019808c768e32ce Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 15 Jan 2020 22:32:30 -0700 Subject: [PATCH] GraphQL client support for querying uploaded files --- Wabbajack.Lib/GraphQL/DTOs/UploadedFile.cs | 16 +++++++ Wabbajack.Lib/GraphQL/GraphQLService.cs | 53 ++++++++++++++++++++++ Wabbajack.Lib/Wabbajack.Lib.csproj | 3 ++ 3 files changed, 72 insertions(+) create mode 100644 Wabbajack.Lib/GraphQL/DTOs/UploadedFile.cs create mode 100644 Wabbajack.Lib/GraphQL/GraphQLService.cs diff --git a/Wabbajack.Lib/GraphQL/DTOs/UploadedFile.cs b/Wabbajack.Lib/GraphQL/DTOs/UploadedFile.cs new file mode 100644 index 00000000..f1d54b23 --- /dev/null +++ b/Wabbajack.Lib/GraphQL/DTOs/UploadedFile.cs @@ -0,0 +1,16 @@ +using System; + +namespace Wabbajack.Lib.GraphQL.DTOs +{ + public class UploadedFile + { + public string Id { get; set; } + public string Name { get; set; } + public string MungedName { get; set; } + public DateTime UploadDate { get; set; } + public string Uploader { get; set; } + public Uri Uri { get; set; } + public string Hash { get; set; } + public long Size { get; set; } + } +} diff --git a/Wabbajack.Lib/GraphQL/GraphQLService.cs b/Wabbajack.Lib/GraphQL/GraphQLService.cs new file mode 100644 index 00000000..40d7e2d5 --- /dev/null +++ b/Wabbajack.Lib/GraphQL/GraphQLService.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Threading.Tasks; +using GraphQL.Client; +using GraphQL.Client.Http; +using GraphQL.Common.Request; +using Wabbajack.Common; +using Wabbajack.Lib.GraphQL.DTOs; +using Path = Alphaleonis.Win32.Filesystem.Path; + +namespace Wabbajack.Lib.GraphQL +{ + public class GraphQLService + { + public static readonly Uri BaseURL = new Uri("https://build.wabbajack.org/graphql"); + public static readonly Uri UploadURL = new Uri("https://build.wabbajack.org/upload_file"); + + public async Task> GetUploadedFiles() + { + var client = new GraphQLHttpClient(BaseURL); + var query = new GraphQLRequest + { + Query = @" + query uploadedFilesQuery { + uploadedFiles { + id + name + hash + uri + uploader + uploadDate + } + }" + }; + var result = await client.SendQueryAsync(query); + return result.GetDataFieldAs>("uploadedFiles"); + } + + public async Task UploadFile(string filename) + { + using (var stream = new StatusFileStream(File.OpenRead(filename), $"Uploading {Path.GetFileName(filename)}")) + { + var client = new HttpClient(); + client.DefaultRequestHeaders.Add("X-API-KEY", "TODO"); + var form = new MultipartFormDataContent {{new StreamContent(stream), "file"}}; + var response = await client.PostAsync(UploadURL, form); + return response.IsSuccessStatusCode; + } + } + } +} diff --git a/Wabbajack.Lib/Wabbajack.Lib.csproj b/Wabbajack.Lib/Wabbajack.Lib.csproj index dcbd419f..fe642cb4 100644 --- a/Wabbajack.Lib/Wabbajack.Lib.csproj +++ b/Wabbajack.Lib/Wabbajack.Lib.csproj @@ -27,6 +27,9 @@ 2.2.2.1 + + 2.0.0-alpha.3 + 1.11.17