firebase sdk update + sql options

This commit is contained in:
Artemy
2026-04-05 13:52:13 +07:00
parent 27ef94721f
commit 1d35356c8c
11 changed files with 99 additions and 25 deletions
@@ -49,13 +49,36 @@ public class LocalStorageService : IStorageService
public async Task RemoveAsync(string url)
{
var path = Path.Combine(_storagePath, url);
if (string.IsNullOrWhiteSpace(url))
throw new ArgumentException("Invalid file url");
if (File.Exists(path))
var rootPath = Path.GetFullPath(_storagePath);
var fullPath = Path.GetFullPath(Path.Combine(rootPath, url));
if (!fullPath.StartsWith(rootPath, StringComparison.OrdinalIgnoreCase))
throw new UnauthorizedAccessException("Invalid file path");
if (!File.Exists(fullPath))
return;
try
{
File.Delete(path);
var fileInfo = new FileInfo(fullPath);
if (fileInfo.IsReadOnly)
fileInfo.IsReadOnly = false;
File.Delete(fullPath);
}
catch (IOException ex)
{
throw new IOException($"Failed to delete file: {fullPath}", ex);
}
catch (UnauthorizedAccessException ex)
{
throw new UnauthorizedAccessException($"No access to delete file: {fullPath}", ex);
}
await Task.CompletedTask;
}
}
@@ -52,9 +52,17 @@ public class MediaService : IMediaService
}
}
public Task DeleteMediaAsync(Guid fileId)
public async Task DeleteMediaAsync(Guid mediaId)
{
throw new NotImplementedException();
var mediaFile = await _dbContext.MediaFiles
.FirstOrDefaultAsync(x => x.Id == mediaId)
?? throw new KeyNotFoundException($"No media found by given id {mediaId}");
await _storageService.RemoveAsync(mediaFile.Url);
_dbContext.MediaFiles.Remove(mediaFile);
await _dbContext.SaveChangesAsync();
}
public Task<Media> GetMediaByUrlAsync(string url)
@@ -1,11 +1,18 @@
using FirebaseAdmin.Messaging;
using Govor.Application.Interfaces.PushNotifications;
using Govor.Application.Interfaces.PushNotifications.Models;
using Microsoft.Extensions.Logging;
namespace Govor.Application.Services.PushNotifications.Providers;
public class FirebasePushProvider : IPushNotificationProvider
{
private readonly ILogger<FirebasePushProvider> _logger;
public FirebasePushProvider(ILogger<FirebasePushProvider> logger)
{
_logger = logger;
}
public string Name => "FCM";
public async Task<SendPushResult> SendToTokenAsync(string token, PushMessage message)
@@ -21,6 +28,7 @@ public class FirebasePushProvider : IPushNotificationProvider
{
if (IsInvalidTokenError(ex))
{
_logger.LogError(ex, "FCM send failed");
return new SendPushResult(0, 1, [token]);
}
@@ -63,7 +71,12 @@ public class FirebasePushProvider : IPushNotificationProvider
{
if (!response.Responses[i].IsSuccess)
{
failedTokens.Add(tokens[i]);
var ex = response.Responses[i].Exception;
if (ex != null && IsInvalidTokenError(ex))
{
failedTokens.Add(tokens[i]); // invalid
}
}
}
@@ -75,6 +88,7 @@ public class FirebasePushProvider : IPushNotificationProvider
}
catch (Exception ex)
{
_logger.LogError(ex, "FCM multicast failed");
return new SendPushResult(0, tokens.Count, tokens.ToList());
}
}