diff --git a/.github/workflows/deploy-printer-app.yml b/.github/workflows/deploy-printer-app.yml index f9b3817..dd956a1 100644 --- a/.github/workflows/deploy-printer-app.yml +++ b/.github/workflows/deploy-printer-app.yml @@ -1,6 +1,7 @@ name: "Deploy PrinterApp x86" on: + pull_request: push: tags: - "v*" @@ -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" diff --git a/PrinterApp/ConfigFile.cs b/PrinterApp/ConfigFile.cs index 5ff7238..627394f 100644 --- a/PrinterApp/ConfigFile.cs +++ b/PrinterApp/ConfigFile.cs @@ -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) diff --git a/PrinterApp/PrinterModel.cs b/PrinterApp/PrinterModel.cs index 92de88e..d07d167 100644 --- a/PrinterApp/PrinterModel.cs +++ b/PrinterApp/PrinterModel.cs @@ -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; @@ -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 @@ -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>(responceString) ?? throw new InvalidOperationException(); @@ -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); @@ -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..."); diff --git a/README.md b/README.md index 5232a18..ad73da2 100644 --- a/README.md +++ b/README.md @@ -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-печати.