mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-05-14 20:08:00 +02:00
api: remove legacy sync hub
This commit is contained in:
@@ -59,8 +59,8 @@ namespace Notesnook.API.Services
|
||||
// URLs generated by S3 are host specific. Changing their hostname on the fly causes
|
||||
// SignatureDoesNotMatch error.
|
||||
// That is why we create 2 separate S3 clients. One for internal traffic and one for external.
|
||||
private AmazonS3Client S3InternalClient { get; }
|
||||
private HttpClient httpClient = new HttpClient();
|
||||
private AmazonS3Client? S3InternalClient { get; }
|
||||
private readonly HttpClient httpClient = new();
|
||||
|
||||
public S3Service(ISyncItemsRepositoryAccessor syncItemsRepositoryAccessor)
|
||||
{
|
||||
@@ -100,8 +100,7 @@ namespace Notesnook.API.Services
|
||||
|
||||
public async Task DeleteObjectAsync(string userId, string name)
|
||||
{
|
||||
var objectName = GetFullObjectName(userId, name);
|
||||
if (objectName == null) throw new Exception("Invalid object name."); ;
|
||||
var objectName = GetFullObjectName(userId, name) ?? throw new Exception("Invalid object name.");
|
||||
|
||||
var response = await GetS3Client(S3ClientMode.INTERNAL).DeleteObjectAsync(GetBucketName(S3ClientMode.INTERNAL), objectName);
|
||||
|
||||
@@ -240,6 +239,7 @@ namespace Notesnook.API.Services
|
||||
await this.AbortMultipartUploadAsync(userId, uploadRequest.Key, uploadRequest.UploadId);
|
||||
throw new Exception("User settings not found.");
|
||||
}
|
||||
userSettings.StorageLimit ??= new Limit { Value = 0, UpdatedAt = 0 };
|
||||
|
||||
if (!Constants.IS_SELF_HOSTED)
|
||||
{
|
||||
@@ -253,9 +253,8 @@ namespace Notesnook.API.Services
|
||||
throw new Exception("Max file size exceeded.");
|
||||
}
|
||||
|
||||
userSettings.StorageLimit ??= new Limit { Value = 0, UpdatedAt = 0 };
|
||||
userSettings.StorageLimit.Value += fileSize;
|
||||
if (StorageHelper.IsStorageLimitReached(subscription, userSettings.StorageLimit))
|
||||
if (StorageHelper.IsStorageLimitReached(subscription, userSettings.StorageLimit.Value))
|
||||
{
|
||||
await this.AbortMultipartUploadAsync(userId, uploadRequest.Key, uploadRequest.UploadId);
|
||||
throw new Exception("Storage limit reached.");
|
||||
@@ -315,13 +314,13 @@ namespace Notesnook.API.Services
|
||||
});
|
||||
}
|
||||
|
||||
private string GetFullObjectName(string userId, string name)
|
||||
private static string? GetFullObjectName(string userId, string name)
|
||||
{
|
||||
if (userId == null || !Regex.IsMatch(name, "[0-9a-zA-Z!" + Regex.Escape("-") + "_.*'()]")) return null;
|
||||
return $"{userId}/{name}";
|
||||
}
|
||||
|
||||
bool IsSuccessStatusCode(int statusCode)
|
||||
static bool IsSuccessStatusCode(int statusCode)
|
||||
{
|
||||
return ((int)statusCode >= 200) && ((int)statusCode <= 299);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user