MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / addChannel

Method addChannel

frontend/src/api.js:574–626  ·  view source on GitHub ↗
(channel)

Source from the content-addressed store, hash-verified

572 }
573
574 static async addChannel(channel) {
575 try {
576 let body = null;
577 // Prepare a copy to safely mutate
578 const channelData = { ...channel };
579
580 // Remove channel_number if empty, null, or not a valid number
581 if (
582 channelData.channel_number === '' ||
583 channelData.channel_number === null ||
584 channelData.channel_number === undefined ||
585 (typeof channelData.channel_number === 'string' &&
586 channelData.channel_number.trim() === '')
587 ) {
588 delete channelData.channel_number;
589 }
590
591 // Add channel profile IDs based on current selection
592 const selectedProfileId = useChannelsStore.getState().selectedProfileId;
593 if (selectedProfileId && selectedProfileId !== '0') {
594 // Specific profile selected - add only to that profile
595 channelData.channel_profile_ids = [parseInt(selectedProfileId)];
596 }
597 // If selectedProfileId is '0' or not set, don't include channel_profile_ids
598 // which will trigger the backend's default behavior of adding to all profiles
599
600 if (channel.logo_file) {
601 // Must send FormData for file upload
602 body = new FormData();
603 for (const prop in channelData) {
604 body.append(prop, channelData[prop]);
605 }
606 } else {
607 body = { ...channelData };
608 delete body.logo_file;
609 }
610
611 const response = await request(`${host}/api/channels/channels/`, {
612 method: 'POST',
613 body: body,
614 });
615
616 API.getLogos();
617
618 if (response.id) {
619 useChannelsStore.getState().addChannel(response);
620 }
621
622 return response;
623 } catch (e) {
624 errorNotification('Failed to create channel', e);
625 }
626 }
627
628 static async deleteChannel(id) {
629 try {

Callers 3

addChannelFunction · 0.80
channels.test.jsxFile · 0.80

Calls 3

requestFunction · 0.85
errorNotificationFunction · 0.85
getLogosMethod · 0.80

Tested by

no test coverage detected