* #103: Adding checks to prevent .wav files from being uploaded: * #103: Added method to create song and moving some code around * #103: Fixed build issue * tsk-103: Cleanup of temporary files * tsk-103: Formatting changes * tsk-103: Minor changes * tsk-103: Fixing build issue * tsk-103: Refactored enum * CORE-23734: Refactoring * tsk-103: Confirmed functionality is working * Removed commented code * Removed commented code
This commit was merged in pull request #105.
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ public class CoverArt
|
||||
{
|
||||
var fullPath = this.Directory;
|
||||
|
||||
if (fullPath![fullPath.Length -1] != '/')
|
||||
if (fullPath![fullPath.Length - 1] != '/')
|
||||
{
|
||||
fullPath += "/";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
|
||||
namespace Icarus.Models;
|
||||
|
||||
public enum CreateFileResult
|
||||
{
|
||||
Unknwon = 0,
|
||||
AlreadyExists = 1,
|
||||
FileCreatedAndExists = 2
|
||||
}
|
||||
@@ -12,4 +12,8 @@
|
||||
<PackageReference Include="newtonsoft.json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
+33
-1
@@ -80,7 +80,7 @@ public class Song
|
||||
{
|
||||
var fullPath = SongDirectory;
|
||||
|
||||
if (fullPath![fullPath.Length -1] != '/')
|
||||
if (fullPath![fullPath.Length - 1] != '/')
|
||||
{
|
||||
fullPath += "/";
|
||||
}
|
||||
@@ -112,6 +112,27 @@ public class Song
|
||||
return includeExtension ? $"{filename}{extension}" : filename;
|
||||
}
|
||||
|
||||
public CreateSongResult Create(Microsoft.AspNetCore.Http.IFormFile file, string filePath, string prompt)
|
||||
{
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
return CreateSongResult.AlreadyExists;
|
||||
}
|
||||
|
||||
using (var filestream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
Console.WriteLine(prompt);
|
||||
file.CopyTo(filestream);
|
||||
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
return CreateSongResult.Created;
|
||||
}
|
||||
}
|
||||
|
||||
return CreateSongResult.NotCreated;
|
||||
}
|
||||
|
||||
private string DetermineFileExtension(AudioFileExtensionsType flag)
|
||||
{
|
||||
switch (flag)
|
||||
@@ -135,11 +156,22 @@ public class Song
|
||||
return filename;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#region Enums
|
||||
public enum AudioFileExtensionsType
|
||||
{
|
||||
Default = 0,
|
||||
WAV = 1,
|
||||
FLAC = 2
|
||||
}
|
||||
|
||||
public enum CreateSongResult
|
||||
{
|
||||
NotCreated = 0,
|
||||
AlreadyExists = 1,
|
||||
Created = 2
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user