Skip to content

Commit

Permalink
Merge pull request #13 from cruikshj:cruikshj/issue12
Browse files Browse the repository at this point in the history
Create directory if it does not exist
  • Loading branch information
cruikshj authored May 24, 2024
2 parents 7299564 + 6626a23 commit c7e006a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ServerManagerDiscordBot/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async Task<IEnumerable<FileInfo>> GetServerFilesAsync(string name, Cancel
var directory = new DirectoryInfo(server.FilesPath);
if (!directory.Exists)
{
throw new DirectoryNotFoundException($"The `{name}` server files directory `{server.FilesPath}` does not exist.");
directory.Create();
}

var files = directory.EnumerateFiles();
Expand Down Expand Up @@ -161,7 +161,7 @@ public async Task<IEnumerable<FileInfo>> GetServerGalleryFilesAsync(string name,
var directory = new DirectoryInfo(server.GalleryPath);
if (!directory.Exists)
{
throw new DirectoryNotFoundException($"The `{name}` server gallery directory `{server.GalleryPath}` does not exist.");
directory.Create();
}

var files = directory.EnumerateFiles()
Expand All @@ -179,6 +179,12 @@ public async Task UploadServerGalleryFileAsync(string name, string sourceUrl, st
throw new InvalidOperationException($"The `{name}` server does not support this operation.");
}

var directory = new DirectoryInfo(server.GalleryPath);
if (!directory.Exists)
{
directory.Create();
}

if (!AppSettings.GalleryFileExtensions.Contains(Path.GetExtension(fileName).Substring(1), StringComparer.OrdinalIgnoreCase))
{
throw new ArgumentException($"The gallery does not support the file type `{Path.GetExtension(fileName)}`.");
Expand Down

0 comments on commit c7e006a

Please sign in to comment.