Skip to content

Commit

Permalink
fixed demos upload fix #3002
Browse files Browse the repository at this point in the history
  • Loading branch information
Licho1 committed Jan 11, 2025
1 parent 504ebc4 commit 14ce877
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions .idea/.idea.Zero-K/.idea/projectSettingsUpdater.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Zero-K.info/Controllers/ReplaysController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
Expand All @@ -18,7 +19,17 @@ public ActionResult Index() {

public ActionResult Download(string name)
{
return Redirect(ReplayStorage.Instance.GetFileUrl(name));
try
{
var url = ReplayStorage.Instance.GetFileUrl(name);
if (url != null) return Redirect(url);
}
catch (Exception ex)
{
Trace.TraceWarning("Error downloading replay {0}, attempting local copy: {1}", name, ex.Message);
}

return File(ReplayStorage.Instance.GetLocalFileContent(name), "application/octet-stream", name);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Zero-K.info/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
Expand Down
30 changes: 26 additions & 4 deletions ZkLobbyServer/ReplayStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,26 @@ namespace ZkLobbyServer
public class ReplayStorage
{
public static ReplayStorage Instance { get; } = new ReplayStorage();

BlobContainerClient azureContainer;

string basePath = GlobalConst.SpringieDataDir;

internal ReplayStorage()
{
azureContainer = new BlobContainerClient(MiscVar.ReplaysConnectionString, MiscVar.ReplaysContainerName);
try
{
if (string.IsNullOrEmpty(MiscVar.ReplaysConnectionString) || string.IsNullOrEmpty(MiscVar.ReplaysContainerName))
{
Trace.TraceWarning("Replay storage not configured, replays won't be stored in blobs");
return;
}

azureContainer = new BlobContainerClient(MiscVar.ReplaysConnectionString, MiscVar.ReplaysContainerName);
} catch (Exception ex)
{
Trace.TraceError("Error initializing replay storage: {0}", ex.Message);
}
}

public async Task<bool> UploadAndDeleteFileAsync(string path)
Expand Down Expand Up @@ -65,17 +79,25 @@ public async Task<byte[]> GetFileContent(string replayName)
return stream.ToArray();
}


public byte[] GetLocalFileContent(string replayName)
{
var path = Path.Combine(basePath, "demos-server", replayName);
if (!File.Exists(path)) return null;
return File.ReadAllBytes(path);
}

public async Task MigrateReplays()
{
// replays themselves
var files = Directory.GetFiles(@"c:\Projekty\springie_spring\demos-server");
var files = Directory.GetFiles(Path.Combine(basePath,"demos-server"));
foreach (var fi in files)
{
await UploadAndDeleteFileAsync(fi);
}

// infologs
files = Directory.GetFiles(@"c:\Projekty\springie_spring","infolog_*.txt");
files = Directory.GetFiles(basePath,"infolog_*.txt");
foreach (var fi in files)
{
await UploadAndDeleteFileAsync(fi);
Expand Down

0 comments on commit 14ce877

Please sign in to comment.