mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-31 20:09:11 +00:00
fix: generate link for companion
This commit is contained in:
committed by
Alex Christoffer Rasmussen
parent
6ff06b21a8
commit
763080cd4d
@@ -29,7 +29,7 @@ export default function GenerateLinkFormExport({ lockedPath }: GenerateLinkFormE
|
|||||||
{ value: OntimeView.Timer, label: 'Timer' },
|
{ value: OntimeView.Timer, label: 'Timer' },
|
||||||
{ value: OntimeView.Cuesheet, label: 'Cuesheet' },
|
{ value: OntimeView.Cuesheet, label: 'Cuesheet' },
|
||||||
{ value: OntimeView.Operator, label: 'Operator' },
|
{ value: OntimeView.Operator, label: 'Operator' },
|
||||||
{ value: '', label: 'Companion' },
|
{ value: '<<companion>>', label: 'Companion' },
|
||||||
...urlPresetData.map((preset) => ({
|
...urlPresetData.map((preset) => ({
|
||||||
value: `preset-${preset.alias}`,
|
value: `preset-${preset.alias}`,
|
||||||
label: `URL Preset: ${preset.alias}`,
|
label: `URL Preset: ${preset.alias}`,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ describe('generateAuthenticatedUrl()', () => {
|
|||||||
authenticate: true,
|
authenticate: true,
|
||||||
hash: '1234',
|
hash: '1234',
|
||||||
});
|
});
|
||||||
expect(withAuth.toString()).toBe('http://192.168.10.173:4001/timer?token=1234&n=1');
|
expect(withAuth.toString()).toBe('http://192.168.10.173:4001/timer?n=1&token=1234');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates a link to an unlocked preset', () => {
|
it('generates a link to an unlocked preset', () => {
|
||||||
@@ -69,6 +69,17 @@ describe('generateAuthenticatedUrl()', () => {
|
|||||||
});
|
});
|
||||||
expect(withAuth.toString()).toBe('http://192.168.10.173:4001/preset/some-cuesheet-preset');
|
expect(withAuth.toString()).toBe('http://192.168.10.173:4001/preset/some-cuesheet-preset');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('generates a link for companion', () => {
|
||||||
|
const withAuth = generateShareUrl('http://192.168.10.173:4001', '<<companion>>', {
|
||||||
|
lockConfig: false,
|
||||||
|
lockNav: false,
|
||||||
|
authenticate: true,
|
||||||
|
preset: undefined,
|
||||||
|
hash: '1234',
|
||||||
|
});
|
||||||
|
expect(withAuth.toString()).toBe('http://192.168.10.173:4001/?token=1234');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('for ontime-cloud URLs', () => {
|
describe('for ontime-cloud URLs', () => {
|
||||||
@@ -100,7 +111,7 @@ describe('generateAuthenticatedUrl()', () => {
|
|||||||
prefix: 'prefix',
|
prefix: 'prefix',
|
||||||
hash: '1234',
|
hash: '1234',
|
||||||
});
|
});
|
||||||
expect(withAuth.toString()).toBe('https://cloud.getontime.no/prefix/timer?token=1234&n=1');
|
expect(withAuth.toString()).toBe('https://cloud.getontime.no/prefix/timer?n=1&token=1234');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates a link to an unlocked preset', () => {
|
it('generates a link to an unlocked preset', () => {
|
||||||
|
|||||||
@@ -64,18 +64,21 @@ export function generateShareUrl(
|
|||||||
): URL {
|
): URL {
|
||||||
const url = new URL(baseUrl);
|
const url = new URL(baseUrl);
|
||||||
|
|
||||||
// if the config is locked and we are in a preset, we hide the canonical path
|
// companion links point to the root
|
||||||
const shouldMaskPath = Boolean(preset) && (canonicalPath === OntimeView.Cuesheet || lockConfig);
|
if (canonicalPath !== '<<companion>>') {
|
||||||
const maybePresetPath = shouldMaskPath ? `preset/${preset}` : preset || canonicalPath;
|
// if the config is locked and we are in a preset, we hide the canonical path
|
||||||
url.pathname = prefix ? `${prefix}/${maybePresetPath}` : maybePresetPath;
|
const shouldMaskPath = Boolean(preset) && (canonicalPath === OntimeView.Cuesheet || lockConfig);
|
||||||
|
const maybePresetPath = shouldMaskPath ? `preset/${preset}` : preset || canonicalPath;
|
||||||
|
url.pathname = prefix ? `${prefix}/${maybePresetPath}` : maybePresetPath;
|
||||||
|
|
||||||
|
if (lockNav) {
|
||||||
|
url.searchParams.append('n', '1');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (authenticate && hash) {
|
if (authenticate && hash) {
|
||||||
url.searchParams.append('token', hash);
|
url.searchParams.append('token', hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lockNav) {
|
|
||||||
url.searchParams.append('n', '1');
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ export const validateGenerateUrl = [
|
|||||||
body('lockConfig').isBoolean(),
|
body('lockConfig').isBoolean(),
|
||||||
body('lockNav').isBoolean(),
|
body('lockNav').isBoolean(),
|
||||||
body('preset').optional().isString().trim().notEmpty(),
|
body('preset').optional().isString().trim().notEmpty(),
|
||||||
body('prefix').optional().isString().trim().notEmpty(),
|
|
||||||
body('hash').optional().isString().trim().notEmpty(),
|
|
||||||
|
|
||||||
requestValidationFunction,
|
requestValidationFunction,
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user