feat(converters): add reverse lookup for supported source formats
This commit is contained in:
parent
dc61643912
commit
4e9c2b8c14
|
|
@ -282,6 +282,37 @@ export const getPossibleTargets = (from: string): Record<string, string[]> => {
|
|||
return possibleTargets[fromClean] || {};
|
||||
};
|
||||
|
||||
// Reverse of possibleTargets: for a given output extension, which input
|
||||
// extensions (across all converters) can produce it, grouped by converter.
|
||||
const possibleSources: Record<string, Record<string, string[]>> = {};
|
||||
|
||||
for (const converterName in properties) {
|
||||
const converterProperties = properties[converterName]?.properties;
|
||||
if (!converterProperties) continue;
|
||||
|
||||
for (const key in converterProperties.from) {
|
||||
const fromList = converterProperties.from[key];
|
||||
const toList = converterProperties.to[key];
|
||||
|
||||
if (!fromList || !toList) continue;
|
||||
|
||||
for (const target of toList) {
|
||||
if (!possibleSources[target]) possibleSources[target] = {};
|
||||
|
||||
const existing = possibleSources[target][converterName];
|
||||
possibleSources[target][converterName] = existing
|
||||
? Array.from(new Set([...existing, ...fromList]))
|
||||
: [...fromList];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const getPossibleSources = (to: string): Record<string, string[]> => {
|
||||
const toClean = normalizeOutputFiletype(to);
|
||||
|
||||
return possibleSources[toClean] || {};
|
||||
};
|
||||
|
||||
const possibleInputs: string[] = [];
|
||||
for (const converterName in properties) {
|
||||
const converterProperties = properties[converterName]?.properties;
|
||||
|
|
|
|||
Loading…
Reference in New Issue