Tweaks to Import
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ public class ImportZipExtractor(ILogger<ImportZipExtractor> 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<ImportZipExtractor> 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<ImportZipExtractor> 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<ImportZipExtractor> logger)
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (Directory.Exists(stagingDir))
|
||||
{
|
||||
Directory.Delete(stagingDir, recursive: true);
|
||||
}
|
||||
if (Directory.Exists(stagingDirectory))
|
||||
Directory.Delete(stagingDirectory, recursive: true);
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -15,5 +15,8 @@
|
||||
"Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware": "Fatal"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Imports": {
|
||||
"RootPath": "../../imports"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user