mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 11:12:44 +00:00
monograph: add support for webrisk api for analyzing urls for pro users
This commit is contained in:
@@ -70,6 +70,7 @@ namespace Streetwriters.Common
|
||||
public static string SSE_CERT_KEY_PATH => Environment.GetEnvironmentVariable("SSE_CERT_KEY_PATH");
|
||||
|
||||
// internal
|
||||
public static string WEBRISK_API_URI => Environment.GetEnvironmentVariable("WEBRISK_API_URI");
|
||||
public static string MONGODB_CONNECTION_STRING => Environment.GetEnvironmentVariable("MONGODB_CONNECTION_STRING");
|
||||
public static string MONGODB_DATABASE_NAME => Environment.GetEnvironmentVariable("MONGODB_DATABASE_NAME");
|
||||
public static int SUBSCRIPTIONS_SERVER_PORT => int.Parse(Environment.GetEnvironmentVariable("SUBSCRIPTIONS_SERVER_PORT") ?? "80");
|
||||
|
||||
13
Streetwriters.Common/Interfaces/IURLAnalyzer.cs
Normal file
13
Streetwriters.Common/Interfaces/IURLAnalyzer.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using MimeKit;
|
||||
using MimeKit.Cryptography;
|
||||
using Streetwriters.Common.Models;
|
||||
|
||||
namespace Streetwriters.Common.Interfaces
|
||||
{
|
||||
public interface IURLAnalyzer
|
||||
{
|
||||
Task<bool> IsURLSafeAsync(string uri);
|
||||
}
|
||||
}
|
||||
36
Streetwriters.Common/Services/URLAnalyzer.cs
Normal file
36
Streetwriters.Common/Services/URLAnalyzer.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Streetwriters.Common.Interfaces;
|
||||
|
||||
namespace Streetwriters.Common.Services
|
||||
{
|
||||
struct Threat
|
||||
{
|
||||
public string[]? ThreatTypes { get; set; }
|
||||
}
|
||||
struct WebRiskAPIResponse
|
||||
{
|
||||
public Threat Threat { get; set; }
|
||||
}
|
||||
|
||||
public class URLAnalyzer : IURLAnalyzer, IDisposable
|
||||
{
|
||||
private readonly HttpClient httpClient = new();
|
||||
|
||||
public async Task<bool> IsURLSafeAsync(string uri)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Constants.WEBRISK_API_URI)) return true;
|
||||
var response = await httpClient.PostAsJsonAsync(Constants.WEBRISK_API_URI, new { uri });
|
||||
if (!response.IsSuccessStatusCode) return true;
|
||||
var json = await response.Content.ReadFromJsonAsync<WebRiskAPIResponse>();
|
||||
return json.Threat.ThreatTypes == null || json.Threat.ThreatTypes.Length == 0;
|
||||
}
|
||||
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
httpClient.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user