types.ts
| 1 | export interface MediaFile { |
| 2 | metadata: { |
| 3 | duration: number; |
| 4 | }; |
| 5 | } |
| 6 | |
| 7 | export interface Directory { |
| 8 | files: FileListing; |
| 9 | } |
| 10 | |
| 11 | //Scanned = we know which children exist |
| 12 | //Unknown = either: |
| 13 | // - not scanned (is a subdirectory and recursive=false) |
| 14 | // - only partially exists, because some deeper file was scannend, and this entry only exists as a link |
| 15 | export interface DirectoryWithStatus { |
| 16 | files: FileListingWithStatus; |
| 17 | status: "Scanned" | "Unknown"; |
| 18 | } |
| 19 | |
| 20 | export type FileListing = Map<string, Directory | MediaFile>; |
| 21 | export type FileListingWithStatus = Map<string, DirectoryWithStatus | MediaFile>; |
| 22 | |
| 23 | export function fileSort(a: [string, Directory | MediaFile], b: [string, Directory | MediaFile]): number { |
| 24 | //sort directories first |
| 25 | if ("metadata" in b[1] && !("metadata" in a[1])) return -1; |
| 26 | if ("metadata" in a[1] && !("metadata" in b[1])) return 1; |
| 27 | return a[0].localeCompare(b[0], undefined, { numeric: true }); |
| 28 | } |
| 29 | |
| 30 | export enum MediaFormat { |
| 31 | "opus/ogg" = "opus/ogg", |
| 32 | "opus/webm" = "opus/webm", |
| 33 | mp3 = "mp3", |
| 34 | "vorbis/ogg" = "vorbis/ogg", |
| 35 | "vorbis/webm" = "vorbis/webm", |
| 36 | aac = "aac", |
| 37 | } |
| 38 |