Skip to content
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

Develop #12

Merged
merged 10 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Apps.Wordpress/Actions/PageActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Blackbird.Applications.Sdk.Utils.Extensions.System;
using Blackbird.Applications.Sdk.Utils.Html.Extensions;
using Blackbird.Applications.Sdk.Utils.Parsers;
using Newtonsoft.Json;
using RestSharp;

namespace Apps.Wordpress.Actions;
Expand Down Expand Up @@ -75,9 +76,10 @@ public async Task<WordPressItem> GetPageById([ActionParameter] PageRequest input
{
var client = new WordpressRestClient(Creds);
var request = new WordpressRestRequest(Endpoint + $"/{input.Id}", Method.Get, Creds);
var post = await client.ExecuteWithHandling<BaseDto>(request);
var post = await client.ExecuteWithHandling(request);

return new(post);
var dto = JsonConvert.DeserializeObject<BaseDto>(post.Content!)!;
return new(dto);
}

[Action("Get page missing translations (P)", Description = "Gets all the languages that are missing for this page.")]
Expand Down Expand Up @@ -114,14 +116,15 @@ public async Task<WordPressItem> GetTranslationByPage([ActionParameter] PageRequ
[Action("Get page as HTML", Description = "Get page by id as HTML file")]
public async Task<FileResponse> GetPageByIdAsHtml([ActionParameter] PageRequest input)
{
var client = new CustomWordpressClient(Creds);
var page = await client.Pages.GetByIDAsync(input.Id);

var html = (page.Title.Rendered, page.Content.Rendered).AsHtml();
var client = new WordpressRestClient(Creds);
var request = new WordpressRestRequest(Endpoint + $"/{input.Id}", Method.Get, Creds);
var post = await client.ExecuteWithHandling<BaseDto>(request);

var html = (post.Title.Rendered, post.Content.Rendered).AsHtml();

using var stream = new MemoryStream(Encoding.UTF8.GetBytes(html));
var file = await _fileManagementClient.UploadAsync(stream, MediaTypeNames.Text.Html,
$"{page.Title.Rendered}.html");
$"{post.Title.Rendered}.html");
return new(file);
}

Expand Down
2 changes: 1 addition & 1 deletion Apps.Wordpress/Api/RestSharp/WordpressRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<List<T>> Paginate<T>(RestRequest request)
});

var response = await ExecuteWithHandling(request);
totalPages ??= int.Parse(response.Headers.First(x => x.Name == "X-Wp-Totalpages").Value.ToString());
totalPages ??= int.Parse(response.Headers.First(x => x.Name!.Equals("X-Wp-Totalpages", StringComparison.OrdinalIgnoreCase)).Value.ToString());
var content = response.Content;

var data = JsonConvert.DeserializeObject<T[]>(response.Content);
Expand Down
4 changes: 2 additions & 2 deletions Apps.Wordpress/Apps.Wordpress.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Product>Wordpress (+ Polylang)</Product>
<Version>1.2.1</Version>
<Version>1.2.2</Version>
<Description>The world’s most popular website builder</Description>
<AssemblyName>Apps.Wordpress</AssemblyName>
</PropertyGroup>
Expand All @@ -13,7 +13,7 @@
<PackageReference Include="Blackbird.Applications.SDK.Extensions.FileManagement" Version="1.0.1" />
<PackageReference Include="Blackbird.Applications.Sdk.Utils" Version="1.0.16" />
<PackageReference Include="Blackbird.Applications.Sdk.Utils.Html" Version="1.0.1" />
<PackageReference Include="WordPressPCL" Version="2.0.1" />
<PackageReference Include="WordPressPCL" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource CopyToOutputDirectory="Always" Include="image\icon.png"></EmbeddedResource>
Expand Down