From cd2a45dcc097d1a5a3ec299a644a630acd63158d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 3 May 2022 22:46:39 -0500 Subject: stub file rewriting --- src/slskd/Program.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 5ce6bfd4..7510f59a 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -633,6 +633,8 @@ namespace slskd } else { + RewriteStaticContentUrls(contentPath, urlBase); + fileServerOptions = new FileServerOptions { FileProvider = new PhysicalFileProvider(contentPath), @@ -831,6 +833,54 @@ namespace slskd } } + private static void RewriteStaticContentUrls(string contentPath, string urlBase) + { + if (string.IsNullOrEmpty(urlBase) || urlBase == "/") + { + // nothing to rewrite + return; + } + + // Log.Warning("Rewriting URLs in static content to reflect custom base url {UrlBase}", urlBase); + // Log.Warning("This is a one-time operation"); + + // var rewrittenFiles = 0; + // var files = System.IO.Directory.GetFiles(contentPath, "*", SearchOption.AllDirectories); + + // foreach (var file in files) + // { + // bool rewritten = false; + // var contents = System.IO.File.ReadAllText(file); + + // if (contents.Contains("../../static") || contents.Contains("./static")) + // { + // contents = contents.Replace("../../static", $"{urlBase}/static"); + // contents = contents.Replace("./static", $"{urlBase}/static"); + // System.IO.File.WriteAllText(file, contents); + // Log.Warning("Rewrote paths in {File}", Path.GetFileName(file)); + // rewritten = true; + // } + + // if (contents.Contains("window.urlBase=\"/\"")) + // { + // contents = contents.Replace("window.urlBase=\"/\"", $"window.urlBase=\"{urlBase}\""); + // System.IO.File.WriteAllText(file, contents); + // Log.Warning("Rewrote urlBase in {File}", Path.GetFileName(file)); + // rewritten = true; + // } + + // if (rewritten) + // { + // rewrittenFiles++; + // } + // } + + // if (rewrittenFiles == 0) + // { + // Log.Warning("No files were rewritten."); + // } + } + private static void GenerateX509Certificate(string password, string filename) { Log.Information("Generating X509 certificate..."); -- cgit v1.2.3