public override async Task <bool> Verify(Archive archive) { var client = new Wabbajack.Lib.Http.Client(); var result = await client.GetAsync(Url, errorsAsExceptions : false); return(result.IsSuccessStatusCode); }
public static async Task <Wabbajack.Lib.Http.Client> GetAuthorizedClient(string?apiKey = null) { var client = new Wabbajack.Lib.Http.Client(); client.Headers.Add(("X-API-KEY", await GetAPIKey(apiKey))); return(client); }
public static async Task <Wabbajack.Lib.Http.Client> GetClient() { var client = new Wabbajack.Lib.Http.Client(); client.Headers.Add((Consts.MetricsKeyHeader, await Metrics.GetMetricsKey())); return(client); }
private async Task <CDNFileDefinition> GetDefinition() { var client = new Wabbajack.Lib.Http.Client(); if (DomainRemaps.TryGetValue(Url.Host, out var remap)) { var builder = new UriBuilder(Url) { Host = remap }; using var data = await client.GetAsync(builder + "/definition.json.gz"); await using var gz = new GZipStream(await data.Content.ReadAsStreamAsync(), CompressionMode.Decompress); return(gz.FromJson <CDNFileDefinition>()); } else { client.Headers.Add(("Host", Url.Host)); using var data = await GetWithMirroredRetry(client, Url + "/definition.json.gz"); await using var gz = new GZipStream(await data.Content.ReadAsStreamAsync(), CompressionMode.Decompress); return(gz.FromJson <CDNFileDefinition>()); } }
private static async Task <IEnumerable <UpdateRecord> > GetFeed(Uri uri) { var client = new Wabbajack.Lib.Http.Client(); var data = await client.GetStringAsync(uri); var reader = XmlReader.Create(new StringReader(data)); var results = SyndicationFeed.Load(reader); return(results.Items .Select(itm => { if (TryParseGameUrl(itm.Links.First(), out var game, out var modId)) { return new UpdateRecord { TimeStamp = itm.PublishDate.UtcDateTime, Game = game, ModId = modId }; } return null; }) .NotNull()); }
public static Wabbajack.Lib.Http.Client GetClient(IEnumerable <Cookie> cookies, string referer) { var client = new Wabbajack.Lib.Http.Client(); client.Headers.Add(("Referrer", referer)); client.Cookies.AddRange(cookies.Select(cookie => new System.Net.Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain))); return(client); }
public async Task LoadListsFromGithub() { var client = new Wabbajack.Lib.Http.Client(); Utils.Log("Loading server whitelist"); using (var response = await client.GetAsync(Consts.ServerWhitelistURL)) using (var result = await response.Content.ReadAsStreamAsync()) { ServerWhitelist = result.FromYaml <ServerWhitelist>(); Utils.Log($"Loaded permissions for {ServerWhitelist.AllowedPrefixes?.Count ?? 0} servers and {ServerWhitelist.GoogleIDs?.Count ?? 0} Google Drive files"); } }
public override async Task <bool> Download(Archive a, AbsolutePath destination) { destination.Parent.CreateDirectory(); var definition = await GetDefinition(); await using var fs = await destination.Create(); using var mmfile = MemoryMappedFile.CreateFromFile(fs, null, definition.Size, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, false); var client = new Wabbajack.Lib.Http.Client(); if (!DomainRemaps.ContainsKey(Url.Host)) { client.Headers.Add(("Host", Url.Host)); } using var queue = new WorkQueue(); await definition.Parts.PMap(queue, async part => { Utils.Status($"Downloading {a.Name}", Percent.FactoryPutInRange(definition.Parts.Length - part.Index, definition.Parts.Length)); await using var ostream = mmfile.CreateViewStream(part.Offset, part.Size); if (DomainRemaps.TryGetValue(Url.Host, out var remap)) { var builder = new UriBuilder(Url) { Host = remap }; using var response = await client.GetAsync($"{builder}/parts/{part.Index}"); if (!response.IsSuccessStatusCode) { throw new HttpException((int)response.StatusCode, response.ReasonPhrase); } await response.Content.CopyToAsync(ostream); } else { using var response = await GetWithMirroredRetry(client, $"{Url}/parts/{part.Index}"); if (!response.IsSuccessStatusCode) { throw new HttpException((int)response.StatusCode, response.ReasonPhrase); } await response.Content.CopyToAsync(ostream); } }); return(true); }
public ABuildServerSystemTest(ITestOutputHelper output, SingletonAdaptor <BuildServerFixture> fixture) : base(output) { Filters.Clear(); _unsubMsgs = Utils.LogMessages.OfType <IInfo>().Subscribe(onNext: msg => XunitContext.WriteLine(msg.ShortDescription)); _unsubErr = Utils.LogMessages.OfType <IUserIntervention>().Subscribe(msg => XunitContext.WriteLine("ERROR: User intervention required: " + msg.ShortDescription)); _client = new Wabbajack.Lib.Http.Client(); _authedClient = new Wabbajack.Lib.Http.Client(); Fixture = fixture.Deref(); _authedClient.Headers.Add(("x-api-key", Fixture.APIKey)); AuthorAPI.ApiKeyOverride = Fixture.APIKey; _queue = new WorkQueue(); Queue = new WorkQueue(); Random = new Random(); Consts.ModlistSummaryURL = MakeURL("lists/status.json"); Consts.ServerWhitelistURL = MakeURL("ServerWhitelist.yaml"); Consts.UnlistedModlistMetadataURL = MakeURL("lists/none.json"); }
public async Task Send(Channel channel, DiscordMessage message) { try { string url = channel switch { Channel.Spam => _settings.SpamWebHook, Channel.Ham => _settings.HamWebHook, _ => null }; if (url == null) return; var client = new Wabbajack.Lib.Http.Client(); await client.PostAsync(url, new StringContent(message.ToJson(true), Encoding.UTF8, "application/json")); } catch (Exception ex) { _logger.LogError(ex, ex.ToString()); } }
private async Task <HTTPDownloader.State> ToHttpState() { var initialURL = $"https://drive.google.com/uc?id={Id}&export=download"; var client = new Wabbajack.Lib.Http.Client(); using var response = await client.GetAsync(initialURL); if (!response.IsSuccessStatusCode) { throw new HttpException((int)response.StatusCode, response.ReasonPhrase); } var regex = new Regex("(?<=/uc\\?export=download&confirm=).*(?=;id=)"); var confirm = regex.Match(await response.Content.ReadAsStringAsync()); var url = $"https://drive.google.com/uc?export=download&confirm={confirm}&id={Id}"; var httpState = new HTTPDownloader.State(url) { Client = client }; return(httpState); }
private Client(Wabbajack.Lib.Http.Client client) { _client = client; }