Tweaks to Import
This commit is contained in:
@@ -12,6 +12,9 @@
|
|||||||
*.env
|
*.env
|
||||||
.env.deploy
|
.env.deploy
|
||||||
|
|
||||||
|
# Local outline drop-box for the import feature (Imports:RootPath)
|
||||||
|
/imports/
|
||||||
|
|
||||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
*.userprefs
|
*.userprefs
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ public class ImportZipExtractor(ILogger<ImportZipExtractor> logger)
|
|||||||
|
|
||||||
private static readonly string[] AllowedFileNames = [".novelly-import.json"];
|
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
|
try
|
||||||
{
|
{
|
||||||
@@ -39,10 +39,7 @@ public class ImportZipExtractor(ILogger<ImportZipExtractor> logger)
|
|||||||
? entry.FullName
|
? entry.FullName
|
||||||
: entry.FullName[(stripPrefix.Length + 1)..];
|
: entry.FullName[(stripPrefix.Length + 1)..];
|
||||||
|
|
||||||
if (relativePath.Length == 0)
|
if (relativePath.Length == 0) continue;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!relativePath.EndsWith(".md", StringComparison.OrdinalIgnoreCase) && !AllowedFileNames.Contains(entry.Name))
|
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.");
|
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)
|
if (totalBytes > MaxTotalUncompressedBytes)
|
||||||
throw new ArgumentException($"The zip file is too large uncompressed (max {MaxTotalUncompressedBytes / (1024 * 1024)} MB).");
|
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)!);
|
Directory.CreateDirectory(Path.GetDirectoryName(destination)!);
|
||||||
|
|
||||||
using var entryStream = entry.Open();
|
using var entryStream = entry.Open();
|
||||||
@@ -66,10 +63,8 @@ public class ImportZipExtractor(ILogger<ImportZipExtractor> logger)
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
if (Directory.Exists(stagingDir))
|
if (Directory.Exists(stagingDirectory))
|
||||||
{
|
Directory.Delete(stagingDirectory, recursive: true);
|
||||||
Directory.Delete(stagingDir, recursive: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,5 +15,8 @@
|
|||||||
"Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware": "Fatal"
|
"Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware": "Fatal"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Imports": {
|
||||||
|
"RootPath": "../../imports"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user