diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs index 39f3bdb..65935d5 100644 --- a/src/MyWebLog.Domain/ViewModels.fs +++ b/src/MyWebLog.Domain/ViewModels.fs @@ -154,7 +154,9 @@ type DisplayTheme = { /// Create a display theme from a theme static member FromTheme inUseFunc (theme: Theme) = - let fileName = if string theme.Id = "default" then "default-theme.zip" else $"./themes/{theme.Id}-theme.zip" + let fileName = + if string theme.Id = "default" then "default-theme.zip" + else Path.Combine(".", "themes", $"{theme.Id}-theme.zip") { Id = string theme.Id Name = theme.Name Version = theme.Version diff --git a/src/MyWebLog.Tests/Domain/ViewModelsTests.fs b/src/MyWebLog.Tests/Domain/ViewModelsTests.fs index da29a2b..67bc0d4 100644 --- a/src/MyWebLog.Tests/Domain/ViewModelsTests.fs +++ b/src/MyWebLog.Tests/Domain/ViewModelsTests.fs @@ -118,16 +118,19 @@ let displayThemeTests = testList "DisplayTheme.FromTheme" [ Expect.isFalse model.IsOnDisk "IsOnDisk should not have been set" } test "succeeds when a non-default theme is not in use and is on disk" { - let dir = Directory.CreateDirectory "themes" - let file = File.Create "./themes/another-theme.zip" + let dir = Directory.CreateDirectory "themes" try - let model = DisplayTheme.FromTheme (fun _ -> false) { theme with Id = ThemeId "another" } - Expect.isFalse model.IsInUse "IsInUse should not have been set" - Expect.isTrue model.IsOnDisk "IsOnDisk should have been set" + let testFile = Path.Combine(".", "themes", "another-theme.zip") + let file = File.Create testFile + try + let model = DisplayTheme.FromTheme (fun _ -> false) { theme with Id = ThemeId "another" } + Expect.isFalse model.IsInUse "IsInUse should not have been set" + Expect.isTrue model.IsOnDisk "IsOnDisk should have been set" + finally + file.Close() + file.Dispose() + File.Delete testFile finally - file.Close() - file.Dispose() - File.Delete "./themes/another-theme.zip" dir.Delete() } test "succeeds when the default theme is on disk" { diff --git a/src/MyWebLog/Handlers/Admin.fs b/src/MyWebLog/Handlers/Admin.fs index a482305..38cfcf3 100644 --- a/src/MyWebLog/Handlers/Admin.fs +++ b/src/MyWebLog/Handlers/Admin.fs @@ -399,8 +399,11 @@ module Theme = let! _ = loadFromZip themeId stream data do! ThemeAssetCache.refreshTheme themeId data TemplateCache.invalidateTheme themeId + // Ensure the themes directory exists + let themeDir = Path.Combine(".", "themes") + if not (Directory.Exists themeDir) then Directory.CreateDirectory themeDir |> ignore // Save the .zip file - use file = new FileStream($"./themes/{themeId}-theme.zip", FileMode.Create) + use file = new FileStream(Path.Combine(".", "themes", $"{themeId}-theme.zip"), FileMode.Create) do! themeFile.CopyToAsync file do! addMessage ctx { UserMessage.Success with @@ -435,7 +438,7 @@ module Theme = | _ -> match! data.Theme.Delete (ThemeId themeId) with | true -> - let zippedTheme = $"./themes/{themeId}-theme.zip" + let zippedTheme = Path.Combine(".", "themes", $"{themeId}-theme.zip") if File.Exists zippedTheme then File.Delete zippedTheme do! addMessage ctx { UserMessage.Success with Message = $"Theme ID {themeId} deleted successfully" } return! all next ctx diff --git a/src/MyWebLog/Program.fs b/src/MyWebLog/Program.fs index 32abcdc..4dc7880 100644 --- a/src/MyWebLog/Program.fs +++ b/src/MyWebLog/Program.fs @@ -218,8 +218,9 @@ let main args = // Load admin and default themes, and all themes in the /themes directory do! Maintenance.loadTheme [| ""; "./admin-theme.zip" |] app.Services do! Maintenance.loadTheme [| ""; "./default-theme.zip" |] app.Services - if Directory.Exists "./themes" then - for themeFile in Directory.EnumerateFiles("./themes", "*-theme.zip") do + let themePath = Path.Combine(".", "themes") + if Directory.Exists themePath then + for themeFile in Directory.EnumerateFiles(themePath, "*-theme.zip") do do! Maintenance.loadTheme [| ""; themeFile |] app.Services let _ = app.UseForwardedHeaders() diff --git a/src/MyWebLog/appsettings.json b/src/MyWebLog/appsettings.json index cad98ac..207a6c5 100644 --- a/src/MyWebLog/appsettings.json +++ b/src/MyWebLog/appsettings.json @@ -1,5 +1,5 @@ { - "Generator": "myWebLog 2.1.1", + "Generator": "myWebLog 2.2", "Logging": { "LogLevel": { "MyWebLog.Handlers": "Information" diff --git a/src/admin-theme/version.txt b/src/admin-theme/version.txt index d23a661..f3f14b6 100644 --- a/src/admin-theme/version.txt +++ b/src/admin-theme/version.txt @@ -1,2 +1,2 @@ myWebLog Admin -2.1.1 \ No newline at end of file +2.2 \ No newline at end of file diff --git a/src/default-theme/version.txt b/src/default-theme/version.txt index dccf21b..d57272f 100644 --- a/src/default-theme/version.txt +++ b/src/default-theme/version.txt @@ -1,2 +1,2 @@ myWebLog Default Theme -2.1.1 \ No newline at end of file +2.2 \ No newline at end of file