Skip to content

Commit 7e2c1d6

Browse files
author
NellowTCS
committed
more stuff
1 parent f0d9542 commit 7e2c1d6

26 files changed

Lines changed: 844 additions & 1371 deletions

Build/src/platform/library/library.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,50 @@ export class LibraryManager implements LibraryActions {
275275
return `lib-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
276276
}
277277
}
278+
279+
export function flattenPlaylists(items: (Playlist | PlaylistFolder)[]): Playlist[] {
280+
const result: Playlist[] = [];
281+
for (const item of items) {
282+
if ("songs" in item) {
283+
result.push(item);
284+
} else if (item.children?.length) {
285+
result.push(...flattenPlaylists(item.children));
286+
}
287+
}
288+
return result;
289+
}
290+
291+
export function findPlaylistById(
292+
items: (Playlist | PlaylistFolder)[],
293+
id: string,
294+
): Playlist | null {
295+
for (const item of items) {
296+
if (item.id === id && "songs" in item) {
297+
return item;
298+
}
299+
if ("children" in item) {
300+
const found = findPlaylistById(item.children, id);
301+
if (found) return found;
302+
}
303+
}
304+
return null;
305+
}
306+
307+
export function findParentFolderId(
308+
items: (Playlist | PlaylistFolder)[],
309+
id: string,
310+
): string | null {
311+
for (const item of items) {
312+
if (item.id === id) return null;
313+
if ("children" in item) {
314+
for (const child of item.children) {
315+
if (child.id === id) return item.id;
316+
if ("children" in child) {
317+
const found = findParentFolderId(item.children, id);
318+
if (found) return found;
319+
}
320+
}
321+
}
322+
}
323+
return null;
324+
}

Build/src/platform/library/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Track, Playlist, PlaylistItem } from "../../core/engine/types";
1+
import type { Track, Playlist, PlaylistItem, PlaylistFolder } from "../../core/engine/types";
22

33
export interface LibraryState {
44
songs: Track[];

Build/src/platform/metadata/musicMetadata.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BaseMetadataExtractor } from "./base";
22
import type { ExtractedMetadata, MetadataExtractor } from "./base";
3+
import type { EmbeddedLyrics, EncodingDetails, GaplessInfo } from "../../core/engine/types";
34

45
export class MusicMetadataExtractor extends BaseMetadataExtractor {
56
async extractMetadata(file: File | Blob): Promise<ExtractedMetadata> {

Build/src/platform/storage/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ export { dialogStorage } from "./dialogs";
77
export { audioStorage, type AudioData } from "./audio";
88
export { getDb, STORES, closeDb } from "./db";
99

10+
export async function clearAllCaches(): Promise<void> {
11+
if ("caches" in window) {
12+
const cacheNames = await caches.keys();
13+
await Promise.all(cacheNames.map((name) => caches.delete(name)));
14+
}
15+
}
16+
1017
export function detectPlatform(): PlatformType {
1118
const ua = navigator.userAgent;
1219
if (/Electron|Tauri/.test(ua)) return "desktop";

Build/src/types/MusicLibrary.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
interface MusicLibrary {
2-
songs: Song[];
3-
playlists: (Playlist | PlaylistFolder)[];
4-
favorites: string[];
1+
import type { Track, Playlist, PlaylistFolder } from "../core/engine/types";
2+
3+
declare global {
4+
interface MusicLibrary {
5+
songs: Track[];
6+
playlists: (Playlist | PlaylistFolder)[];
7+
favorites: string[];
8+
}
59
}
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
interface CachedSong {
2-
song: Song;
3-
url: string;
4-
loadedAt: number;
1+
import type { Track } from "../core/engine/types";
2+
3+
declare global {
4+
interface CachedSong {
5+
song: Track;
6+
url: string;
7+
loadedAt: number;
8+
}
59
}

Build/src/types/PlayerSettings.d.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

Build/src/types/PlayerState.d.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

Build/src/types/Playlist.d.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

Build/src/types/Song.d.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)