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

Web Converter improved #40

Merged
merged 19 commits into from
Sep 3, 2023
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
6 changes: 2 additions & 4 deletions .github/workflows/githubpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
push:
branches:
- 'master'
- 'webconverter'

jobs:
publish:
Expand Down Expand Up @@ -40,12 +41,9 @@ jobs:
run: dotnet publish src/WebConverter/WebConverter.csproj -c Release -p:PublishProfile=src/WebConverter/Properties/PublishProfiles/PublishSite.pubxml --no-restore
- name: Create .nojekyll file
run: touch src/WebConverter/bin/Release/net7.0/publish/wwwroot/.nojekyll
- name: Update relative paths
working-directory: src/WebConverter/bin/Release/net7.0/publish/wwwroot
run: |
sed -i "s/return Response.redirect(\'\/\', 303);/return Response.redirect(\'\/${{github.event.repository.name}}\/\', 303);/g" service-worker.js
- name: Update service-worker-assets.js hashes
working-directory: src/WebConverter/bin/Release/net7.0/publish/wwwroot
if: false
run: |
jsFile=$(<service-worker-assets.js)
# remove JavaScript from contents so it can be interpreted as JSON
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Website](https://img.shields.io/website?up_message=online&down_message=offline&url=https%3A%2F%2Fsungaila.github.io%2FPDFtoImage%2F&style=flat-square&label=website)](https://sungaila.github.io/PDFtoImage/)
[![GitHub license](https://img.shields.io/github/license/sungaila/PDFtoImage?style=flat-square)](https://github.com/sungaila/PDFtoImage/blob/master/LICENSE)

A .NET library to render [PDF files](https://en.wikipedia.org/wiki/PDF) into images. Give it a try on [GitHub Pages](https://sungaila.github.io/PDFtoImage/)!
A .NET library to render [PDF files](https://en.wikipedia.org/wiki/PDF) into images.

This .NET library is built on top of
* [PDFium](https://pdfium.googlesource.com/pdfium/) (native PDF renderer)
Expand Down
12 changes: 0 additions & 12 deletions src/WebConverter/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.JSInterop;
using System;
using System.Linq;
using System.Net.Http;
Expand All @@ -16,8 +14,6 @@
{
public class Program
{
private static Logger<Program>? logger;

public static event EventHandler<HandledFileArgs>? FilesHandled;

public static async Task Main(string[] args)
Expand All @@ -31,10 +27,8 @@
builder.Services.AddWebShareService();

var host = builder.Build();
var navigationManager = host.Services.GetService<NavigationManager>()!;

Check warning on line 30 in src/WebConverter/Client/Program.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Remove the unused local variable 'navigationManager'. (https://rules.sonarsource.com/csharp/RSPEC-1481)

logger = host.Services.GetService<Logger<Program>>()!;

if (host.Services.GetService<FileHandlingService>() is FileHandlingService service && await service.IsSupportedAsync())
{
await service.SetConsumerAsync(async (launchParams) =>
Expand All @@ -52,7 +46,7 @@
await host.RunAsync();
}

public class HandledFileArgs : EventArgs

Check warning on line 49 in src/WebConverter/Client/Program.cs

View workflow job for this annotation

GitHub Actions / SonarCloud

Make this class name end with 'EventArgs'. (https://rules.sonarsource.com/csharp/RSPEC-3376)
{
public KristofferStrube.Blazor.FileAPI.File File { get; }

Expand All @@ -61,11 +55,5 @@
File = file;
}
}

[JSInvokable]
public static void ReceiveWebShareTarget(string title, string text, string url, IJSObjectReference objRef)
{
logger?.LogWarning($"Hey! {title}, {text}, {url}, {objRef}");
}
}
}
31 changes: 31 additions & 0 deletions src/WebConverter/Models/FileStringyfied.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Text.Json.Serialization;

namespace PDFtoImage.WebConverter.Models
{
public partial record FileStringyfied(
[property: JsonPropertyName("name")]
[property: JsonRequired]
string Name,

[property: JsonPropertyName("lastModified")]
[property: JsonRequired]
[property: JsonConverter(typeof(UnixDateTimeConverter))]
DateTimeOffset LastModified,

[property: JsonPropertyName("size")]
[property: JsonRequired]
int Size,

[property: JsonPropertyName("type")]
[property: JsonRequired]
string Type,

[property: JsonPropertyName("data")]
[property: JsonRequired]
string Data
)
{
public string GetData() => Data[(Data.IndexOf("base64,") + "base64,".Length)..];
};
}
18 changes: 18 additions & 0 deletions src/WebConverter/Models/FilesStringyfied.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace PDFtoImage.WebConverter.Models
{
public record FilesStringyfied(
[property: JsonPropertyName("title")]
string? Title,

[property: JsonPropertyName("text")]
string? Text,

[property: JsonPropertyName("url")]
string? Url,

[property: JsonPropertyName("files")]
FileStringyfied[]? Files
);
}
19 changes: 19 additions & 0 deletions src/WebConverter/Models/UnixDateTimeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace PDFtoImage.WebConverter.Models
{
public class UnixDateTimeConverter : JsonConverter<DateTimeOffset>
{
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return DateTimeOffset.FromUnixTimeMilliseconds(reader.GetInt64());
}

public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value.ToUnixTimeMilliseconds());
}
}
}
Loading