This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Uploader.cs
71 lines (63 loc) · 2.42 KB
/
Uploader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace QQAI2D
{
internal class Uploader
{
private readonly HttpClient _client;
private readonly string _image;
private readonly int _uploadsCount;
public Uploader(string imageBase64, int uploadsCount)
{
_image = imageBase64;
_uploadsCount = uploadsCount;
_client = new HttpClient { };
}
public async IAsyncEnumerable<string> GetConvertedImagesURL()
{
for (int i = 0; i < _uploadsCount; i++)
{
Response response;
do
{
response = await ProcessImage();
} while (response.code != 0);
yield return JsonSerializer.Deserialize<Extra>(response.extra).URL;
}
}
private async Task<Response> ProcessImage()
{
var requestData = new RequestData(_image);
var responseMessage = await _client.PostAsJsonAsync("https://ai.tu.qq.com/trpc.shadow_cv.ai_processor_cgi.AIProcessorCgi/Process", requestData);
var responseStream = await responseMessage.Content.ReadAsStreamAsync();
return await JsonSerializer.DeserializeAsync<Response>(responseStream);
}
private class RequestData
{
[JsonPropertyName("busiId")]
public string BusiID => "ai_painting_anime_img_entry";
[JsonPropertyName("extra")]
public string Extra => """{"face_rects":[],"version":2,"platform":"web","data_report":{"parent_trace_id":"7dcf28ca-9286-16a6-235b-3c8cca67fe9d","root_channel":"qq_sousuo","level":12}}""";
[JsonPropertyName("images")]
public string[] Images { get; init; }
public RequestData(string imageBase64)
{
Images = new string[1] { imageBase64 };
}
}
private class Response
{
public int code { get; set; }
public string msg { get; set; }
public List<object> images { get; set; }
public List<object> faces { get; set; }
public string extra { get; set; }
}
private class Extra
{
public string URL => $"https://activity.tu.qq.com/mqq/ai_painting_anime/share/{uuid}.jpg";
public string uuid { get; set; }
}
}
}