mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
GraphQL client support for querying uploaded files
This commit is contained in:
parent
6a0688d37a
commit
476d6363db
16
Wabbajack.Lib/GraphQL/DTOs/UploadedFile.cs
Normal file
16
Wabbajack.Lib/GraphQL/DTOs/UploadedFile.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
53
Wabbajack.Lib/GraphQL/GraphQLService.cs
Normal file
53
Wabbajack.Lib/GraphQL/GraphQLService.cs
Normal file
@ -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<List<UploadedFile>> 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<List<UploadedFile>>("uploadedFiles");
|
||||
}
|
||||
|
||||
public async Task<bool> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,9 @@
|
||||
<PackageReference Include="Genbox.AlphaFS">
|
||||
<Version>2.2.2.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="GraphQL.Client">
|
||||
<Version>2.0.0-alpha.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="HtmlAgilityPack">
|
||||
<Version>1.11.17</Version>
|
||||
</PackageReference>
|
||||
|
Loading…
Reference in New Issue
Block a user