From 7df1fffdcada1dd145faa64394224887a3327115 Mon Sep 17 00:00:00 2001 From: James Wampler Date: Thu, 20 Aug 2026 14:21:33 -0700 Subject: [PATCH] Tweaks to Import --- .gitignore | 3 +++ src/Novelly.Api/Imports/ImportZipExtractor.cs | 17 ++++++----------- src/Novelly.Api/appsettings.Development.json | 3 +++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 0217999..69b84c1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,9 @@ *.env .env.deploy +# Local outline drop-box for the import feature (Imports:RootPath) +/imports/ + # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/src/Novelly.Api/Imports/ImportZipExtractor.cs b/src/Novelly.Api/Imports/ImportZipExtractor.cs index 8a824e0..5e37fd4 100644 --- a/src/Novelly.Api/Imports/ImportZipExtractor.cs +++ b/src/Novelly.Api/Imports/ImportZipExtractor.cs @@ -10,9 +10,9 @@ public class ImportZipExtractor(ILogger logger) private static readonly string[] AllowedFileNames = [".novelly-import.json"]; - public void Extract(Stream zipStream, string stagingDir) + public void Extract(Stream zipStream, string stagingDirectory) { - Directory.CreateDirectory(stagingDir); + Directory.CreateDirectory(stagingDirectory); try { @@ -39,10 +39,7 @@ public class ImportZipExtractor(ILogger logger) ? entry.FullName : entry.FullName[(stripPrefix.Length + 1)..]; - if (relativePath.Length == 0) - { - continue; - } + if (relativePath.Length == 0) continue; if (!relativePath.EndsWith(".md", StringComparison.OrdinalIgnoreCase) && !AllowedFileNames.Contains(entry.Name)) throw new ArgumentException($"'{entry.FullName}' is not a markdown file. Only .md files (and .novelly-import.json) are allowed."); @@ -54,7 +51,7 @@ public class ImportZipExtractor(ILogger logger) if (totalBytes > MaxTotalUncompressedBytes) throw new ArgumentException($"The zip file is too large uncompressed (max {MaxTotalUncompressedBytes / (1024 * 1024)} MB)."); - var destination = ImportPaths.ResolveWithin(stagingDir, relativePath); + var destination = ImportPaths.ResolveWithin(stagingDirectory, relativePath); Directory.CreateDirectory(Path.GetDirectoryName(destination)!); using var entryStream = entry.Open(); @@ -66,10 +63,8 @@ public class ImportZipExtractor(ILogger logger) } catch { - if (Directory.Exists(stagingDir)) - { - Directory.Delete(stagingDir, recursive: true); - } + if (Directory.Exists(stagingDirectory)) + Directory.Delete(stagingDirectory, recursive: true); throw; } diff --git a/src/Novelly.Api/appsettings.Development.json b/src/Novelly.Api/appsettings.Development.json index 2026d5b..b08b08c 100644 --- a/src/Novelly.Api/appsettings.Development.json +++ b/src/Novelly.Api/appsettings.Development.json @@ -15,5 +15,8 @@ "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware": "Fatal" } } + }, + "Imports": { + "RootPath": "../../imports" } }