mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Add endpoints for getting IndexedVirtualFiles
This commit is contained in:
parent
1584cb1ea7
commit
a70dd4ba6c
74
Wabbajack.BuildServer/Controllers/IndexedFiles.cs
Normal file
74
Wabbajack.BuildServer/Controllers/IndexedFiles.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using Wabbajack.BuildServer.Models;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib.DTOs;
|
||||
|
||||
namespace Wabbajack.BuildServer.Controllers
|
||||
{
|
||||
[Route("/indexed_files")]
|
||||
public class IndexedFiles : AControllerBase<IndexedFiles>
|
||||
{
|
||||
public IndexedFiles(ILogger<IndexedFiles> logger, DBContext db) : base(logger, db)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("{xxHashAsBase64}")]
|
||||
public async Task<IndexedVirtualFile> GetFile(string xxHashAsBase64)
|
||||
{
|
||||
var id = xxHashAsBase64;//.FromHex().ToBase64();
|
||||
var query = new[]
|
||||
{
|
||||
new BsonDocument("$match",
|
||||
new BsonDocument("_id", id)),
|
||||
new BsonDocument("$graphLookup",
|
||||
new BsonDocument
|
||||
{
|
||||
{"from", "indexed_files"},
|
||||
{"startWith", "$Children.Hash"},
|
||||
{"connectFromField", "Hash"},
|
||||
{"connectToField", "_id"},
|
||||
{"as", "ChildFiles"},
|
||||
{"maxDepth", 8},
|
||||
{"restrictSearchWithMatch", new BsonDocument()}
|
||||
})
|
||||
};
|
||||
|
||||
var result = await Db.IndexedFiles.AggregateAsync<TreeResult>(query);
|
||||
|
||||
IndexedVirtualFile Convert(TreeResult t, string Name = null)
|
||||
{
|
||||
if (t == null)
|
||||
return null;
|
||||
|
||||
Dictionary<string, TreeResult> indexed_children= new Dictionary<string, TreeResult>();
|
||||
if (t.IsArchive)
|
||||
indexed_children = t.ChildFiles.ToDictionary(t => t.Hash);
|
||||
|
||||
var file = new IndexedVirtualFile
|
||||
{
|
||||
Name = Name,
|
||||
Size = t.Size,
|
||||
Hash = t.Hash,
|
||||
Children = t.IsArchive ? t.Children.Select(child => Convert(indexed_children[child.Hash], child.Name)).ToList() : new List<IndexedVirtualFile>()
|
||||
};
|
||||
return file;
|
||||
}
|
||||
|
||||
return Convert(result.FirstOrDefault());
|
||||
}
|
||||
|
||||
public class TreeResult : IndexedFile
|
||||
{
|
||||
public List<TreeResult> ChildFiles { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -54,16 +54,6 @@ namespace Wabbajack.BuildServer.GraphQL
|
||||
return data;
|
||||
});
|
||||
|
||||
Field<VirtualFileType> ("indexedFileTree",
|
||||
arguments: new QueryArguments(
|
||||
new QueryArgument<IdGraphType> {Name = "hash", Description = "Hash of the Job"}),
|
||||
resolve: context =>
|
||||
{
|
||||
var hash = context.GetArgument<string>("hash");
|
||||
var data = db.IndexedFiles.AsQueryable().Where(j => j.Hash == hash).FirstOrDefault();
|
||||
return data;
|
||||
});
|
||||
|
||||
FieldAsync<ListGraphType<MetricResultType>>("dailyUniqueMetrics",
|
||||
arguments: new QueryArguments(
|
||||
new QueryArgument<MetricEnum> {Name = "metric_type", Description = "The grouping of metric data to query"}
|
||||
|
15
Wabbajack.Lib/DTOs/IndexedVirtualFile.cs
Normal file
15
Wabbajack.Lib/DTOs/IndexedVirtualFile.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Wabbajack.Lib.DTOs
|
||||
{
|
||||
/// <summary>
|
||||
/// Response from the Build server for a indexed file
|
||||
/// </summary>
|
||||
public class IndexedVirtualFile
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Hash { get; set; }
|
||||
public long Size { get; set; }
|
||||
public List<IndexedVirtualFile> Children { get; set; } = new List<IndexedVirtualFile>();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user