MCPcopy Index your code
hub / github.com/Dispatcharr/Dispatcharr / uploadLogo

Method uploadLogo

frontend/src/api.js:2639–2692  ·  view source on GitHub ↗
(file, name = null)

Source from the content-addressed store, hash-verified

2637 }
2638
2639 static async uploadLogo(file, name = null) {
2640 try {
2641 const formData = new FormData();
2642 formData.append('file', file);
2643
2644 // Add custom name if provided
2645 if (name && name.trim()) {
2646 formData.append('name', name.trim());
2647 }
2648
2649 // Add timeout handling for file uploads
2650 const controller = new AbortController();
2651 const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout
2652
2653 const response = await fetch(`${host}/api/channels/logos/upload/`, {
2654 method: 'POST',
2655 body: formData,
2656 headers: {
2657 Authorization: `Bearer ${await API.getAuthToken()}`,
2658 },
2659 signal: controller.signal,
2660 });
2661
2662 clearTimeout(timeoutId);
2663
2664 if (!response.ok) {
2665 const error = new Error(`HTTP error! Status: ${response.status}`);
2666 let errorBody = await response.text();
2667
2668 try {
2669 errorBody = JSON.parse(errorBody);
2670 } catch (e) {
2671 // If parsing fails, leave errorBody as the raw text
2672 }
2673
2674 error.status = response.status;
2675 error.response = response;
2676 error.body = errorBody;
2677 throw error;
2678 }
2679
2680 const result = await response.json();
2681 useLogosStore.getState().addLogo(result);
2682 return result;
2683 } catch (e) {
2684 if (e.name === 'AbortError') {
2685 const timeoutError = new Error('Upload timed out. Please try again.');
2686 timeoutError.code = 'NETWORK_ERROR';
2687 throw timeoutError;
2688 }
2689 errorNotification('Failed to upload logo', e);
2690 throw e;
2691 }
2692 }
2693
2694 static async createLogo(values) {
2695 try {

Callers 1

uploadLogoFunction · 0.80

Calls 3

errorNotificationFunction · 0.85
getAuthTokenMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected