#103: Added method to create song and moving some code around
This commit is contained in:
@@ -366,6 +366,27 @@ public class SongManager : BaseManager
|
|||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Create(IFormFile file, string filePath, string prompt)
|
||||||
|
{
|
||||||
|
if (System.IO.File.Exists(filePath))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var filestream = new FileStream(filePath, FileMode.Create))
|
||||||
|
{
|
||||||
|
Console.WriteLine(prompt);
|
||||||
|
file.CopyTo(filestream);
|
||||||
|
|
||||||
|
if (System.IO.File.Exists(filePath))
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool SongRecordChanged(Song currentSong, Song songUpdates)
|
private bool SongRecordChanged(Song currentSong, Song songUpdates)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class SongDataController : BaseController
|
|||||||
case "wav":
|
case "wav":
|
||||||
// song = _songMgr.SaveSongToFileSystem(up.SongData, up.CoverArtData, song);
|
// song = _songMgr.SaveSongToFileSystem(up.SongData, up.CoverArtData, song);
|
||||||
// TODO: Make sure the tmp file gets deleted
|
// TODO: Make sure the tmp file gets deleted
|
||||||
return BadRequest(".wav files are not supported");
|
return BadRequest("No support for .wav files");
|
||||||
case "flac":
|
case "flac":
|
||||||
song = _songMgr.SaveFlacSongToFileSystem(up.SongData, up.CoverArtData, song);
|
song = _songMgr.SaveFlacSongToFileSystem(up.SongData, up.CoverArtData, song);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
<PackageReference Include="File.TypeChecker" Version="4.1.1" />
|
<PackageReference Include="File.TypeChecker" Version="4.1.1" />
|
||||||
<PackageReference Include="Iconic.Zlib.Netstandard" Version="1.0.0" />
|
<PackageReference Include="Iconic.Zlib.Netstandard" Version="1.0.0" />
|
||||||
<PackageReference Include="JWT" Version="10.1.1" />
|
<PackageReference Include="JWT" Version="10.1.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.6" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
@@ -37,6 +35,10 @@
|
|||||||
<ProjectReference Include="..\Models\Models.csproj" />
|
<ProjectReference Include="..\Models\Models.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Update="nlog.config" CopyToOutputDirectory="PreserveNewest" />
|
<Content Update="nlog.config" CopyToOutputDirectory="PreserveNewest" />
|
||||||
<Content Include="Images/Stock/*.*" CopyToOutputDirectory="PreserveNewest" />
|
<Content Include="Images/Stock/*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||||
|
|||||||
+4
-1
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
// using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
@@ -52,6 +52,9 @@ var Configuration = builder.Configuration;
|
|||||||
|
|
||||||
var connString = Configuration.GetConnectionString("DefaultConnection");
|
var connString = Configuration.GetConnectionString("DefaultConnection");
|
||||||
|
|
||||||
|
// Microsoft.AspNetCore.Authentication
|
||||||
|
// builder.Services.AddAuthentication()
|
||||||
|
|
||||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
|
||||||
{
|
{
|
||||||
options.RequireHttpsMetadata = false;
|
options.RequireHttpsMetadata = false;
|
||||||
|
|||||||
@@ -12,4 +12,8 @@
|
|||||||
<PackageReference Include="newtonsoft.json" Version="13.0.3" />
|
<PackageReference Include="newtonsoft.json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -112,6 +112,27 @@ public class Song
|
|||||||
return includeExtension ? $"{filename}{extension}" : filename;
|
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)
|
private string DetermineFileExtension(AudioFileExtensionsType flag)
|
||||||
{
|
{
|
||||||
switch (flag)
|
switch (flag)
|
||||||
@@ -135,11 +156,22 @@ public class Song
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Enums
|
||||||
public enum AudioFileExtensionsType
|
public enum AudioFileExtensionsType
|
||||||
{
|
{
|
||||||
Default = 0,
|
Default = 0,
|
||||||
WAV = 1,
|
WAV = 1,
|
||||||
FLAC = 2
|
FLAC = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum CreateSongResult
|
||||||
|
{
|
||||||
|
NotCreated = 0,
|
||||||
|
AlreadyExists = 1,
|
||||||
|
Created = 2
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user