Compare commits

...

2 Commits

Author SHA1 Message Date
6a92451776 fix: stored procedure and database cleanup fix (also fixes file copying)
All checks were successful
Update changelog / changelog (push) Successful in 26s
2026-01-27 07:52:20 +01:00
17b8bafccd feat: make setup wizard copy a generic album image to music library path 2026-01-27 06:50:32 +01:00
4 changed files with 42 additions and 11 deletions

BIN
Assets/vinyl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -13,7 +13,7 @@ public partial class _00000000000000_StoredProcedure : Migration
AS $$
BEGIN
DELETE FROM "Songs"
WHERE "State" = 0;
WHERE "State" = 1;
COMMIT;
END;

View File

@@ -44,9 +44,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
<Folder Include="Mapping\" />
<Folder Include="DTOs\" />
</ItemGroup>
</Project>

View File

@@ -154,7 +154,8 @@ public class Cli
{
Name = username!,
NormalizedName = username!.ToLower(),
Password = password
Password = password,
Role = isUserAdmin ? 0 : 1 // 0 = admin
};
db.Users.Add(newUser);
@@ -218,9 +219,9 @@ public class Cli
Console.WriteLine($"[Shadow] Remove user");
if (args.Length == 2)
Console.WriteLine($" You will be promped to enter the password.");
Console.WriteLine($" You will be prompted to enter the password.");
else
Console.WriteLine($" You will be promped to enter the username and password.");
Console.WriteLine($" You will be prompted to enter the username and password.");
string? username = null;
if (args.Length != 2)
@@ -339,6 +340,29 @@ public class Cli
System.IO.Directory.CreateDirectory(newMusicLibraryPath);
System.IO.Directory.CreateDirectory(newMusicThumbnailPath);
// Try to find the Assets directory automatically
string currentPath = AppContext.BaseDirectory;
for (int i = 0; i < 5; i++)
{
if (Directory.GetFiles(currentPath, "Shadow.slnx")
.FirstOrDefault() != null)
{
File.Copy(
Path.Combine(currentPath, "Assets", "vinyl.png"),
Path.Combine(newMusicThumbnailPath, "default.png"),
true
);
break;
}
currentPath = Path.Combine(currentPath, "..");
if (i == 5) Console.WriteLine("\n" +
"[Error] Could not determine content root path. \n" +
"Please place Assets/vinyl.png in your thumbnail path directory manually\n" +
"and rename it to default.png.");
}
// UpdateRange can both Add and Update rows.
db.Globals.UpdateRange(musicLibraryPath, musicThumbnailPath);
db.SaveChanges();
@@ -362,7 +386,10 @@ public class Cli
int rowsAffected = 0;
// Retrieve orphaned songs
List<Song> orphanedSongs = db.Songs.Where(s => s.State == 1).ToList();
List<Song> orphanedSongs = db.Songs
.Where(s => s.State == 1)
.Include(s => s.Album)
.ToList();
// Ask if it's alright to remove them
// and related listening data permanently
@@ -390,11 +417,13 @@ public class Cli
// TODO: Remove song images if not used by any other resource
// ...
db.SaveChanges();
}
// Perform cleanup with stored procedure
rowsAffected += db.Database.ExecuteSqlRaw("CALL song_cleanup()");
// rowsAffected += songs.Count;
db.Database.ExecuteSqlRaw("CALL song_cleanup()");
rowsAffected += orphanedSongs.Count;
}
}
else Console.WriteLine("No orphaned songs found.");
@@ -411,13 +440,17 @@ public class Cli
{
db.Albums.RemoveRange(orphanedAlbums);
rowsAffected += orphanedAlbums.Count;
db.SaveChanges();
}
}
else Console.WriteLine("No orphaned albums found.");
// Retrieve orphaned artists (artists with no songs AND albums)
List<Artist> orphanedArtists = db.Artists.Where(a => a.Songs.Count == 0 && a.Albums.Count == 0).ToList();
Artist? unknownArtist = db.Artists.FirstOrDefault(a => a.NormalizedName == "[unknown artist]");
List<Artist> orphanedArtists = db.Artists
.Where(a => a.Songs.Count == 0 && a.Albums.Count == 0)
.ToList();
Artist? unknownArtist = db.Artists
.FirstOrDefault(a => a.NormalizedName == "[unknown artist]");
// Account for the [Unknown Artist],
// which is a meta-artist and shall