FModel/FModel/ViewModels/ApiEndpointViewModel.cs
ᴅᴊʟᴏʀ3xᴢᴏ 40ed646dcd
Some checks failed
FModel QA Builder / build (push) Has been cancelled
Fix HTML tags in some Quests DisplayName. (#640)
* Fix HTML tags in some Quests DisplayName.

* New Backups & Hotfixes API

* fix backups being null

---------

Co-authored-by: GhostScissors <79089473+GhostScissors@users.noreply.github.com>
2026-02-11 20:33:50 +05:30

49 lines
1.6 KiB
C#

using System;
using System.IO;
using System.Threading.Tasks;
using FModel.Framework;
using FModel.ViewModels.ApiEndpoints;
using RestSharp;
namespace FModel.ViewModels;
public class ApiEndpointViewModel
{
private readonly RestClient _client = new (new RestClientOptions
{
UserAgent = $"FModel/{Constants.APP_VERSION}",
Timeout = TimeSpan.FromSeconds(5)
}, configureSerialization: s => s.UseSerializer<JsonNetSerializer>());
public FortniteApiEndpoint FortniteApi { get; }
public ValorantApiEndpoint ValorantApi { get; }
public DillyApiEndpoint DillyApi { get; }
public EpicApiEndpoint EpicApi { get; }
public FModelApiEndpoint FModelApi { get; }
public GitHubApiEndpoint GitHubApi { get; }
public DynamicApiEndpoint DynamicApi { get; }
public ApiEndpointViewModel()
{
FortniteApi = new FortniteApiEndpoint(_client);
ValorantApi = new ValorantApiEndpoint(_client);
DillyApi = new DillyApiEndpoint(_client);
EpicApi = new EpicApiEndpoint(_client);
FModelApi = new FModelApiEndpoint(_client);
GitHubApi = new GitHubApiEndpoint(_client);
DynamicApi = new DynamicApiEndpoint(_client);
}
public async Task DownloadFileAsync(string fileLink, string installationPath)
{
var request = new FRestRequest(fileLink);
var data = _client.DownloadData(request) ?? Array.Empty<byte>();
await File.WriteAllBytesAsync(installationPath, data);
}
public void DownloadFile(string fileLink, string installationPath)
{
DownloadFileAsync(fileLink, installationPath).GetAwaiter().GetResult();
}
}