Skip to content

Commit

Permalink
Add toggle to ignore CORS
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffvli committed Feb 5, 2023
1 parent 22fec8f commit d2e553a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
6 changes: 5 additions & 1 deletion src/renderer/api/jellyfin.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ import { ServerListItem, ServerType } from '/@/renderer/types';
import { parseSearchParams } from '/@/renderer/utils';
import packageJson from '../../../package.json';

const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';

const getCommaDelimitedString = (value: string[]) => {
return value.join(',');
};

const api = ky.create({});
const api = ky.create({
mode: IGNORE_CORS ? 'no-cors' : undefined,
});

const authenticate = async (
url: string,
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/api/navidrome.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import { ServerListItem, ServerType } from '/@/renderer/types';
import { parseSearchParams } from '/@/renderer/utils';
import { subsonicApi } from '/@/renderer/api/subsonic.api';

const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';

const api = ky.create({
hooks: {
afterResponse: [
Expand Down Expand Up @@ -122,6 +124,7 @@ const api = ky.create({
},
],
},
mode: IGNORE_CORS ? 'no-cors' : undefined,
});

const authenticate = async (
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/api/subsonic.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {
import { toast } from '/@/renderer/components/toast';
import { nanoid } from 'nanoid/non-secure';

const IGNORE_CORS = localStorage.getItem('IGNORE_CORS') === 'true';

const getCoverArtUrl = (args: {
baseUrl: string;
coverArtId: string;
Expand Down Expand Up @@ -93,6 +95,7 @@ const api = ky.create({
},
],
},
mode: IGNORE_CORS ? 'no-cors' : undefined,
});

const getDefaultParams = (server: ServerListItem | null) => {
Expand Down
53 changes: 34 additions & 19 deletions src/renderer/features/servers/components/server-list.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Group } from '@mantine/core';
import { Accordion, Button, ContextModalVars } from '/@/renderer/components';
import { Group, Stack } from '@mantine/core';
import { Accordion, Button, ContextModalVars, Switch } from '/@/renderer/components';
import { useLocalStorage } from '@mantine/hooks';
import { openContextModal } from '@mantine/modals';
import { RiAddFill, RiServerFill } from 'react-icons/ri';
import { AddServerForm } from '/@/renderer/features/servers/components/add-server-form';
Expand All @@ -22,6 +23,11 @@ export const ServerList = () => {
});
};

const [ignoreCORS, setIgnoreCORS] = useLocalStorage({
defaultValue: 'false',
key: 'ignore_cors',
});

return (
<>
<Group
Expand All @@ -44,23 +50,32 @@ export const ServerList = () => {
Add server
</Button>
</Group>
<Accordion variant="separated">
{serverListQuery?.map((s) => (
<Accordion.Item
key={s.id}
value={s.name}
>
<Accordion.Control icon={<RiServerFill size={15} />}>
<Group position="apart">
{titleCase(s.type)} - {s.name}
</Group>
</Accordion.Control>
<Accordion.Panel>
<ServerListItem server={s} />
</Accordion.Panel>
</Accordion.Item>
))}
</Accordion>
<Stack>
<Accordion variant="separated">
{serverListQuery?.map((s) => (
<Accordion.Item
key={s.id}
value={s.name}
>
<Accordion.Control icon={<RiServerFill size={15} />}>
<Group position="apart">
{titleCase(s.type)} - {s.name}
</Group>
</Accordion.Control>
<Accordion.Panel>
<ServerListItem server={s} />
</Accordion.Panel>
</Accordion.Item>
))}
</Accordion>
<Group position="right">
<Switch
checked={ignoreCORS === 'true'}
label="Ignore CORS (requires restart)"
onChange={(e) => setIgnoreCORS(String(e.currentTarget.checked))}
/>
</Group>
</Stack>
</>
);
};

0 comments on commit d2e553a

Please sign in to comment.