Skip to content

Commit

Permalink
Merge branch 'dev' of private:sdcb/chats into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
greywen committed Dec 11, 2024
2 parents 1526d75 + 9940e68 commit 7ee22d2
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 15 deletions.
14 changes: 0 additions & 14 deletions src/BE/DB/Init/scaffold-basic-data.linq
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
<Query Kind="Program">
<Connection>
<ID>35a33e06-2204-4d18-88ea-ce7dedb2c722</ID>
<NamingServiceVersion>2</NamingServiceVersion>
<Persist>true</Persist>
<Server>home.starworks.cc,37965</Server>
<SqlSecurity>true</SqlSecurity>
<UserName>sa</UserName>
<Password>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAmOMyzcMZ5ka3bwTJ5AmIAwAAAAACAAAAAAAQZgAAAAEAACAAAACgg8NDg49czDMsZVdzq0y270QbNlJreQzmHHylcaOAlwAAAAAOgAAAAAIAACAAAAA1kH5y8TgdeVizkX0gG0DZt5z6nAJLL4Y0djorJiZ7fCAAAACiWyAkQ+ISVpGnhPB4xAyJDsOPI0hd8DQa9L6IyOo/oUAAAABshwYQgiVMG/CpeAqgSnxR5z5/wCjv+GHgbUPOpYZV+Aue7TCSybx1R1e0hJKq285TBIpwrJVD6373TkwMSj9Y</Password>
<AllowDateOnlyTimeOnly>true</AllowDateOnlyTimeOnly>
<Database>ChatsSTG</Database>
<DriverData>
<LegacyMFA>false</LegacyMFA>
</DriverData>
</Connection>
<NuGetReference>Microsoft.CodeAnalysis.Analyzers</NuGetReference>
<NuGetReference>Microsoft.CodeAnalysis.CSharp</NuGetReference>
<Namespace>Microsoft.CodeAnalysis</Namespace>
Expand Down
11 changes: 10 additions & 1 deletion src/BE/Services/UrlEncryption/UrlEncryptionService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Chats.BE.Infrastructure.Functional;
using System.Security.Cryptography;

namespace Chats.BE.Services.UrlEncryption;

Expand Down Expand Up @@ -32,7 +33,15 @@ public string CreateSignedPath(TimedId timedId, EncryptionPurpose purpose)

public Result<int> DecodeSignedPathAsInt32(string path, long validBefore, string hash, EncryptionPurpose purpose)
{
int id = DecryptAsInt32(path, purpose);
int id;
try
{
id = DecryptAsInt32(path, purpose);
}
catch (CryptographicException)
{
return Result.Fail<int>("Invalid encrypted ID.");
}
DateTimeOffset validBeforeTime = DateTimeOffset.FromUnixTimeMilliseconds(validBefore);
if (validBeforeTime < DateTimeOffset.UtcNow)
{
Expand Down
84 changes: 84 additions & 0 deletions src/scripts/2024-12-10-scaffold-fe.linq
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<Query Kind="Program">
<Namespace>System.Net.Http</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>

async Task Main()
{
string wwwroot = Path.Combine(new DirectoryInfo(Path.GetDirectoryName(Util.CurrentQueryPath)!).Parent!.ToString(), "BE", "wwwroot");
Directory.Delete(wwwroot, recursive: true);
string latestfeUrl = "https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip";
using HttpClient http = new();
ZipArchive zip = new(await http.GetStreamAsync(latestfeUrl), ZipArchiveMode.Read, leaveOpen: false);
foreach (ZipArchiveEntry entry in zip.Entries)
{
entry.Uncapsulate()._storedEntryName = entry.FullName.Replace("chats-fe/", "");
ExtractRelativeToDirectory(entry, wwwroot, overwrite: false);
}
File.WriteAllBytes(Path.Combine(wwwroot, ".gitkeep"), new byte[0]);
}

internal static void ExtractRelativeToDirectory(ZipArchiveEntry source, string destinationDirectoryName, bool overwrite)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(destinationDirectoryName);

// Note that this will give us a good DirectoryInfo even if destinationDirectoryName exists:
DirectoryInfo di = Directory.CreateDirectory(destinationDirectoryName);
string destinationDirectoryFullPath = di.FullName;
if (!destinationDirectoryFullPath.EndsWith(Path.DirectorySeparatorChar))
{
char sep = Path.DirectorySeparatorChar;
destinationDirectoryFullPath = string.Concat(destinationDirectoryFullPath, new ReadOnlySpan<char>(in sep));
}

string fileDestinationPath = Path.GetFullPath(Path.Combine(destinationDirectoryFullPath, SanitizeEntryFilePath(source.FullName)));

if (!fileDestinationPath.StartsWith(destinationDirectoryFullPath, PathInternal.StringComparison))
throw new IOException("IO_ExtractingResultsInOutside");

if (Path.GetFileName(fileDestinationPath).Length == 0)
{
// If it is a directory:

if (source.Length != 0)
throw new IOException("IO_DirectoryNameWithData");

Directory.CreateDirectory(fileDestinationPath);
}
else
{
// If it is a file:
// Create containing directory:
Directory.CreateDirectory(Path.GetDirectoryName(fileDestinationPath)!);
source.ExtractToFile(fileDestinationPath, overwrite: overwrite);
}


static string SanitizeEntryFilePath(string entryPath, bool preserveDriveRoot = false) => entryPath.Replace('\0', '_');
}

/// <summary>Contains internal path helpers that are shared between many projects.</summary>
internal static partial class PathInternal
{
/// <summary>Returns a comparison that can be used to compare file and directory names for equality.</summary>
internal static StringComparison StringComparison
{
get
{
return IsCaseSensitive ?
StringComparison.Ordinal :
StringComparison.OrdinalIgnoreCase;
}
}

/// <summary>Gets whether the system is case-sensitive.</summary>
internal static bool IsCaseSensitive
{
get
{
return !(OperatingSystem.IsWindows() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS());
}
}
}

0 comments on commit 7ee22d2

Please sign in to comment.