Skip to content

Commit

Permalink
Fix github artifacts updating (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
DTTerastar authored Jan 11, 2024
1 parent d9a1fa6 commit e208e27
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Controllers/FirmwareController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO.Compression;
using System.IO.Compression;
using System.Net.WebSockets;
using System.Text;
using ESPresense.Network;
Expand Down Expand Up @@ -54,6 +54,7 @@ public async Task Update(string id, [FromQuery] string url)
}
catch (Exception e)
{
_logger.LogError(e, "Error updating firmware");
await Log(e.Message, -1);
}
finally
Expand Down Expand Up @@ -84,7 +85,14 @@ private async Task<MemoryStream> GetFirmware(string url)
await stream.CopyToAsync(ms1);
ms1.Position = 0;

if (response.Content.Headers.ContentType?.MediaType != "application/zip") return ms1;
byte[] buffer = new byte[2];
ms1.Read(buffer, 0, 2);
ms1.Position = 0;
bool isZip = buffer[0] == 0x50 && buffer[1] == 0x4B; // Check for 'PK'

var mediaType = response.Content.Headers.ContentType?.MediaType;
if (!isZip && mediaType != "application/zip")
return ms1;

using (var zipArchive = new ZipArchive(ms1))
{
Expand Down

0 comments on commit e208e27

Please sign in to comment.