-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrapper Updates #4
Conversation
Add Experimental Flag, Remove Miki.Http usings for now Add Multipart Form Data
Update README.md to reflect changes to project
src/Imghoard.Tests/ClientTests.cs
Outdated
@@ -10,9 +10,29 @@ public class ClientTests | |||
[Fact] | |||
public void ConstructClientTest() | |||
{ | |||
var i = new ImghoardClient(ImghoardClient.Config.Default()); | |||
var i = new ImghoardClient(Config.Default()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make it so that if you pass null it will fallback to null? this way we could make it optional to pass a Config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, if the constructor is empty, it uses the default configuration, this was just a straggler that was oversighted from testing.
src/Imghoard/Config.cs
Outdated
{ | ||
public string Tenancy { get; set; } = "production"; | ||
public string Endpoint { get; set; } = "https://api.miki.ai/"; | ||
public string UserAgent { get; set; } = $"Mozilla/5.0 (Imghoard.Net/{Assembly.GetExecutingAssembly().GetName().Version.ToString().Substring(0, 3)}; +https://github.com/Mikibot/dotnet-imghoard)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Mozilla/5.0? This is not a web browser.
src/Imghoard/ImghoardClient.cs
Outdated
/// <returns>The url of the uploaded image or null on failure</returns> | ||
public async Task<string> PostImageAsync(Memory<byte> bytes, params string[] Tags) | ||
{ | ||
if(bytes.Length >= 1000000 && !config.Experimental) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preferably do not use 'magic numbers'. Recommend 10 * Mb where Mb is a constant.
src/Imghoard/ImghoardClient.cs
Outdated
} | ||
|
||
var b64 = Convert.ToBase64String(bytes); | ||
image.Position = 0; | ||
(bool supported, string prefix) = IsSupported(bytes.Span.ToArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This copies the array twice. I would recommend for the future to move IsSupported
to a span/memory as well.
src/Imghoard/ImghoardClient.cs
Outdated
Data = $"data:image/{prefix};base64,{Convert.ToBase64String(bytes.Span)}", | ||
Tags = Tags | ||
}, | ||
new JsonSerializerSettings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making this a constant
src/Imghoard/ImghoardClient.cs
Outdated
var response = await apiClient.PostAsync("/images", body); | ||
|
||
if (response.Success) | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to return null? or throw an exception?
{ | ||
public class ImagesResponse | ||
{ | ||
private readonly ImghoardClient ClientInstance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private variables should be lowerCamelCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe all of these have been resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good progress!
@@ -10,9 +10,29 @@ public class ClientTests | |||
[Fact] | |||
public void ConstructClientTest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't make much sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would recommend to verify if there's something like the client set up, or the correct URL is being propagated
src/Imghoard/ImghoardClient.cs
Outdated
|
||
apiClient = new HttpClient(); | ||
apiClient.DefaultRequestHeaders.Add("x-miki-tenancy", config.Tenancy); | ||
apiClient.DefaultRequestHeaders.Add("User-Agent", config.UserAgent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this capp'd, but the other one isn't?
src/Imghoard/ImghoardClient.cs
Outdated
|
||
if (page > 0) | ||
{ | ||
query.Append($"page={page}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would recommend to rewrite this as
List<string> args = new List<string>();
if(page > 0)
{
args.Add($"page={page}");
}
if(tags.Any())
{
args.Add($"tags={string.Join("+", tags)}")
}
string endpoint = baseEndpoint;
if(args.Any())
{
endpoint += "?" + string.Join("&", args);
}
{ | ||
var mock = new Mock<IImghoardClient>(); | ||
|
||
mock.Setup(x => x.GetImageAsync(It.IsAny<ulong>())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically here you want to mock the http client and inject it into the imghoard client
Technically I'm not against pushing this, but I added these and want to know what you think @exsersewo |
…tedimage internal struct
Summary:
Add More Client Tests,
Added Interface,
Add Comments,
Redid PostImage Response
EDIT:
Also contains experimental multipart uploading on files >= 1mb