From ee97edfd390a3ba3b4d36b4dfe45e3d4ae595f0d Mon Sep 17 00:00:00 2001 From: femsci Date: Thu, 22 Feb 2024 17:08:54 +0100 Subject: [PATCH] picture retrieval --- src/Nyanbyte.PPCheck.Lib/ApiClient.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Nyanbyte.PPCheck.Lib/ApiClient.cs b/src/Nyanbyte.PPCheck.Lib/ApiClient.cs index eb031fa..739a3e8 100644 --- a/src/Nyanbyte.PPCheck.Lib/ApiClient.cs +++ b/src/Nyanbyte.PPCheck.Lib/ApiClient.cs @@ -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 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);