Skip to content
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/deploy-printer-app.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "Deploy PrinterApp x86"

on:
pull_request:
push:
tags:
- "v*"
Expand All @@ -25,6 +26,7 @@ jobs:
- run: dotnet publish ${{ env.PROJECT_PATH }} -c Release --self-contained -r win-x86 -p:PublishSingleFile=true -p:PlatformTarget=x86 --no-restore

- name: Archive Release
if: startsWith(github.ref, 'refs/tags/')
uses: thedoctor0/zip-release@main
with:
type: "zip"
Expand Down
3 changes: 1 addition & 2 deletions PrinterApp/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public void LoadConfig(string fileName)
AutoUpdate = config.AutoUpdate;
AuthorizationToken = config.AuthorizationToken;
WriteConfig(configPath);
Log.Debug("Load from config file\n" +
JsonConvert.SerializeObject(this, Formatting.Indented));
Log.Debug("Loaded printer configuration");
}
}
catch (Exception e)
Expand Down
16 changes: 5 additions & 11 deletions PrinterApp/PrinterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.WebSockets;
using System.Reflection;
using System.Text;
Expand Down Expand Up @@ -70,10 +69,8 @@ public PrinterModel(ConfigFile configFile, AutoUpdater autoUpdater)
SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Authorization
= new AuthenticationHeaderValue(_configFile.AuthorizationToken);
_httpClient.DefaultRequestHeaders.Add("Authorization", _configFile.AuthorizationToken);

Log.Information($"[CONSTRUCTOR] Token set: {_configFile.AuthorizationToken}");
Log.Information($"[CONSTRUCTOR] API URL: {ApiUrl}");

try
Expand All @@ -88,9 +85,7 @@ public PrinterModel(ConfigFile configFile, AutoUpdater autoUpdater)
var responseBody = response.Result.Content.ReadAsStringAsync();
responseBody.Wait(1000);
var responceString = responseBody.Result;

Log.Information($"[CONSTRUCTOR] Response body: {responceString}");


var htmlAttributes =
JsonConvert.DeserializeObject<Dictionary<string, string>>(responceString) ??
throw new InvalidOperationException();
Expand Down Expand Up @@ -253,8 +248,9 @@ public async void PrintAsync(bool printDialog)
saveFilePath =
saveFilePath.Replace(Path.DirectorySeparatorChar.ToString(), "/");
ShowComplement();
using var cdnClient = new HttpClient();
await using var s =
await _httpClient.GetStreamAsync(
await cdnClient.GetStreamAsync(
"https://cdn.profcomff.com/app/printer/iddqd.pdf");
await using var fs = new FileStream(saveFilePath, FileMode.OpenOrCreate);
await s.CopyToAsync(fs);
Expand Down Expand Up @@ -503,10 +499,8 @@ private async void SocketsStartAsync()

private async Task RunSocketSessionAsync(ClientWebSocket socket)
{
Log.Information(
$"[WEBSOCKET] Authorization header: {_httpClient.DefaultRequestHeaders.Authorization}");
socket.Options.SetRequestHeader("Authorization",
_httpClient.DefaultRequestHeaders.Authorization!.ToString());
_configFile.AuthorizationToken);

Log.Information("[WEBSOCKET] Attempting connection...");

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@
[Продолжение в CONTRIBUTING.md](CONTRIBUTING.md)

![doom-bigfont-good-luck-newbie](https://user-images.githubusercontent.com/13213573/200591035-6a69a06e-21dd-4145-a492-4c78a36e750b.png)

## Права терминала

Сессии из `AuthorizationToken` нужны два scope в `session_scopes`:

- `print.file.read` — получить метаданные по PIN и скачать PDF.
- `print.qr_task.get` — подключиться к WebSocket и получить задание QR-печати.
Loading