akborana4 commited on
Commit
7a5f946
·
verified ·
1 Parent(s): c61fc87

Create utils.js

Browse files
Files changed (1) hide show
  1. client/src/utils.js +21 -0
client/src/utils.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export function detectMediaTypeFromUrl(url) {
2
+ try {
3
+ const u = new URL(url);
4
+ const path = u.pathname.toLowerCase();
5
+ if (/\.(mp4|webm|ogg|mkv|mov|m4v)$/.test(path)) return 'video';
6
+ if (/\.(mp3|wav|aac|m4a|flac|ogg|opus)$/.test(path)) return 'audio';
7
+ } catch {}
8
+ return 'unknown';
9
+ }
10
+
11
+ export function safeTitle(track) {
12
+ return track?.title || track?.meta?.title || track?.url || 'Untitled';
13
+ }
14
+
15
+ export function prettyError(e) {
16
+ if (!e) return 'Unknown error';
17
+ if (typeof e === 'string') return e;
18
+ if (e.response && e.response.data && e.response.data.error) return e.response.data.error;
19
+ if (e.message) return e.message;
20
+ return JSON.stringify(e);
21
+ }