Skip to content

Commit

Permalink
Merge pull request #353 from dorthl/mian
Browse files Browse the repository at this point in the history
Fix problems Build release tests
  • Loading branch information
dorthl authored Jul 31, 2023
2 parents 12900df + ecb618d commit 5bac660
Show file tree
Hide file tree
Showing 39 changed files with 1,470 additions and 1,437 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
Dockerfile
docker-compose.yml
deploy/
**/package-lock.json
3 changes: 3 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# docker
docker build -t dorthl/blogifier:latest .
docker push dorthl/blogifier:latest
2 changes: 1 addition & 1 deletion docs/02-Database.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dotnet ef migrations remove --context MySqlDbContext

# Postgres
dotnet ef migrations add Init --context PostgresDbContext --output-dir Data/Migrations/Postgres
dotnet ef migrations remove --context MySqlDbContext
dotnet ef migrations remove --context PostgresDbContext
```

### Warn
Expand Down
4 changes: 0 additions & 4 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Local machine
rm -fr dist
dotnet publish -c Release /p:RuntimeIdentifier=linux-x64 ./src/Blogifier/Blogifier.csproj --output dist

# docker
# docker build -t dorthl/blogifier:latest .
# docker push dorthl/blogifier:latest
2 changes: 1 addition & 1 deletion src/Blogifier.Admin/BlogAuthStateProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
var stream = await response.Content.ReadAsStreamAsync();
if (stream.Length > 0)
{
claims = JsonSerializer.Deserialize<BlogifierClaims>(stream, BlogifierSharedConstant.DefaultJsonSerializerOptionss)!;
claims = JsonSerializer.Deserialize<BlogifierClaims>(stream, BlogifierSharedConstant.DefaultJsonSerializerOptions)!;
_logger.LogInformation("claims success userName:{UserName}", claims.UserName);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Blogifier.Admin/Blogifier.Admin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Blazored.Typeahead" Version="4.7.0" />
<PackageReference Include="ChartJs.Blazor.Fork" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.9" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.9" />
<PackageReference Include="Sotsera.Blazor.Toaster" Version="3.0.0" />
</ItemGroup>

Expand Down Expand Up @@ -50,10 +50,10 @@
<ProjectCapability Include="ClientAssetsAlpha" />
</ItemGroup>

<Target Name="ClientAssetsClean" BeforeTargets="Clean">
<!--<Target Name="ClientAssetsClean" BeforeTargets="Clean">
<RemoveDir Directories="$(ClientAssetsBuildOutput)" />
<Delete Files="$(IntermediateOutputPath)clientassetsbuild.complete.txt" />
</Target>
</Target>-->

<Target Name="ClientAssetsRestore" BeforeTargets="$(ClientAssetsRestoreBeforeTargets)" Inputs="$(ClientAssetsRestoreInputs)" Outputs="$(ClientAssetsRestoreOutputs)">
<Message Importance="high" Text="Running $(ClientAssetsRestoreCommand)..." />
Expand Down
16 changes: 10 additions & 6 deletions src/Blogifier.Admin/Components/EditorComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@
<div class="easymde-wrapper">
<textarea @ref="_textareaReference" tabindex="2" class="visually-hidden" placeholder="@_localizer["type-here"]"></textarea>
</div>
<InputFile @ref="inputImageFiles" OnChange="@LoadImageFiles" style="display:none;" accept="image/*" />
<InputFile @ref="_inputFileReference" OnChange="@LoadImageFiles" style="display:none;" accept="image/*" />

@code {

[Parameter] public string Toolbar { get; set; } = default!;

private ValueTask<IJSObjectReference> _taskModule;
private ElementReference? _textareaReference;
private InputFile? inputImageFiles;
private InputFile? _inputFileReference;
private List<FrontFileDto> _frontFiles = new List<FrontFileDto>();

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_taskModule = _jsRuntime.InvokeAsync<IJSObjectReference>("import", "./admin/js/editor.js");
var module = await _taskModule;
await module.InvokeVoidAsync("loadEditor", Toolbar, _textareaReference, inputImageFiles?.Element);
var element = _inputFileReference?.Element;
await module.InvokeVoidAsync("loadEditor", Toolbar, _textareaReference, element);
}
}

protected async Task LoadImageFiles(InputFileChangeEventArgs args)
{
var module = await _taskModule;
await module.InvokeVoidAsync("previewImage", inputImageFiles?.Element);
var element = _inputFileReference?.Element;
var file = await module.InvokeAsync<FrontFileDto>("writeFrontFile", element);
_frontFiles.Add(file);
}

public async ValueTask SetValueAsync(string value)
Expand All @@ -37,11 +41,11 @@
await module.InvokeVoidAsync("setEditorValue", value);
}

public async ValueTask<string?> GetValueAsync()
public async ValueTask<(string?, List<FrontFileDto>)> GetValueAsync()
{
var module = await _taskModule;
var content = await module.InvokeAsync<string>("getEditorValue");
return content;
return (content, _frontFiles);
}

async ValueTask IAsyncDisposable.DisposeAsync()
Expand Down
17 changes: 11 additions & 6 deletions src/Blogifier.Admin/Components/PostEditorComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@inject IJSRuntime _jsruntime
@inject NavigationManager _navigation
@inject IToaster _toaster
@inject IMapper _mapper

<div class="bfeditor">
<div class="bfeditor-header">
Expand Down Expand Up @@ -79,21 +80,21 @@
@code {

[Parameter] public PostEditorDto Post { get; set; } = default!;
[Parameter] public EventCallback<PostEditorDto> OnSaveCallback { get; set; }
[Parameter] public EventCallback<FrontPostEditorDto> OnSaveCallback { get; set; }
[Parameter] public EventCallback<int> OnRemoveCallback { get; set; }

private EditorComponent _editorComponent = default!;

protected override async Task OnParametersSetAsync()
public async Task SetPostInfoAsync(PostEditorDto post)
{
var headTitle = _localizer["edit"] + " - " + Post.Title;
var headTitle = _localizer["edit"] + " - " + post.Title;
await _jsruntime.InvokeVoidAsync("commonJsFunctions.setTitle", headTitle);
await _editorComponent.SetValueAsync(Post.Content);
await _editorComponent.SetValueAsync(post.Content);
}

protected async Task SaveCoreAsync(PostState postState)
{
var content = await _editorComponent.GetValueAsync();
var (content, frontFiles) = await _editorComponent.GetValueAsync();
if (string.IsNullOrEmpty(Post.Title) || string.IsNullOrEmpty(content))
{
_toaster.Error(_localizer["title-content-required"]);
Expand All @@ -105,7 +106,10 @@
if (string.IsNullOrEmpty(Post.Cover)) Post.Cover = BlogifierSharedConstant.DefaultCover;
if (string.IsNullOrEmpty(Post.Description)) Post.Description = Post.Title;
Post.State = postState;
await OnSaveCallback.InvokeAsync(Post);

var post = _mapper.Map<FrontPostEditorDto>(Post);
post.Files = frontFiles;
await OnSaveCallback.InvokeAsync(post);
}

protected async Task SaveAsync()
Expand Down Expand Up @@ -142,4 +146,5 @@
Post.Cover = null;
await SaveAsync();
}

}
8 changes: 8 additions & 0 deletions src/Blogifier.Admin/Dtos/FrontFileDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Blogifier.Admin;

public class FrontFileDto
{
public string FileName { get; set; } = default!;
public string Url { get; set; } = default!;
public string Selection { get; set; } = default!;
}
2 changes: 1 addition & 1 deletion src/Blogifier.Admin/Dtos/FrontImportDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Blogifier.Admin;

public class FrontImportDto : ImportDto
{
public new List<FrontPostEditorDto> Posts { get; set; } = default!;
public new List<FrontPostImportDto> Posts { get; set; } = default!;
}
4 changes: 2 additions & 2 deletions src/Blogifier.Admin/Dtos/FrontPostEditorDto.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using Blogifier.Shared;

namespace Blogifier.Admin;

public class FrontPostEditorDto : PostEditorDto
{
public bool Selected { get; set; }
public bool? ImportComplete { get; set; }
public List<FrontFileDto> Files { get; set; } = default!;
}
9 changes: 9 additions & 0 deletions src/Blogifier.Admin/Dtos/FrontPostImportDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Blogifier.Shared;

namespace Blogifier.Admin;

public class FrontPostImportDto : PostEditorDto
{
public bool Selected { get; set; }
public bool? ImportComplete { get; set; }
}
32 changes: 26 additions & 6 deletions src/Blogifier.Admin/Pages/Blogs/EditorView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
@inject NavigationManager _navigation
@inject IToaster _toaster
@inject ToasterService _toasterService
@inject IMapper _mapper

<PageTitleComponent Title="@_localizer["new-post"]" />

<PostEditorComponent Post="@Post" OnSaveCallback="OnSaveAsync" OnRemoveCallback="OnRemoveAsync"></PostEditorComponent>
<PostEditorComponent @ref="_postEditorComponent" Post="@Post" OnSaveCallback="OnSaveAsync" OnRemoveCallback="OnRemoveAsync" />

@code {

[Parameter] public string? Slug { get; set; }

private PostEditorComponent _postEditorComponent = default!;

protected PostEditorDto Post { get; set; } = new PostEditorDto
{
Title = string.Empty,
Expand All @@ -31,14 +33,17 @@
{
Post = (await _httpClient.GetFromJsonAsync<PostEditorDto>($"api/post/byslug/{Slug}"))!;
if (Post.Categories == null) Post.Categories = new List<CategoryDto>();
await _postEditorComponent.SetPostInfoAsync(Post);
}
}

protected async Task OnSaveAsync(PostEditorDto post)
protected async Task OnSaveAsync(FrontPostEditorDto input)
{
if (Post.Id == 0)
var post = _mapper.Map<PostEditorDto>(input);

if (post.Id == 0)
{
var response = await _httpClient.PostAsJsonAsync<PostEditorDto>($"api/post/add", Post);
var response = await _httpClient.PostAsJsonAsync<PostEditorDto>($"api/post/add", post);
if (_toasterService.CheckResponse(response))
{
var slug = await response.Content.ReadAsStringAsync();
Expand All @@ -47,7 +52,7 @@
}
else
{
var response = await _httpClient.PutAsJsonAsync<PostEditorDto>($"api/post/update", Post);
var response = await _httpClient.PutAsJsonAsync<PostEditorDto>($"api/post/update", post);
_toasterService.CheckResponse(response);
}
}
Expand All @@ -60,4 +65,19 @@
_navigation.NavigateTo($"admin");
}

//protected async Task OnFileUploadAsync(FrontFilePreviewDto file)
//{
// using var fileContent = new StreamContent(file.BrowserFile.OpenReadStream());
// fileContent.Headers.ContentType = new MediaTypeHeaderValue(file.BrowserFile.ContentType);
// using var content = new MultipartFormDataContent();
// content.Add(content: fileContent, name: "\"file\"", fileName: file.BrowserFile.Name);
// var response = await _httpClient.PostAsync("api/storage/upload", content);
// if (response.IsSuccessStatusCode)
// {
// var stream = await response.Content.ReadAsStreamAsync();
// var storage = JsonSerializer.Deserialize<StorageDto>(stream, BlogifierSharedConstant.DefaultJsonSerializerOptions)!;
// await _postEditorComponent.ReplaceSelectionAsync(file, storage);
// }
//}
}
2 changes: 1 addition & 1 deletion src/Blogifier.Admin/Pages/Blogs/ImportView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ else
if (response.IsSuccessStatusCode)
{
var stream = await response.Content.ReadAsStreamAsync();
var inputPosts = (await JsonSerializer.DeserializeAsync<List<PostEditorDto>>(stream, BlogifierSharedConstant.DefaultJsonSerializerOptionss))!;
var inputPosts = (await JsonSerializer.DeserializeAsync<List<PostEditorDto>>(stream, BlogifierSharedConstant.DefaultJsonSerializerOptions))!;
var successCount = 0;
foreach (var post in inputPosts)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Blogifier.Admin/Pages/Newsletter/SettingsView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
var stream = await response.Content.ReadAsStreamAsync();
if (stream.Length > 0)
{
Mail = (await JsonSerializer.DeserializeAsync<MailSettingDto>(stream, BlogifierSharedConstant.DefaultJsonSerializerOptionss))!;
Mail = (await JsonSerializer.DeserializeAsync<MailSettingDto>(stream, BlogifierSharedConstant.DefaultJsonSerializerOptions))!;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Blogifier.Admin/Pages/Pages/PagesView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
</svg>
}
</button>
<a class="list-btn" href="posts/@post.Slug" target="_blank">
<a class="list-btn" href="post/@post.Slug" target="_blank">
<svg class="bi" width="15" height="15" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" data-bs-toggle="tooltip" title="@_localizer["view"]">
<path d="M7.85724 2.17097L6 4L7 5L8.93201 3.24577C9.89935 2.27845 11.4719 2.27845 12.4393 3.24577C13.4066 4.21308 13.4066 5.78571 12.4393 6.75303L10.5141 8.75674L11.5141 9.75674L13.5141 7.82783C15.0754 6.26652 15.0754 3.73225 13.5141 2.17094C11.9528 0.609657 9.41852 0.609688 7.85724 2.17097Z" />
<path d="M3.24575 12.4392C2.2784 11.4719 2.2784 9.89935 3.24575 8.93201L5 7L4 6L2.17098 7.85721C0.609703 9.41849 0.609642 11.9528 2.17098 13.514C3.73226 15.0753 6.26656 15.0753 7.82784 13.514L9.5141 11.7567L8.5141 10.7567L6.75301 12.4392C5.78573 13.4066 4.2131 13.4066 3.24575 12.4392Z" />
Expand Down
1 change: 1 addition & 0 deletions src/Blogifier.Admin/Profiles/PostEditorProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class PostEditorProfile : Profile
{
public PostEditorProfile()
{
CreateMap<PostEditorDto, FrontPostImportDto>().ReverseMap();
CreateMap<PostEditorDto, FrontPostEditorDto>().ReverseMap();
}
}
5 changes: 3 additions & 2 deletions src/Blogifier.Admin/assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,13 @@ export function getEditorValue() {
return easymde.value();
}

export function previewImage(inputElem) {
const file = inputElem.files[0];
export function writeFrontFile(inputElement) {
const file = inputElement.files[0];
const fileName = file.name;
const url = URL.createObjectURL(file);
let output = '\r\n![' + fileName + '](' + url + ')';
let codemirror = easymde.codemirror;
codemirror.selection;
codemirror.replaceSelection(output);
return { fileName, url, selection: output }
}
4 changes: 2 additions & 2 deletions src/Blogifier.Admin/assets/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default [
output: {
format: 'iife',
file: 'dist/admin/js/blogifier.js',
sourcemap: true,
sourcemap: false,
minifyInternalExports: true,
plugins: [terser()]
},
Expand All @@ -22,7 +22,7 @@ export default [
output: {
format: 'es',
file: 'dist/admin/js/editor.js',
sourcemap: true,
sourcemap: false,
minifyInternalExports: true,
plugins: [terser()]
},
Expand Down
2 changes: 1 addition & 1 deletion src/Blogifier.Shared/Blogifier.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="7.0.9" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Blogifier.Shared/BlogifierSharedConstant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public static class BlogifierSharedConstant
public static readonly string DefaultAvatar = "img/avatar.webp";
public static readonly string DefaultCover = "img/cover.jpg";
public static readonly string DefaultLogo = "img/logo-sm.png";
public static readonly JsonSerializerOptions DefaultJsonSerializerOptionss = new(JsonSerializerDefaults.Web);
public static readonly JsonSerializerOptions DefaultJsonSerializerOptions = new(JsonSerializerDefaults.Web);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
<ProjectCapability Include="ClientAssetsAlpha" />
</ItemGroup>

<Target Name="ClientAssetsClean" BeforeTargets="Clean">
<!--<Target Name="ClientAssetsClean" BeforeTargets="Clean">
<RemoveDir Directories="$(ClientAssetsBuildOutput)" />
<Delete Files="$(IntermediateOutputPath)clientassetsbuild.complete.txt" />
</Target>
</Target>-->

<Target Name="ClientAssetsRestore" BeforeTargets="$(ClientAssetsRestoreBeforeTargets)" Inputs="$(ClientAssetsRestoreInputs)" Outputs="$(ClientAssetsRestoreOutputs)">
<Message Importance="high" Text="Running $(ClientAssetsRestoreCommand)..." />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
</a>
<div class="account">
<a class="account-logo link-blogifier" href="http://blogifier.net/" target="_blank" rel="nofollow external"
data-bs-toggle="tooltip" title="@_localizer["powered-by-blogifier"]">
data-bs-toggle="tooltip" title="@_localizer["powered-by-blogifier"]">
<svg width="40" height="40" fill="currentColor" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
<path
d="M179.2 0H102.4L81.92 51.2H166.4C180.538 51.2 192 62.6615 192 76.8C192 90.9385 180.538 102.4 166.4 102.4H61.44L40.96 153.6L166.4 153.6C180.538 153.6 192 165.062 192 179.2C192 193.338 180.538 204.8 166.4 204.8H20.48L0 256H179.2C221.615 256 256 221.615 256 179.2C256 159.53 248.605 141.587 236.444 128C248.605 114.413 256 96.4699 256 76.8C256 34.3845 221.615 0 179.2 0Z" />
<path d="M179.2 0H102.4L81.92 51.2H166.4C180.538 51.2 192 62.6615 192 76.8C192 90.9385 180.538 102.4 166.4 102.4H61.44L40.96 153.6L166.4 153.6C180.538 153.6 192 165.062 192 179.2C192 193.338 180.538 204.8 166.4 204.8H20.48L0 256H179.2C221.615 256 256 221.615 256 179.2C256 159.53 248.605 141.587 236.444 128C248.605 114.413 256 96.4699 256 76.8C256 34.3845 221.615 0 179.2 0Z" />
</svg>
</a>
@RenderBody()
Expand Down
Loading

0 comments on commit 5bac660

Please sign in to comment.