mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 17:03:53 +00:00
39 lines
1005 B
TypeScript
39 lines
1005 B
TypeScript
import { DatabaseModel, URLPreset } from 'ontime-types';
|
|
|
|
import { ErrorEmitter } from '../../utils/parserUtils.js';
|
|
|
|
/**
|
|
* Parse URL preset portion of a project file
|
|
*/
|
|
export function parseUrlPresets(data: Partial<DatabaseModel>, emitError?: ErrorEmitter): URLPreset[] {
|
|
if (!data.urlPresets) {
|
|
emitError?.('No data found to import');
|
|
return [];
|
|
}
|
|
|
|
console.log('Found URL presets, importing...');
|
|
|
|
const newPresets: URLPreset[] = [];
|
|
|
|
for (const preset of data.urlPresets) {
|
|
if (!preset.alias || !preset.target) {
|
|
emitError?.(`Invalid URL preset: ${JSON.stringify(preset)}`);
|
|
continue;
|
|
}
|
|
|
|
const newPreset: URLPreset = {
|
|
enabled: preset.enabled ?? false,
|
|
alias: preset.alias,
|
|
target: preset.target,
|
|
search: preset.search ?? '',
|
|
displayInNav: preset.displayInNav ?? false,
|
|
options: preset?.options,
|
|
};
|
|
newPresets.push(newPreset);
|
|
}
|
|
|
|
console.log(`Uploaded ${newPresets.length} preset(s)`);
|
|
|
|
return newPresets;
|
|
}
|