Pkzipping Notification blobs to keep with convention

This commit is contained in:
rockstardev
2020-06-11 18:14:23 -05:00
parent 1f35534dfb
commit b53cb50a91
4 changed files with 22 additions and 17 deletions

View File

@@ -1,11 +1,5 @@
using System; using BTCPayServer.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Models.NotificationViewModels; using BTCPayServer.Models.NotificationViewModels;
using ExchangeSharp;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace BTCPayServer.Events.Notifications namespace BTCPayServer.Events.Notifications
@@ -16,7 +10,7 @@ namespace BTCPayServer.Events.Notifications
public override NotificationViewModel ToViewModel(NotificationData data) public override NotificationViewModel ToViewModel(NotificationData data)
{ {
var casted = JsonConvert.DeserializeObject<NewVersionNotification>(data.Blob.ToStringFromUTF8()); var casted = JsonConvert.DeserializeObject<NewVersionNotification>(ZipUtils.Unzip(data.Blob));
var obj = new NotificationViewModel var obj = new NotificationViewModel
{ {
Id = data.Id, Id = data.Id,

View File

@@ -1,7 +1,6 @@
using System; using System;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Models.NotificationViewModels; using BTCPayServer.Models.NotificationViewModels;
using ExchangeSharp;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace BTCPayServer.Events.Notifications namespace BTCPayServer.Events.Notifications
@@ -18,7 +17,7 @@ namespace BTCPayServer.Events.Notifications
{ {
Created = DateTimeOffset.UtcNow, Created = DateTimeOffset.UtcNow,
NotificationType = NotificationType, NotificationType = NotificationType,
Blob = obj.ToBytesUTF8(), Blob = ZipUtils.Zip(obj),
Seen = false Seen = false
}; };
return data; return data;

View File

@@ -93,6 +93,8 @@ namespace BTCPayServer.HostedServices
.Count(); .Count();
if (resp.UnseenCount > 0) if (resp.UnseenCount > 0)
{
try
{ {
resp.Last5 = _db.Notifications resp.Last5 = _db.Notifications
.Where(a => a.ApplicationUserId == userId && !a.Seen) .Where(a => a.ApplicationUserId == userId && !a.Seen)
@@ -101,6 +103,17 @@ namespace BTCPayServer.HostedServices
.Select(a => a.ViewModel()) .Select(a => a.ViewModel())
.ToList(); .ToList();
} }
catch (System.IO.InvalidDataException iex)
{
// invalid notifications that are not pkuzipable, burn them all
var notif = _db.Notifications.Where(a => a.ApplicationUserId == userId);
_db.Notifications.RemoveRange(notif);
_db.SaveChanges();
resp.UnseenCount = 0;
resp.Last5 = new List<NotificationViewModel>();
}
}
else else
{ {
resp.Last5 = new List<NotificationViewModel>(); resp.Last5 = new List<NotificationViewModel>();

View File

@@ -7,7 +7,6 @@ using System.Threading.Tasks;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Events; using BTCPayServer.Events;
using BTCPayServer.Events.Notifications; using BTCPayServer.Events.Notifications;
using ExchangeSharp;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace BTCPayServer.Models.NotificationViewModels namespace BTCPayServer.Models.NotificationViewModels