-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFingerprints.cs
53 lines (43 loc) · 2.31 KB
/
Fingerprints.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
using CurseForge.APIClient.Models;
using CurseForge.APIClient.Models.Fingerprints;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace CurseForge.APIClient
{
public partial class ApiClient
{
public async Task<GenericResponse<FingerprintMatchesResult>> GetFingerprintByGameIdMatchesAsync(int gameId, GetFingerprintMatchesRequestBody body) =>
await PostItem<FingerprintMatchesResult>($"/v1/fingerprints/{gameId}", body);
public async Task<GenericResponse<FingerprintMatchesResult>> GetFingerprintMatchesAsync(GetFingerprintMatchesRequestBody body) =>
await PostItem<FingerprintMatchesResult>("/v1/fingerprints", body);
public async Task<GenericResponse<FingerprintFuzzyMatchResult>> GetFingerprintsFuzzyMatchesByGameIdAsync(int gameId, GetFuzzyMatchesRequestBody body) =>
await PostItem<FingerprintFuzzyMatchResult>($"/v1/fingerprints/fuzzy/{gameId}", body);
public async Task<GenericResponse<FingerprintFuzzyMatchResult>> GetFingerprintsFuzzyMatchesAsync(GetFuzzyMatchesRequestBody body) =>
await PostItem<FingerprintFuzzyMatchResult>("/v1/fingerprints/fuzzy", body);
public async Task<GenericResponse<FingerprintMatchesResult>> GetFingerprintMatchesForFileByGameIdAsync(int gameId, string file)
{
var fingerprint = GetFingerprintFromFile(file);
return await PostItem<FingerprintMatchesResult>($"/v1/fingerprints/{gameId}", new GetFingerprintMatchesRequestBody
{
Fingerprints = new List<long> { fingerprint }
});
}
public async Task<GenericResponse<FingerprintMatchesResult>> GetFingerprintMatchesForFileAsync(string file)
{
var fingerprint = GetFingerprintFromFile(file);
return await PostItem<FingerprintMatchesResult>("/v1/fingerprints", new GetFingerprintMatchesRequestBody
{
Fingerprints = new List<long> { fingerprint }
});
}
public long GetFingerprintFromFile(string file)
{
return GetFingerprintFromBytes(File.ReadAllBytes(file));
}
public long GetFingerprintFromBytes(byte[] fileBytes)
{
return MurmurHash2.Hash(MurmurHash2.NormalizeByteArray(fileBytes));
}
}
}