feat(playlist): 歌单数据层 + 加入歌单入口
数据层: - PlaylistSummary(歌单名/歌曲数/封面),DB 用一条 SQL 取摘要, 封面取歌单内第一首有封面的歌 - PlaylistRepository.getSummaries() / addSongs()(批量加入并去重) - 修复 AudioService.playPlaylist:之前把文件路径直接当 URL, 歌单播放必然失败;现在用 WebDAVService.getFileUrl 构造 入口(视觉为临时实现,等设计稿替换): - 文件列表长按 -> "加入歌单" 底部弹层 - 可在弹层里新建歌单并直接加入 真机验证:长按歌曲 -> 新建 "TL" -> 数据库 playlists/playlist_songs 均有记录。 测试:新增 playlist_summary 4 个用例,累计 29 个全绿。
This commit is contained in:
@@ -313,6 +313,26 @@ class SongDatabase {
|
||||
return await db.query('playlists', orderBy: 'created_at DESC');
|
||||
}
|
||||
|
||||
/// 歌单摘要:歌曲数 + 封面(取歌单内第一首有封面的歌)。
|
||||
/// 列表页只需要这些,不用把每首歌都拉出来。
|
||||
Future<List<Map<String, dynamic>>> getPlaylistSummaries() async {
|
||||
final db = await database;
|
||||
return await db.rawQuery('''
|
||||
SELECT p.id, p.name, p.updated_at,
|
||||
(SELECT COUNT(*) FROM playlist_songs ps
|
||||
WHERE ps.playlist_id = p.id) AS song_count,
|
||||
(SELECT s.artwork_path FROM playlist_songs ps2
|
||||
JOIN songs s ON s.remote_path = ps2.song_id
|
||||
WHERE ps2.playlist_id = p.id
|
||||
AND s.artwork_path IS NOT NULL
|
||||
AND s.artwork_path != ''
|
||||
ORDER BY ps2.order_index
|
||||
LIMIT 1) AS cover_path
|
||||
FROM playlists p
|
||||
ORDER BY p.updated_at DESC
|
||||
''');
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> getPlaylist(String id) async {
|
||||
_logQuery('playlists', 'get', args: {'id': id});
|
||||
final db = await database;
|
||||
|
||||
Reference in New Issue
Block a user