picture retrieval

This commit is contained in:
femsci 2024-02-22 17:08:54 +01:00
parent 723eb19090
commit ee97edfd39
Signed by: femsci
GPG key ID: 21AC2CC03E5BBCD6

View file

@ -1,6 +1,7 @@
using System.Data;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Nyanbyte.PPCheck.Lib.Models;
@ -58,6 +59,28 @@ public class ApiClient : IDisposable
return resp;
}
public async Task<byte[]?> GetImage(Guid identityId)
{
var request = new HttpRequestMessage(HttpMethod.Get, $"Persone/ImageGet/{identityId}");
request.Headers.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0");
request.Headers.Add("Referer", "https://rps.ms.gov.pl/pl-PL/Public");
request.Headers.Add("Accept", "application/json, text/plain, */*");
request.Headers.Add("Accept-Language", "en-US,en;q=0.5");
var httpResponse = await _http.SendAsync(request);
httpResponse.EnsureSuccessStatusCode();
string resp = (await httpResponse.Content.ReadAsStringAsync()).Trim('"');
if (resp == null)
{
return null;
}
byte[] img = Convert.FromBase64String(resp);
return img;
}
public void Dispose()
{
GC.SuppressFinalize(this);