-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor file handling methods and add CDN configuration
- Removed unused code related to specific storage types - Refactored file handling methods in the FilesController class for better readability and maintainability - Added a new CDN configuration option for payload signature mode to enhance security
- Loading branch information
Showing
36 changed files
with
326 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Argon.Features.Auth; | ||
|
||
using Services; | ||
|
||
public static class AuthorizationFeature | ||
{ | ||
public static void AddArgonAuthorization(this WebApplicationBuilder builder) | ||
{ | ||
builder.Services.AddHttpContextAccessor(); | ||
builder.Services.AddSingleton<IPasswordHashingService, PasswordHashingService>(); | ||
builder.Services.AddTransient<UserManagerService>(); | ||
builder.Services.AddDataProtection(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Argon.Features.EF; | ||
|
||
public static class DatabaseFeature | ||
{ | ||
public static void AddPooledDatabase<T>(this WebApplicationBuilder builder) where T : DbContext | ||
=> builder.Services.AddPooledDbContextFactory<T>(x => x | ||
.EnableDetailedErrors().EnableSensitiveDataLogging().UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")) | ||
.AddInterceptors(new TimeStampAndSoftDeleteInterceptor())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,33 @@ | ||
namespace Argon.Features.MediaStorage; | ||
|
||
public readonly struct AssetId(Guid assetId, AssetScope scope, AssetKind kind, string extensions) | ||
|
||
public abstract class AssetId(Guid assetId, string extensions) | ||
{ | ||
public string ToFileId() | ||
=> $"{assetId:D}-{((byte)scope):X2}-{((byte)kind):X2}-00.{extensions}"; // last two zero reserved | ||
=> $"{assetId:N}.{extensions}"; | ||
|
||
public string GetFilePath() | ||
{ | ||
if (scope == AssetScope.ProfileAsset) | ||
return $"profile/{assetId.ToString().Substring(0, 8)}/{ToFileId()}"; | ||
if (scope == AssetScope.ChatAsset) | ||
return $"chat/{assetId.ToString().Substring(0, 8)}/{ToFileId()}"; | ||
if (scope == AssetScope.ServiceAsset) | ||
return $"service/{assetId.ToString().Substring(0, 8)}/{ToFileId()}"; | ||
return $"temp/{ToFileId()}"; | ||
} | ||
public abstract string GetFilePath(); | ||
|
||
public Dictionary<string, string> GetTags(StorageNameSpace @namespace) | ||
{ | ||
var tags = new Dictionary<string, string> | ||
{ | ||
{ | ||
nameof(AssetScope), $"{scope}" | ||
}, | ||
{ | ||
nameof(AssetKind), $"{kind}" | ||
}, | ||
{ | ||
$"Id", $"{assetId}" | ||
}, | ||
{ | ||
$"Namespace", $"{@namespace.path}:{@namespace.id}" | ||
} | ||
}; | ||
return tags; | ||
} | ||
|
||
public static AssetId FromFileId(string fileId) | ||
{ | ||
if (fileId.Length < 46) | ||
throw new InvalidOperationException("Bad file id"); | ||
var span = fileId.AsSpan(); | ||
var guid = Guid.Parse(span.Slice(0, 36)); | ||
var scope = byte.Parse(span.Slice(37, 2)); | ||
var kind = byte.Parse(span.Slice(40, 2)); | ||
var ext = fileId.Split('.').Last(); | ||
return new AssetId(guid, (AssetScope)scope, (AssetKind)kind, ext); | ||
} | ||
public static AssetId Avatar(Guid userId) | ||
=> new UserAssetId(userId, Guid.NewGuid(), "png"); | ||
|
||
public static AssetId Avatar() => new(Guid.NewGuid(), AssetScope.ProfileAsset, AssetKind.Image, "png"); | ||
public static AssetId VideoAvatar() => new(Guid.NewGuid(), AssetScope.ProfileAsset, AssetKind.VideoNoSound, "mp4"); | ||
public static AssetId ServerFile(Guid serverId, string extension) | ||
=> new UserAssetId(serverId, Guid.NewGuid(), extension); | ||
} | ||
|
||
public enum AssetScope : byte | ||
public sealed class UserAssetId(Guid userId, Guid assetId, string extensions) : AssetId(assetId, extensions) | ||
{ | ||
ProfileAsset, | ||
ChatAsset, | ||
ServiceAsset | ||
public override string GetFilePath() | ||
=> $"user/{userId:N}/{ToFileId()}"; | ||
} | ||
|
||
public enum AssetKind : byte | ||
public sealed class ServerAssetId(Guid serverId, Guid assetId, string extensions) : AssetId(assetId, extensions) | ||
{ | ||
public override string GetFilePath() | ||
=> $"server/{serverId:N}/{ToFileId()}"; | ||
} | ||
public sealed class ChannelAssetId(Guid serverId, Guid channelId, Guid assetId, string extensions) : AssetId(assetId, extensions) | ||
{ | ||
Image, | ||
Video, // only png | ||
VideoNoSound, // gif | ||
File, | ||
ServerContent, | ||
ServiceContent, | ||
Sound | ||
public override string GetFilePath() | ||
=> $"server/{serverId:N}/channel/{channelId:N}/{ToFileId()}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.